net.sf.rej.util
Interface ByteParser

All Known Implementing Classes:
ByteArrayByteParser, StreamByteParser

public interface ByteParser

Interface for reading binary data.

Author:
Sami Koivu

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. This feature is not applicable to streams, so it should not be used. Instead either a mark / reset along with a byte array read approach should be used instead.
 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.
 

Method Detail

getByte

byte getByte()
Returns the next byte available.

Returns:
next byte in the parser.

getBytes

byte[] getBytes(int count)
Returns an array of the next count bytes.

Parameters:
count - the number of bytes to read.
Returns:
a byte array of the data read.

getByteAsInt

int getByteAsInt()
Returns the next unsigned byte available as an int.

Returns:
the unsigned value of the next available byte.

getShortAsInt

int getShortAsInt()
Returns the unsigned value of the next two bytes available in the parser as an int.

Returns:
the next available unsigned short value.

getInt

long getInt()
Returns the unsigned value of the next 4 bytes as a long.

Returns:
long value of the next 4 bytes.

getNewParser

@Deprecated
ByteParser getNewParser()
Deprecated. This feature is not applicable to streams, so it should not be used. Instead either a mark / reset along with a byte array read approach should be used instead.

Creates a new parser starting from the current position independent of this parser.

Returns:
a new parser starting from current position.

setBigEndian

void setBigEndian(boolean bigEndian)
Sets the big-endian mode of this parser.

Parameters:
bigEndian - a boolean value true for big-endian mode, false for non-big-endian mode.

hasMore

boolean hasMore()
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.

Returns:
boolean true if there is still more data available to be read.

getPosition

int getPosition()
Returns the current position of this parser. In other words, the number of bytes read from this parser.

Returns:
the position of this parser.

peekByte

int peekByte()
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 getByteAsInt() other than for the fact that the position is not advanced.

Returns:
the unsigned value of the next available byte.