|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
java.io.FilterInputStream
com.claritysys.io.MessageInputStream
public final class MessageInputStream
A MessageInputStream is used to receive data from an underlying InputStream where each block of bytes contains a 2 byte length header, in network byte order, of the amount of data contained in the message. The length does not include the 2 byte header.
Field Summary | |
---|---|
protected boolean |
atEOF
A flag to remember that we've already hit EOF. |
protected byte[] |
buffer
The buffer in which message bytes are queued up for reading. |
protected int |
dataLength
The current length of data in the buffer. |
Fields inherited from class java.io.FilterInputStream |
---|
in |
Constructor Summary | |
---|---|
MessageInputStream(java.io.InputStream in)
Create a new MessageInputStream on the given InputStream. |
Method Summary | |
---|---|
int |
read(byte[] b)
Read an array full of bytes from this stream. |
int |
read(byte[] b,
int off,
int len)
Read an array full of bytes from this stream. |
java.lang.String |
readString()
Read a String from the underlying stream. |
int |
receive()
Wait for an incoming message from the InputStream. |
Methods inherited from class java.io.FilterInputStream |
---|
available, close, mark, markSupported, read, reset, skip |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected byte[] buffer
protected int dataLength
protected boolean atEOF
Constructor Detail |
---|
public MessageInputStream(java.io.InputStream in)
in
- The underlying InputStream to read from.Method Detail |
---|
public int read(byte[] b) throws java.io.IOException
Be sure that the array is larger than any potential message.
read
in class java.io.FilterInputStream
b
- A byte array to read data into.
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
Be sure that the array is larger than any potential message.
read
in class java.io.FilterInputStream
b
- A byte array to read data into.off
- The starting position to read into.len
- The maximum number of bytes to read.
java.io.IOException
public java.lang.String readString() throws java.io.IOException
If data has been read from this stream already this will return the remaining data. If there is no data available, this will block until a message is received.
java.io.IOException
String.String(byte[],int,int)
public int receive() throws java.io.IOException
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |