|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.grizzly.streams.AbstractStreamReader
public abstract class AbstractStreamReader
Each method reads data from the current ByteBuffer. If not enough data is present in the current ByteBuffer, discard is called on the current ByteBuffer and we advance to the next ByteBuffer, or block if not enough data is present. If close() is called, all subsequent method calls will throw an IllegalStateException, and any threads blocked waiting for more data will be unblocked, and continue with an IllegalStateException from the blocking method call.
dataReceived and close may be safely invoked by multiple threads. The other methods must be invoked only by one thread, which is the reader of this data stream.
| Nested Class Summary | |
|---|---|
protected static class |
AbstractStreamReader.NotifyObject
|
| Field Summary | |
|---|---|
protected int |
bufferSize
|
protected LinkedList |
dataRecords
|
protected AbstractStreamReader.NotifyObject |
notifyObject
|
protected Object |
sync
|
protected long |
timeoutMillis
|
| Constructor Summary | |
|---|---|
|
AbstractStreamReader()
|
protected |
AbstractStreamReader(Connection connection)
Create a new ByteBufferReader. |
| Method Summary | |
|---|---|
protected boolean |
append(Object data)
|
boolean |
appendBuffer(Buffer buffer)
Add more data to the end of the stream. |
int |
availableDataSize()
Return the number of bytes available for get calls. |
void |
close()
Closes the StreamReader and causes all subsequent method calls on this object to throw IllegalStateException. |
protected Object |
current()
|
protected void |
ensureRead()
|
protected void |
ensureRead(boolean readIfEmpty)
|
void |
finishBuffer()
Finishes processing of the current StreamReader's source Buffer. |
Buffer |
getBuffer()
Return the current StreamReader's source Buffer. |
int |
getBufferSize()
Get the preferred Buffer size to be used for StreamReader
read operations. |
Connection |
getConnection()
Get the Connection this StreamReader belongs to. |
long |
getTimeout(TimeUnit timeunit)
Get the timeout for StreamReader I/O operations. |
boolean |
hasAvailableData()
Return true if StreamReader has available data, which could be read, or false otherwise. |
boolean |
isBlocking()
Returns the StreamReader mode. |
boolean |
isClosed()
Returns true, if StreamReader has been closed, or false otherwise. |
protected Buffer |
newBuffer(int size)
|
Future<Integer> |
notifyAvailable(int size)
Method returns Future, using which it's possible check if
StreamReader has required amound of bytes available
for reading reading. |
Future<Integer> |
notifyAvailable(int size,
CompletionHandler<Integer> completionHandler)
Method returns Future, using which it's possible check if
StreamReader has required amound of bytes available
for reading reading. |
Future<Integer> |
notifyCondition(Condition<StreamReader> condition)
Method returns Future, using which it's possible check if
StreamReader meets specific Condition. |
protected Object |
poll()
|
protected Buffer |
pollBuffer()
|
protected boolean |
prepend(Object data)
|
boolean |
prependBuffer(Buffer buffer)
Add more data to the beginning of the stream. |
protected abstract Object |
read0()
|
boolean |
readBoolean()
Get the next boolean in the stream. |
void |
readBooleanArray(boolean[] data)
Fill data with booleans (byte 1=true, 0=false) from the stream. |
Buffer |
readBuffer()
Returns the current StreamReader's source Buffer and
makes next available Buffer current. |
byte |
readByte()
Get the next byte in the stream. |
void |
readByteArray(byte[] data)
Fill data with bytes from the stream. |
void |
readByteArray(byte[] data,
int offset,
int length)
Fill data with bytes from the stream. |
void |
readBytes(Buffer buffer)
Fill the buffer with data from the stream (that is, copy data from the stream to fill buffer from position to limit). |
char |
readChar()
Get the next character in the stream. |
void |
readCharArray(char[] data)
Fill data with characters from the stream. |
double |
readDouble()
Get the next double in the stream. |
void |
readDoubleArray(double[] data)
Fill data with characters from the stream. |
float |
readFloat()
Get the next float in the stream. |
void |
readFloatArray(float[] data)
Fill data with characters from the stream. |
int |
readInt()
Get the next int in the stream. |
void |
readIntArray(int[] data)
Fill data with characters from the stream. |
long |
readLong()
Get the next long in the stream. |
void |
readLongArray(long[] data)
Fill data with characters from the stream. |
short |
readShort()
Get the next short in the stream. |
void |
readShortArray(short[] data)
Fill data with characters from the stream. |
void |
setBlocking(boolean isBlocking)
Sets the StreamReader mode. |
void |
setBufferSize(int size)
Set the preferred Buffer size to be used for StreamReader
read operations. |
void |
setConnection(Connection connection)
|
void |
setTimeout(long timeout,
TimeUnit timeunit)
Set the timeout for StreamReader I/O operations. |
protected abstract Buffer |
unwrap(Object data)
|
protected abstract Object |
wrap(Buffer buffer)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.sun.grizzly.streams.StreamReader |
|---|
notifyCondition |
| Field Detail |
|---|
protected int bufferSize
protected long timeoutMillis
protected final Object sync
protected LinkedList dataRecords
protected AbstractStreamReader.NotifyObject notifyObject
| Constructor Detail |
|---|
public AbstractStreamReader()
protected AbstractStreamReader(Connection connection)
timeout - Time in milliseconds to wait for more data: If 0, the reader will
never block.
TimeoutException - when a read operation times out waiting for more data.| Method Detail |
|---|
public boolean isBlocking()
StreamReader mode.
true, if StreamReader is operating in blocking mode, or
false otherwise.
isBlocking in interface StreamReaderStreamReader mode.public void setBlocking(boolean isBlocking)
StreamReader mode.
setBlocking in interface StreamReaderisBlocking - true, if StreamReader is operating in
blocking mode, or false otherwise.public boolean prependBuffer(Buffer buffer)
prependBuffer in interface StreamReaderStreamReader,
or false otherwiseprotected boolean prepend(Object data)
public boolean appendBuffer(Buffer buffer)
appendBuffer in interface StreamReaderStreamReader,
or false otherwiseprotected boolean append(Object data)
public void close()
close in interface Closeablepublic boolean isClosed()
isClosed in interface StreamReader
protected void ensureRead()
throws IOException
IOException
protected void ensureRead(boolean readIfEmpty)
throws IOException
IOExceptionprotected Buffer pollBuffer()
protected Object poll()
public final boolean hasAvailableData()
hasAvailableData in interface StreamReaderpublic int availableDataSize()
availableDataSize in interface StreamReader
public boolean readBoolean()
throws IOException
readBoolean in interface StreamReaderIOException
public byte readByte()
throws IOException
readByte in interface StreamReaderIOException
public char readChar()
throws IOException
readChar in interface StreamReaderIOException
public short readShort()
throws IOException
readShort in interface StreamReaderIOException
public int readInt()
throws IOException
readInt in interface StreamReaderIOException
public long readLong()
throws IOException
readLong in interface StreamReaderIOException
public final float readFloat()
throws IOException
readFloat in interface StreamReaderIOException
public final double readDouble()
throws IOException
readDouble in interface StreamReaderIOException
public void readBooleanArray(boolean[] data)
throws IOException
readBooleanArray in interface StreamReaderIOException
public void readByteArray(byte[] data)
throws IOException
readByteArray in interface StreamReaderIOException
public void readByteArray(byte[] data,
int offset,
int length)
throws IOException
readByteArray in interface StreamReaderIOException
public void readBytes(Buffer buffer)
throws IOException
readBytes in interface StreamReaderIOException
public void readCharArray(char[] data)
throws IOException
readCharArray in interface StreamReaderIOException
public void readShortArray(short[] data)
throws IOException
readShortArray in interface StreamReaderIOException
public void readIntArray(int[] data)
throws IOException
readIntArray in interface StreamReaderIOException
public void readLongArray(long[] data)
throws IOException
readLongArray in interface StreamReaderIOException
public void readFloatArray(float[] data)
throws IOException
readFloatArray in interface StreamReaderIOException
public void readDoubleArray(double[] data)
throws IOException
readDoubleArray in interface StreamReaderIOExceptionpublic Future<Integer> notifyAvailable(int size)
Future, using which it's possible check if
StreamReader has required amound of bytes available
for reading reading.
notifyAvailable in interface StreamReadersize - number of bytes, which should become available on
StreamReader.
Future, using which it's possible to check whether
StreamReader has required amount of bytes available for reading.
public Future<Integer> notifyAvailable(int size,
CompletionHandler<Integer> completionHandler)
Future, using which it's possible check if
StreamReader has required amound of bytes available
for reading reading.
CompletionHandler is also passed to get notified, once required
number of bytes will become available for reading.
notifyAvailable in interface StreamReadersize - number of bytes, which should become available on
StreamReader.completionHandler - CompletionHandler, which will be notified
once required number of bytes will become available.
Future, using which it's possible to check whether
StreamReader has required amount of bytes available for reading.public Future<Integer> notifyCondition(Condition<StreamReader> condition)
Future, using which it's possible check if
StreamReader meets specific Condition.
notifyCondition in interface StreamReadercondition - Condition StreamReader should meet.
Future, using which it's possible to check whether
StreamReader meets the required Condition.
public Buffer readBuffer()
throws IOException
Buffer and
makes next available Buffer current.
readBuffer in interface StreamReaderBuffer
IOExceptionpublic Buffer getBuffer()
Buffer.
Unlike StreamReader.readBuffer(), this method doesn't
make any internal updates of current Buffer.
getBuffer in interface StreamReaderBuffer.protected Object current()
public void finishBuffer()
Buffer. This method doesn't call Buffer.dispose().
finishBuffer in interface StreamReaderpublic Connection getConnection()
Connection this StreamReader belongs to.
getConnection in interface StreamReaderConnection this StreamReader belongs to.public void setConnection(Connection connection)
protected Buffer newBuffer(int size)
public int getBufferSize()
Buffer size to be used for StreamReader
read operations.
getBufferSize in interface StreamReaderBuffer size to be used for StreamReader
read operations.public void setBufferSize(int size)
Buffer size to be used for StreamReader
read operations.
setBufferSize in interface StreamReadersize - the preferred Buffer size to be used for
StreamReader read operations.public long getTimeout(TimeUnit timeunit)
getTimeout in interface StreamReadertimeunit - timeout unit TimeUnit.
public void setTimeout(long timeout,
TimeUnit timeunit)
setTimeout in interface StreamReadertimeout - the timeout for StreamReader I/O operations.timeunit - timeout unit TimeUnit.
protected abstract Object read0()
throws IOException
IOExceptionprotected abstract Object wrap(Buffer buffer)
protected abstract Buffer unwrap(Object data)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||