- All Superinterfaces:
AutoCloseable,Closeable,Stream
- All Known Implementing Classes:
AbstractStreamReader,DefaultStreamReader,SSLStreamReader,TransformerStreamReader
Interface that defines methods for reading primitive types and arrays of primitive types from a stream. A stream is
implemented as a sequence of
Buffers which are supplied by the receiveData method. The stream consumes the
Buffers: after all data has been read from a Buffer, Buffer.dispose() is called.
Note, that StreamReader implementation may not be thread-safe.- Author:
- Ken Cavanaugh, Alexey Stashok
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionintReturn the number of bytes available for get calls.<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 StreamReaderbooleanReturn true if StreamReader has available data, which could be read, or false otherwise.booleanisClosed()Returns true, if StreamReader has been closed, or false otherwise.booleannotifyAvailable(int size) Method returnsFuture, using which it's possible check if StreamReader has required amount of bytes available for reading reading.notifyAvailable(int size, CompletionHandler<Integer> completionHandler) Method returnsFuture, using which it's possible check if StreamReader has required amount of bytes available for reading reading.notifyCondition(Condition condition) notifyCondition(Condition condition, CompletionHandler<Integer> completionHandler) booleanGet the next boolean in the stream.voidreadBooleanArray(boolean[] data) Fill data with booleans (byte 1=true, 0=false) from the stream.bytereadByte()Get the next byte in the stream.voidreadByteArray(byte[] data) Fill data with bytes from the stream.voidreadByteArray(byte[] data, int offset, int length) Fill data with bytes from the stream.voidFill the buffer with data from the stream (that is, copy data from the stream to fill buffer from position to limit).charreadChar()Get the next character in the stream.voidreadCharArray(char[] data) Fill data with characters from the stream.doubleGet the next double in the stream.voidreadDoubleArray(double[] data) Fill data with characters from the stream.floatGet the next float in the stream.voidreadFloatArray(float[] data) Fill data with characters from the stream.intreadInt()Get the next int in the stream.voidreadIntArray(int[] data) Fill data with characters from the stream.longreadLong()Get the next long in the stream.voidreadLongArray(long[] data) Fill data with characters from the stream.shortGet the next short in the stream.voidreadShortArray(short[] data) Fill data with characters from the stream.voidskip(int length) Methods inherited from interface org.glassfish.grizzly.streams.Stream
getConnection
-
Method Details
-
notifyAvailable
Method returnsFuture, using which it's possible check if StreamReader has required amount of bytes available for reading reading.- Parameters:
size- number of bytes, which should become available on StreamReader.- Returns:
Future, using which it's possible to check whether StreamReader has required amount of bytes available for reading.
-
notifyAvailable
Method returnsFuture, using which it's possible check if StreamReader has required amount of bytes available for reading reading.CompletionHandleris also passed to get notified, once required number of bytes will become available for reading.- Parameters:
size- number of bytes, which should become available on StreamReader.completionHandler-CompletionHandler, which will be notified once required number of bytes will become available.- Returns:
Future, using which it's possible to check whether StreamReader has required amount of bytes available for reading.
-
notifyCondition
-
notifyCondition
GrizzlyFuture<Integer> notifyCondition(Condition condition, CompletionHandler<Integer> completionHandler) Method returnsFuture, using which it's possible check if StreamReader meets specificCondition.CompletionHandleris also passed to get notified, once theConditionwill be satisfied.- Parameters:
condition-ConditionStreamReader should meet.completionHandler-CompletionHandler, which will be notified, once theConditionwill be satisfied.- Returns:
Future, using which it's possible to check whether StreamReader meets the requiredCondition.
-
hasAvailable
boolean hasAvailable()Return true if StreamReader has available data, which could be read, or false otherwise.- Returns:
- true if StreamReader has available data, which could be read, or false otherwise.
-
available
int available()Return the number of bytes available for get calls. An attempt to get more data than is present in the stream will either result in blocking (if isBlocking() returns true) or a BufferUnderflowException. -
readBoolean
Get the next boolean in the stream. Requires 1 byte.- Throws:
IOException
-
readByte
Get the next byte in the stream. Requires 1 byte.- Throws:
IOException
-
readChar
Get the next character in the stream. Requires 2 bytes.- Throws:
IOException
-
readShort
Get the next short in the stream. Requires 2 bytes.- Throws:
IOException
-
readInt
Get the next int in the stream. Requires 4 bytes.- Throws:
IOException
-
readLong
Get the next long in the stream. Requires 8 bytes.- Throws:
IOException
-
readFloat
Get the next float in the stream. Requires 4 bytes.- Throws:
IOException
-
readDouble
Get the next double in the stream. Requires 8 bytes.- Throws:
IOException
-
readBooleanArray
Fill data with booleans (byte 1=true, 0=false) from the stream. If this method returns normally, data has been filled completely. Requires data.length bytes.- Throws:
IOException
-
readByteArray
Fill data with bytes from the stream. If this method returns normally, data has been filled completely. Requires data.length bytes.- Throws:
IOException
-
readByteArray
Fill data with bytes from the stream. If this method returns normally, data has been filled completely. Requires data.length bytes.- Throws:
IOException
-
readBytes
Fill the buffer with data from the stream (that is, copy data from the stream to fill buffer from position to limit). This is useful when data must be read from one stream and then added to another stream for further processing.- Throws:
IOException
-
readCharArray
Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 2*data.length bytes.- Throws:
IOException
-
readShortArray
Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 2*data.length bytes.- Throws:
IOException
-
readIntArray
Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 4*data.length bytes.- Throws:
IOException
-
readLongArray
Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 8*data.length bytes.- Throws:
IOException
-
readFloatArray
Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 4*data.length bytes.- Throws:
IOException
-
readDoubleArray
Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 8*data.length bytes.- Throws:
IOException
-
skip
void skip(int length) -
decode
Read and decode data from the StreamReader- Type Parameters:
E- decoded data type- Parameters:
decoder-Transformer- Returns:
Future, which will hold the decoding state.
-
decode
Read and decode data from the StreamReader- Type Parameters:
E- decoded data type- Parameters:
decoder-TransformercompletionHandler-CompletionHandler, which will be notified, when decoder will become ready.- Returns:
Future, which will hold the decoding state.
-
isClosed
boolean isClosed()Returns true, if StreamReader has been closed, or false otherwise.- Returns:
- true, if StreamReader has been closed, or false otherwise.
-
isSupportBufferWindow
boolean isSupportBufferWindow() -
getBufferWindow
Buffer getBufferWindow() -
takeBufferWindow
Buffer takeBufferWindow()
-