com.aragost.javahg.internals
Class HgInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.BufferedInputStream
              extended by com.aragost.javahg.internals.HgInputStream
All Implemented Interfaces:
Closeable

public class HgInputStream
extends BufferedInputStream

An InputStream that has some methods that make it convenient for JavaHg to read the stdout from the command server.


Field Summary
 
Fields inherited from class java.io.BufferedInputStream
buf, count, marklimit, markpos, pos
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
HgInputStream(InputStream in, CharsetDecoder textDecoder)
           
 
Method Summary
 void consumeAll()
          Read until EOF and discard the bytes read
 DateTime dateTimeUpTo(int stopByte)
          Read a Mercurial date from the stream, stopping when a fixed byte is met.
 int decimalIntUpTo(int stop)
          Read a non-negative integer from the stream until a fixed byte is found.
 boolean find(byte[] bytes)
          Search for the specified bytes in the stream.
 boolean find(int b)
          Read from stream until the specified byte is read.
 boolean isEof()
           
 boolean match(byte[] bytes)
          Look for a fixed set of bytes in the stream.
 boolean match(int b)
          Look for a fixed byte in the stream.
 void mustMatch(byte[] bytes)
          Verifies that the next bytes in the stream matches the specified bytes.
 void mustMatch(int b)
          Verifies that the next byte in the stream matches the specified byte.
 byte[] next(int length)
          Get the next length bytes from the stream.
 String nextAsText(int length)
          Get the next length bytes from the stream, and return it as a String
 int peek()
          Return the next byte from the stream without forwarding the position.
 Integer readDecimal()
          Read a non-negative integer from the stream.
 int revisionUpTo(int stop)
          Read a revision number from the stream until a fixed byte is found.
 String textUpTo(byte[] end)
          Read from the stream until end is found, return the read portion as a String.
 String textUpTo(int b)
          Read from the stream until the byte b is found, return the read portion as a String.
 String toString()
           
 byte[] upTo(byte[] stop)
          Read from the stream until a fixed set of bytes are found.
 byte[] upTo(int stop)
          Read from the stream until a fixed byte is found.
 
Methods inherited from class java.io.BufferedInputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.io.FilterInputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HgInputStream

public HgInputStream(InputStream in,
                     CharsetDecoder textDecoder)
Parameters:
in - the byte stream.
textDecoder - the decoder used when Strings are extracted from the byte stream.
Method Detail

peek

public int peek()
         throws IOException
Return the next byte from the stream without forwarding the position.

Returns:
the byte read or -1 if EOF is reached.
Throws:
IOException

isEof

public boolean isEof()
              throws IOException
Returns:
true if no more bytes can be read from the stream
Throws:
IOException

next

public byte[] next(int length)
            throws IOException
Get the next length bytes from the stream.

Parameters:
length - the number of bytes to read.
Returns:
the bytes read or null if EOF is reached before all the bytes have been read.
Throws:
IOException

nextAsText

public String nextAsText(int length)
                  throws IOException
Get the next length bytes from the stream, and return it as a String

Parameters:
length -
Returns:
the decoded String
Throws:
IOException

match

public boolean match(byte[] bytes)
              throws IOException
Look for a fixed set of bytes in the stream. The current position is advanced by the length of the bytes to look for if they are found, otherwise it is left unchanged.

Parameters:
bytes - the bytes to look for
Returns:
true if the bytes were found at the current position.
Throws:
IOException

match

public boolean match(int b)
              throws IOException
Look for a fixed byte in the stream. The current position is advanced by 1 if the byte is found, otherwise it is left unchanged.

Parameters:
b - the byte to look for.
Returns:
true if the byte was found at the current position.
Throws:
IOException

mustMatch

public void mustMatch(byte[] bytes)
               throws IOException,
                      UnexpectedCommandOutputException
Verifies that the next bytes in the stream matches the specified bytes.

Parameters:
bytes -
Throws:
IOException
UnexpectedCommandOutputException - if the stream doesn't match the specified bytes

mustMatch

public void mustMatch(int b)
               throws IOException,
                      UnexpectedCommandOutputException
Verifies that the next byte in the stream matches the specified byte.

Parameters:
b - the next byte
Throws:
IOException
UnexpectedCommandOutputException - if the stream doesn't match the specified bytes

upTo

public byte[] upTo(byte[] stop)
            throws IOException
Read from the stream until a fixed set of bytes are found. The current position is left after the stop bytes.

Parameters:
stop - the bytes to look for.
Returns:
the bytes read while looking for the stop bytes. This does not include the stop bytes themselves.
Throws:
IOException

upTo

public byte[] upTo(int stop)
            throws IOException
Read from the stream until a fixed byte is found. The current position is left after the stop byte.

Parameters:
stop - the byte to look for.
Returns:
the bytes read while looking for the stop byte. This does not include the stop byte.
Throws:
IOException

find

public boolean find(byte[] bytes)
             throws IOException
Search for the specified bytes in the stream. If found then the position in the stream is just after the bytes. If not found, the stream is positioned at EOF.

Parameters:
bytes -
Returns:
true if the bytes were found, false otherwise
Throws:
IOException

find

public boolean find(int b)
             throws IOException
Read from stream until the specified byte is read.

Parameters:
b -
Returns:
true if the byte was found, otherwise false
Throws:
IOException

decimalIntUpTo

public int decimalIntUpTo(int stop)
                   throws IOException
Read a non-negative integer from the stream until a fixed byte is found. The current position is left after the stop byte.

Parameters:
stop - the byte to look for.
Returns:
the integer read.
Throws:
IOException

readDecimal

public Integer readDecimal()
                    throws IOException
Read a non-negative integer from the stream. All characters that are a valid digit is read.

Returns:
null if the next character is a non-digit, otherwise return the integer value of the digit characters read from stream
Throws:
IOException

revisionUpTo

public int revisionUpTo(int stop)
                 throws IOException
Read a revision number from the stream until a fixed byte is found. A revision number is an integer greater than or equal to -1. The current position is left after the stop byte.

Initial spaces in the stream is skipped until a '-' or a digit is found.

Parameters:
stop - the byte to look for.
Returns:
the integer read.
Throws:
IOException

dateTimeUpTo

public DateTime dateTimeUpTo(int stopByte)
                      throws IOException
Read a Mercurial date from the stream, stopping when a fixed byte is met. A Mercurial date is produced with the "hgdate" template filter and consist of two integers, the first is the number of seconds since 1970 and the second is the time zone offset.

Parameters:
stopByte - the stop byte
Returns:
a parsed date
Throws:
IOException

textUpTo

public String textUpTo(byte[] end)
                throws IOException
Read from the stream until end is found, return the read portion as a String. The current position is left after the end marker.

Parameters:
end - the stop marker.
Returns:
the decoded bytes
Throws:
IOException

textUpTo

public String textUpTo(int b)
                throws IOException
Read from the stream until the byte b is found, return the read portion as a String. The current position is left after the b marker.

Parameters:
b - the stop marker.
Returns:
the decoded bytes
Throws:
IOException

consumeAll

public void consumeAll()
                throws IOException
Read until EOF and discard the bytes read

Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011-2013 aragost Trifork ag. All Rights Reserved.