|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.InputStream
com.voytechs.jnetstream.io.ProtocolDataInputStream
public abstract class ProtocolDataInputStream
This stream object extends the DataInputStream which defines how to read basic data types from a binary stream. This stream in addition to the Java native primitives that DataInput defines, add ability to read on a variable bit boundry. Any subset of bits can be read and returned in 'int' data type.
| Field Summary | |
|---|---|
protected int |
bitsLeft
This is the bit offset wihin the bytes that we have read so far. |
protected java.io.DataInputStream |
in
Our source DataInputStream since we require to provide similar interface as it is. |
| Constructor Summary | |
|---|---|
ProtocolDataInputStream(java.io.DataInputStream inputStream)
Initialize with DataInputStream. |
|
ProtocolDataInputStream(java.io.InputStream inputStream)
|
|
| Method Summary | |
|---|---|
protected abstract boolean |
isReady()
|
protected abstract boolean |
isReady(int len)
|
static void |
main(java.lang.String[] args)
Test function for ProtocolDataInputStream |
int |
read()
Any normal read() operation invalidates our bit cache since we only allow reads to happen at the byte boudary. |
int |
readBits(int numOfBits)
Read from the stream number of bits and return them as a 'int' data type while advancing the bit-based position in the stream. |
long |
readBitsLong(int numOfBits)
Read from the stream number of bits and return them as a 'long' data type while advancing the bit-based position in the stream. |
boolean |
readBoolean()
Read one input byte and returns true if that byte is nonzero, false if that bye is zero. |
byte |
readByte()
Read one byte from the stream. |
java.math.BigInteger |
readerUnsignedLongLittleEndian()
|
int |
readFromPacket()
Reads a 1 byte from stream but returns it as an int. |
int |
readFromPacket(byte[] array)
Reads n bytes from stream but returns it as an int. |
int |
readInt()
Reads a 32bit int using Big Endian encoding from stream. |
int |
readIntLittleEndian()
Reads a 32bit int using Little Endian encoding from stream. |
long |
readLong()
Reads a 64bit unsigned int using Big Endian encoding from stream. |
long |
readLongLittleEndian()
Reads a 64bit long int using Little Endian encoding from stream. |
int |
readShort()
Reads a 32bit int using Big Endian encoding from stream. |
short |
readShortLittleEndian()
Reads a 16bit short using Little Endian encoding from stream. |
int |
readUnsignedByte()
Reads a 1 byte from stream but returns it as an int. |
long |
readUnsignedInt()
Reads a 32bit unsigned int using Big Endian encoding from stream. |
long |
readUnsignedIntLittleEndian()
Reads a 32bit int using Little Endian encoding from stream. |
java.math.BigInteger |
readUnsignedLong()
|
int |
readUnsignedShort()
Reads a 16bit unsigned int using Big Endian encoding from stream. |
int |
readUnsignedShortLittleEndian()
Reads a 16bit unsigned short using Little Endian encoding from stream. |
protected void |
reThrow(java.io.IOException ioe)
Conveniece method that checks if the stream has thrown EOFException. |
| Methods inherited from class java.io.InputStream |
|---|
available, close, mark, markSupported, read, read, reset, skip |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected int bitsLeft
protected java.io.DataInputStream in
| Constructor Detail |
|---|
public ProtocolDataInputStream(java.io.DataInputStream inputStream)
inputStream - Stream to read underlying data from.public ProtocolDataInputStream(java.io.InputStream inputStream)
| Method Detail |
|---|
public int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOException - any exceptions thrown by source input stream
public int readBits(int numOfBits)
throws java.io.IOException
numOfBits - Number of bits (0 to 32) to read from the stream
starting at the current byte and bit position. The maximum number of
bits that can be read is 32. 0 count of bits will always return
value 0 and will not advance the position in the stream.
Less then 0 will generate an IvalidArgumentException.
InvalidArgumentExcpeption - is trown if numOfBits is outside
the 0 to 32 range.
java.io.IOException - any IOException thrown by source input stream.
public long readBitsLong(int numOfBits)
throws java.io.IOException
numOfBits - Number of bits (0 to 64) to read from the stream
starting at the current byte and bit position. The maximum number of
bits that can be read is 64. 0 count of bits will always return
value 0 and will not advance the position in the stream.
Less then 0 will generate an IvalidArgumentException.
InvalidArgumentExcpeption - is trown if numOfBits is outside
the 0 to 64 range.
java.io.IOException - any IOException thrown by source input stream.
protected abstract boolean isReady(int len)
throws EOPacket
EOPacket
protected abstract boolean isReady()
throws EOPacket
EOPacket
public byte readByte()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public boolean readBoolean()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public int readInt()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public int readShort()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public long readUnsignedInt()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public int readUnsignedShort()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public long readLong()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public short readShortLittleEndian()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public int readIntLittleEndian()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public long readUnsignedIntLittleEndian()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public long readLongLittleEndian()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public int readUnsignedShortLittleEndian()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public java.math.BigInteger readUnsignedLong()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public java.math.BigInteger readerUnsignedLongLittleEndian()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public int readFromPacket()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public int readFromPacket(byte[] array)
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
public int readUnsignedByte()
throws java.io.IOException,
EOPacket,
EOPacketStream
java.io.IOException
EOPacket
EOPacketStream
protected void reThrow(java.io.IOException ioe)
throws java.io.IOException,
EOPacketStream
ioe - IOException to check if its EOFException.
java.io.IOException - original exception re-thrown again.
EOPacketStream - a replacement exception is thrown which
indicates that end of packet stream has been reached.public static void main(java.lang.String[] args)
args - command line arguments
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||