|
|||||||||
| Home >> All >> com >> voytechs >> jnetstream >> [ io overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.voytechs.jnetstream.io
Class ProtocolDataInputStream

java.lang.Objectjava.io.InputStream
com.voytechs.jnetstream.io.ProtocolDataInputStream
- All Implemented Interfaces:
- java.io.Closeable
- Direct Known Subclasses:
- PacketInputStream
- public abstract class ProtocolDataInputStream
- extends java.io.InputStream
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. |
private int |
cacheByte
Keep the current byte value out of which we are reading various bits. |
private static boolean |
debug
|
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)
|
private void |
loadChacheByte()
|
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. |
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. |
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 |
debug
private static final boolean debug
- See Also:
- Constant Field Values
cacheByte
private int cacheByte
- Keep the current byte value out of which we are reading various bits.
Only have to keep track of the last byte.
bitsLeft
protected int bitsLeft
- This is the bit offset wihin the bytes that we have read so far.
If bitsLeft == 0 then there is no real data in the chachedByte variable
if bitsLeft > 1 and bitOffset < 7 then we have real data in the
cached byte and should read from upto the remainder of the cache.
It should always have values between 0 and 7;
in
protected java.io.DataInputStream in
- Our source DataInputStream since we require to provide similar
interface as it is.
| Constructor Detail |
ProtocolDataInputStream
public ProtocolDataInputStream(java.io.DataInputStream inputStream)
- Initialize with DataInputStream. We will besides the baseclasses
functions to read native data types from the stream we will define
methods for accessing on variouable bit boundries.
ProtocolDataInputStream
public ProtocolDataInputStream(java.io.InputStream inputStream)
| Method Detail |
read
public int read()
throws java.io.IOException
- Any normal read() operation invalidates our bit cache since we only
allow reads to happen at the byte boudary.
readBits
public int readBits(int numOfBits)
throws java.io.IOException
- Read from the stream number of bits and return them as a 'int' data type
while advancing the bit-based position in the stream.
readBitsLong
public long readBitsLong(int numOfBits)
throws java.io.IOException
- Read from the stream number of bits and return them as a 'long' data type
while advancing the bit-based position in the stream.
loadChacheByte
private void loadChacheByte()
throws java.io.IOException
isReady
protected abstract boolean isReady(int len)
throws EOPacket
isReady
protected abstract boolean isReady()
throws EOPacket
readByte
public byte readByte()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Read one byte from the stream.
readBoolean
public boolean readBoolean()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Read one input byte and returns true if that byte is nonzero,
false if that bye is zero.
readInt
public int readInt()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads a 32bit int using Big Endian encoding from stream.
readShort
public int readShort()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads a 32bit int using Big Endian encoding from stream.
readUnsignedInt
public long readUnsignedInt()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads a 32bit unsigned int using Big Endian encoding from stream.
readUnsignedShort
public int readUnsignedShort()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads a 16bit unsigned int using Big Endian encoding from stream.
readLong
public long readLong()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads a 64bit unsigned int using Big Endian encoding from stream.
readShortLittleEndian
public short readShortLittleEndian()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads a 16bit short using Little Endian encoding from stream.
readIntLittleEndian
public int readIntLittleEndian()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads a 32bit int using Little Endian encoding from stream.
readUnsignedIntLittleEndian
public long readUnsignedIntLittleEndian()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads a 32bit int using Little Endian encoding from stream.
readLongLittleEndian
public long readLongLittleEndian()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads a 64bit long int using Little Endian encoding from stream.
readUnsignedShortLittleEndian
public int readUnsignedShortLittleEndian()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads a 16bit unsigned short using Little Endian encoding from stream.
readFromPacket
public int readFromPacket()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads a 1 byte from stream but returns it as an int.
This is replaces the normal read() method but implements
ProtocolStream specific exception reporting.
readFromPacket
public int readFromPacket(byte[] array)
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads n bytes from stream but returns it as an int.
This is replaces the normal read() method but implements
ProtocolStream specific exception reporting.
readUnsignedByte
public int readUnsignedByte()
throws java.io.IOException,
EOPacket,
EOPacketStream
- Reads a 1 byte from stream but returns it as an int.
This is replaces the normal read() method but implements
ProtocolStream specific exception reporting.
reThrow
protected void reThrow(java.io.IOException ioe) throws java.io.IOException, EOPacketStream
- Conveniece method that checks if the stream has thrown
EOFException. If yes then EOPacketStream exception is thrown
instead otherwise the original exception is re-thrown.
This method always throws an exception. Either original or new
EOPacketStream.
main
public static void main(java.lang.String[] args)
- Test function for ProtocolDataInputStream
|
|||||||||
| Home >> All >> com >> voytechs >> jnetstream >> [ io overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC