Top Description Methods
org.glassfish.grizzly.streams

public Interface StreamReader

extends Stream
Known Direct Implementers
org.glassfish.grizzly.streams.AbstractStreamReader
Imports
java.io.IOException, java.util.concurrent.Future, org.glassfish.grizzly.Buffer, .CompletionHandler, .Connection, .GrizzlyFuture, .Transformer, org.glassfish.grizzly.utils.conditions.Condition

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.
Authors
Ken Cavanaugh, Alexey Stashok
See Also
StreamWriter, Connection

Method Summary

Modifier and TypeMethod and Description
public int
available()

Return the number of bytes available for get calls.

public <
decoded data type
E
>
GrizzlyFuture<E>

Returns:

Future, which will hold the decoding state.
decode
(Transformer<Stream, E> decoder)

Read and decode data from the StreamReader

public <
decoded data type
E
>
GrizzlyFuture<E>

Returns:

Future, which will hold the decoding state.
decode
(Transformer<Stream, E> decoder, CompletionHandler<E>
CompletionHandler, which will be notified, when decoder will become ready.
completionHandler
)

Read and decode data from the StreamReader

public Buffer
public boolean

Returns:

true if StreamReader has available data, which could be read, or false otherwise.
hasAvailable
()

Return true if StreamReader has available data, which could be read, or false otherwise.

public boolean

Returns:

true, if StreamReader has been closed, or false otherwise.
isClosed
()

Returns true, if StreamReader has been closed, or false otherwise.

public boolean
public GrizzlyFuture<Integer>

Returns:

Future, using which it's possible to check whether StreamReader has required amount of bytes available for reading.
notifyAvailable
(int
number of bytes, which should become available on StreamReader.
size
)

Method returns Future, using which it's possible check if StreamReader has required amount of bytes available for reading reading.

public GrizzlyFuture<Integer>

Returns:

Future, using which it's possible to check whether StreamReader has required amount of bytes available for reading.
notifyAvailable
(int
number of bytes, which should become available on StreamReader.
size
,
CompletionHandler<Integer>
CompletionHandler, which will be notified once required number of bytes will become available.
completionHandler
)

Method returns Future, using which it's possible check if StreamReader has required amount of bytes available for reading reading.

public GrizzlyFuture<Integer>

Returns:

Future, using which it's possible to check whether StreamReader meets the required Condition.
notifyCondition
(Condition
Condition StreamReader should meet.
condition
)

Method returns Future, using which it's possible check if StreamReader meets specific Condition.

public GrizzlyFuture<Integer>

Returns:

Future, using which it's possible to check whether StreamReader meets the required Condition.
notifyCondition
(Condition
Condition StreamReader should meet.
condition
,
CompletionHandler<Integer>
CompletionHandler, which will be notified, once the Condition will be satisfied.
completionHandler
)

Method returns Future, using which it's possible check if StreamReader meets specific Condition.

public boolean
readBoolean()

Get the next boolean in the stream.

public void
readBooleanArray(boolean[] data)

Fill data with booleans (byte 1=true, 0=false) from the stream.

public byte
readByte()

Get the next byte in the stream.

public void
readByteArray(byte[] data)

Fill data with bytes from the stream.

public void
readByteArray(byte[] data, int offset, int length)

Fill data with bytes from the stream.

public 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).

public char
readChar()

Get the next character in the stream.

public void
readCharArray(char[] data)

Fill data with characters from the stream.

public double
readDouble()

Get the next double in the stream.

public void
readDoubleArray(double[] data)

Fill data with characters from the stream.

public float
readFloat()

Get the next float in the stream.

public void
readFloatArray(float[] data)

Fill data with characters from the stream.

public int
readInt()

Get the next int in the stream.

public void
readIntArray(int[] data)

Fill data with characters from the stream.

public long
readLong()

Get the next long in the stream.

public void
readLongArray(long[] data)

Fill data with characters from the stream.

public short
readShort()

Get the next short in the stream.

public void
readShortArray(short[] data)

Fill data with characters from the stream.

public void
skip(int length)

public Buffer
Inherited from org.glassfish.grizzly.streams.Stream:
getConnection

Method Detail

availableback to summary
public 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.

decodeback to summary
public <E> GrizzlyFuture<E> decode(Transformer<Stream, E> decoder)

Read and decode data from the StreamReader

Parameters
<E>
decoded data type
decoder:Transformer<Stream, E>

Transformer

Returns:GrizzlyFuture<E>

Future, which will hold the decoding state.

decodeback to summary
public <E> GrizzlyFuture<E> decode(Transformer<Stream, E> decoder, CompletionHandler<E> completionHandler)

Read and decode data from the StreamReader

Parameters
<E>
decoded data type
decoder:Transformer<Stream, E>

Transformer

completionHandler:CompletionHandler<E>

CompletionHandler, which will be notified, when decoder will become ready.

Returns:GrizzlyFuture<E>

Future, which will hold the decoding state.

getBufferWindowback to summary
public Buffer getBufferWindow()
hasAvailableback to summary
public boolean hasAvailable()

Return true if StreamReader has available data, which could be read, or false otherwise.

Returns:boolean

true if StreamReader has available data, which could be read, or false otherwise.

isClosedback to summary
public boolean isClosed()

Returns true, if StreamReader has been closed, or false otherwise.

Returns:boolean

true, if StreamReader has been closed, or false otherwise.

isSupportBufferWindowback to summary
public boolean isSupportBufferWindow()
notifyAvailableback to summary
public 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.

Parameters
size:int

number of bytes, which should become available on StreamReader.

Returns:GrizzlyFuture<Integer>

Future, using which it's possible to check whether StreamReader has required amount of bytes available for reading.

notifyAvailableback to summary
public 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. CompletionHandler is also passed to get notified, once required number of bytes will become available for reading.

Parameters
size:int

number of bytes, which should become available on StreamReader.

completionHandler:CompletionHandler<Integer>

CompletionHandler, which will be notified once required number of bytes will become available.

Returns:GrizzlyFuture<Integer>

Future, using which it's possible to check whether StreamReader has required amount of bytes available for reading.

notifyConditionback to summary
public GrizzlyFuture<Integer> notifyCondition(Condition condition)

Method returns Future, using which it's possible check if StreamReader meets specific Condition.

Parameters
condition:Condition

Condition StreamReader should meet.

Returns:GrizzlyFuture<Integer>

Future, using which it's possible to check whether StreamReader meets the required Condition.

notifyConditionback to summary
public GrizzlyFuture<Integer> notifyCondition(Condition condition, CompletionHandler<Integer> completionHandler)

Method returns 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.

Parameters
condition:Condition

Condition StreamReader should meet.

completionHandler:CompletionHandler<Integer>

CompletionHandler, which will be notified, once the Condition will be satisfied.

Returns:GrizzlyFuture<Integer>

Future, using which it's possible to check whether StreamReader meets the required Condition.

readBooleanback to summary
public boolean readBoolean() throws IOException

Get the next boolean in the stream. Requires 1 byte.

readBooleanArrayback to summary
public void readBooleanArray(boolean[] data) throws IOException

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.

readByteback to summary
public byte readByte() throws IOException

Get the next byte in the stream. Requires 1 byte.

readByteArrayback to summary
public void readByteArray(byte[] data) throws IOException

Fill data with bytes from the stream. If this method returns normally, data has been filled completely. Requires data.length bytes.

readByteArrayback to summary
public void readByteArray(byte[] data, int offset, int length) throws IOException

Fill data with bytes from the stream. If this method returns normally, data has been filled completely. Requires data.length bytes.

readBytesback to summary
public void readBytes(Buffer buffer) throws IOException

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.

readCharback to summary
public char readChar() throws IOException

Get the next character in the stream. Requires 2 bytes.

readCharArrayback to summary
public void readCharArray(char[] data) throws IOException

Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 2*data.length bytes.

readDoubleback to summary
public double readDouble() throws IOException

Get the next double in the stream. Requires 8 bytes.

readDoubleArrayback to summary
public void readDoubleArray(double[] data) throws IOException

Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 8*data.length bytes.

readFloatback to summary
public float readFloat() throws IOException

Get the next float in the stream. Requires 4 bytes.

readFloatArrayback to summary
public void readFloatArray(float[] data) throws IOException

Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 4*data.length bytes.

readIntback to summary
public int readInt() throws IOException

Get the next int in the stream. Requires 4 bytes.

readIntArrayback to summary
public void readIntArray(int[] data) throws IOException

Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 4*data.length bytes.

readLongback to summary
public long readLong() throws IOException

Get the next long in the stream. Requires 8 bytes.

readLongArrayback to summary
public void readLongArray(long[] data) throws IOException

Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 8*data.length bytes.

readShortback to summary
public short readShort() throws IOException

Get the next short in the stream. Requires 2 bytes.

readShortArrayback to summary
public void readShortArray(short[] data) throws IOException

Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 2*data.length bytes.

skipback to summary
public void skip(int length)
takeBufferWindowback to summary
public Buffer takeBufferWindow()