net.sf.rej.util
Class StreamByteParser

java.lang.Object
  extended by net.sf.rej.util.StreamByteParser
All Implemented Interfaces:
ByteParser

public class StreamByteParser
extends java.lang.Object
implements ByteParser

A ByteParser subclass providing parsing of a stream instead of a byte array (as is the case with ByteParser class).

Author:
Sami Koivu

Constructor Summary
StreamByteParser(java.io.InputStream in)
          Initializes a new parser with the given InputStream.
 
Method Summary
 byte getByte()
          Returns the next byte available.
 int getByteAsInt()
          Returns the next unsigned byte available as an int.
 byte[] getBytes(int count)
          Returns an array of the next count bytes.
 long getInt()
          Returns the unsigned value of the next 4 bytes as a long.
 ByteParser getNewParser()
          Deprecated. 
 int getPosition()
          Returns the current position of this parser.
 int getShortAsInt()
          Returns the unsigned value of the next two bytes available in the parser as an int.
 boolean hasMore()
          Returns true if the end of the underlying data source has not been reached yet.
 int peekByte()
          Returns an unsigned value of the next byte in this parser, without advancing the position of the parser.
 void setBigEndian(boolean bigEndian)
          Sets the big-endian mode of this parser.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamByteParser

public StreamByteParser(java.io.InputStream in)
Initializes a new parser with the given InputStream.

Parameters:
in - the steam to parse.
Method Detail

getByte

public byte getByte()
             throws ParsingException
Description copied from interface: ByteParser
Returns the next byte available.

Specified by:
getByte in interface ByteParser
Returns:
next byte in the parser.
Throws:
ParsingException

getBytes

public byte[] getBytes(int count)
                throws ParsingException
Description copied from interface: ByteParser
Returns an array of the next count bytes.

Specified by:
getBytes in interface ByteParser
Parameters:
count - the number of bytes to read.
Returns:
a byte array of the data read.
Throws:
ParsingException

getByteAsInt

public int getByteAsInt()
                 throws ParsingException
Description copied from interface: ByteParser
Returns the next unsigned byte available as an int.

Specified by:
getByteAsInt in interface ByteParser
Returns:
the unsigned value of the next available byte.
Throws:
ParsingException

getShortAsInt

public int getShortAsInt()
                  throws ParsingException
Description copied from interface: ByteParser
Returns the unsigned value of the next two bytes available in the parser as an int.

Specified by:
getShortAsInt in interface ByteParser
Returns:
the next available unsigned short value.
Throws:
ParsingException

getInt

public long getInt()
            throws ParsingException
Description copied from interface: ByteParser
Returns the unsigned value of the next 4 bytes as a long.

Specified by:
getInt in interface ByteParser
Returns:
long value of the next 4 bytes.
Throws:
ParsingException

getNewParser

@Deprecated
public ByteParser getNewParser()
                        throws ParsingException
Deprecated. 

Description copied from interface: ByteParser
Creates a new parser starting from the current position independent of this parser.

Specified by:
getNewParser in interface ByteParser
Returns:
a new parser starting from current position.
Throws:
ParsingException

setBigEndian

public void setBigEndian(boolean bigEndian)
Description copied from interface: ByteParser
Sets the big-endian mode of this parser.

Specified by:
setBigEndian in interface ByteParser
Parameters:
bigEndian - a boolean value true for big-endian mode, false for non-big-endian mode.

hasMore

public boolean hasMore()
                throws ParsingException
Description copied from interface: ByteParser
Returns true if the end of the underlying data source has not been reached yet. Not that the return of this method in no way indicates that data is available for immediate reading, for example of the underlying data source is a socket.

Specified by:
hasMore in interface ByteParser
Returns:
boolean true if there is still more data available to be read.
Throws:
ParsingException

getPosition

public int getPosition()
Description copied from interface: ByteParser
Returns the current position of this parser. In other words, the number of bytes read from this parser.

Specified by:
getPosition in interface ByteParser
Returns:
the position of this parser.

peekByte

public int peekByte()
Description copied from interface: ByteParser
Returns an unsigned value of the next byte in this parser, without advancing the position of the parser. Thus, if this method is called n times in succession without calling the other methods of this class, a value i will be consistently returned every time. This method is identical to the method ByteParser.getByteAsInt() other than for the fact that the position is not advanced.

Specified by:
peekByte in interface ByteParser
Returns:
the unsigned value of the next available byte.