public abstract class AbstractStreamReader extends Object implements StreamReader
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.
Modifier and Type | Field and Description |
---|---|
protected Connection |
connection |
protected Input |
input |
protected AtomicBoolean |
isClosed |
Modifier | Constructor and Description |
---|---|
protected |
AbstractStreamReader(Connection connection,
Input streamInput)
Create a new ByteBufferReader.
|
Modifier and Type | Method and Description |
---|---|
int |
available()
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.
|
<E> GrizzlyFuture<E> |
decode(Transformer<Stream,E> decoder)
Read and decode data from the StreamReader
|
<E> GrizzlyFuture<E> |
decode(Transformer<Stream,E> decoder,
CompletionHandler<E> completionHandler)
Read and decode data from the StreamReader
|
Buffer |
getBufferWindow() |
Connection |
getConnection()
Get the
Connection this StreamReader belongs to. |
boolean |
hasAvailable()
Return true if StreamReader has available data, which
could be read, or false otherwise.
|
boolean |
isClosed()
Returns true, if StreamReader has been closed,
or false otherwise.
|
boolean |
isSupportBufferWindow() |
GrizzlyFuture<Integer> |
notifyAvailable(int size)
Method returns
Future , using which it's possible check if
StreamReader has required amount of bytes available
for reading reading. |
GrizzlyFuture<Integer> |
notifyAvailable(int size,
CompletionHandler<Integer> completionHandler)
Method returns
Future , using which it's possible check if
StreamReader has required amount of bytes available
for reading reading. |
GrizzlyFuture<Integer> |
notifyCondition(Condition condition)
|
GrizzlyFuture<Integer> |
notifyCondition(Condition condition,
CompletionHandler<Integer> completionHandler)
|
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.
|
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 |
skip(int length) |
Buffer |
takeBufferWindow() |
protected final Connection connection
protected final Input input
protected final AtomicBoolean isClosed
protected AbstractStreamReader(Connection connection, Input streamInput)
connection
- the Connection
to be associated with this
AbstractStreamReader
streamInput
- the stream sourcepublic boolean readBoolean() throws IOException
readBoolean
in interface StreamReader
IOException
public byte readByte() throws IOException
readByte
in interface StreamReader
IOException
public char readChar() throws IOException
readChar
in interface StreamReader
IOException
public short readShort() throws IOException
readShort
in interface StreamReader
IOException
public int readInt() throws IOException
readInt
in interface StreamReader
IOException
public long readLong() throws IOException
readLong
in interface StreamReader
IOException
public final float readFloat() throws IOException
readFloat
in interface StreamReader
IOException
public final double readDouble() throws IOException
readDouble
in interface StreamReader
IOException
public void readBooleanArray(boolean[] data) throws IOException
readBooleanArray
in interface StreamReader
IOException
public void readByteArray(byte[] data) throws IOException
readByteArray
in interface StreamReader
IOException
public void readByteArray(byte[] data, int offset, int length) throws IOException
readByteArray
in interface StreamReader
IOException
public void readBytes(Buffer buffer) throws IOException
readBytes
in interface StreamReader
IOException
public void readCharArray(char[] data) throws IOException
readCharArray
in interface StreamReader
IOException
public void readShortArray(short[] data) throws IOException
readShortArray
in interface StreamReader
IOException
public void readIntArray(int[] data) throws IOException
readIntArray
in interface StreamReader
IOException
public void readLongArray(long[] data) throws IOException
readLongArray
in interface StreamReader
IOException
public void readFloatArray(float[] data) throws IOException
readFloatArray
in interface StreamReader
IOException
public void readDoubleArray(double[] data) throws IOException
readDoubleArray
in interface StreamReader
IOException
public void skip(int length)
skip
in interface StreamReader
public <E> GrizzlyFuture<E> decode(Transformer<Stream,E> decoder)
decode
in interface StreamReader
E
- decoded data typedecoder
- Transformer
Future
, which will hold the decoding state.public <E> GrizzlyFuture<E> decode(Transformer<Stream,E> decoder, CompletionHandler<E> completionHandler)
decode
in interface StreamReader
E
- decoded data typedecoder
- Transformer
completionHandler
- CompletionHandler
, which will be
notified, when decoder will become ready.Future
, which will hold the decoding state.public GrizzlyFuture<Integer> notifyAvailable(int size)
Future
, using which it's possible check if
StreamReader has required amount of bytes available
for reading reading.notifyAvailable
in interface StreamReader
size
- 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 GrizzlyFuture<Integer> notifyAvailable(int size, CompletionHandler<Integer> completionHandler)
Future
, using which it's possible check if
StreamReader has required amount 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 StreamReader
size
- 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 GrizzlyFuture<Integer> notifyCondition(Condition condition)
notifyCondition
in interface StreamReader
condition
- Condition
StreamReader should meet.Future
, using which it's possible to check whether
StreamReader meets the required Condition
.public GrizzlyFuture<Integer> notifyCondition(Condition condition, CompletionHandler<Integer> completionHandler)
Future
, using which it's possible check if
StreamReader meets specific Condition
.
CompletionHandler
is also passed to get notified, once
the Condition
will be satisfied.notifyCondition
in interface StreamReader
condition
- Condition
StreamReader should meet.completionHandler
- CompletionHandler
, which will be
notified, once the Condition
will be satisfied.Future
, using which it's possible to check whether
StreamReader meets the required Condition
.public void close()
close
in interface Closeable
close
in interface AutoCloseable
public boolean isClosed()
isClosed
in interface StreamReader
public final boolean hasAvailable()
hasAvailable
in interface StreamReader
public int available()
available
in interface StreamReader
public boolean isSupportBufferWindow()
isSupportBufferWindow
in interface StreamReader
public Buffer getBufferWindow()
getBufferWindow
in interface StreamReader
public Buffer takeBufferWindow()
takeBufferWindow
in interface StreamReader
public Connection getConnection()
Connection
this StreamReader belongs to.getConnection
in interface Stream
Connection
this StreamReader belongs to.Copyright © 2015 Oracle Corporation. All rights reserved.