org.glassfish.grizzly.streams
Interface StreamReader

All Superinterfaces:
java.io.Closeable, Stream
All Known Implementing Classes:
AbstractStreamReader, DefaultStreamReader, SSLStreamReader, TransformerStreamReader

public interface StreamReader
extends Stream

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:
StreamWriter, Connection

Method Summary
 int available()
          Return 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 StreamReader
 Buffer getBufferWindow()
           
 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<java.lang.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<java.lang.Integer> notifyAvailable(int size, CompletionHandler<java.lang.Integer> completionHandler)
          Method returns Future, using which it's possible check if StreamReader has required amount of bytes available for reading reading.
 GrizzlyFuture<java.lang.Integer> notifyCondition(Condition condition)
          Method returns Future, using which it's possible check if StreamReader meets specific Condition.
 GrizzlyFuture<java.lang.Integer> notifyCondition(Condition condition, CompletionHandler<java.lang.Integer> completionHandler)
          Method returns Future, using which it's possible check if StreamReader meets specific Condition.
 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()
           
 
Methods inherited from interface org.glassfish.grizzly.streams.Stream
getConnection
 
Methods inherited from interface java.io.Closeable
close
 

Method Detail

notifyAvailable

GrizzlyFuture<java.lang.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 - 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

GrizzlyFuture<java.lang.Integer> notifyAvailable(int size,
                                                 CompletionHandler<java.lang.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 - 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

GrizzlyFuture<java.lang.Integer> notifyCondition(Condition condition)
Method returns Future, using which it's possible check if StreamReader meets specific Condition.

Parameters:
condition - Condition StreamReader should meet.
Returns:
Future, using which it's possible to check whether StreamReader meets the required Condition.

notifyCondition

GrizzlyFuture<java.lang.Integer> notifyCondition(Condition condition,
                                                 CompletionHandler<java.lang.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 StreamReader should meet.
completionHandler - CompletionHandler, which will be notified, once the Condition will be satisfied.
Returns:
Future, using which it's possible to check whether StreamReader meets the required Condition.

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

boolean readBoolean()
                    throws java.io.IOException
Get the next boolean in the stream. Requires 1 byte.

Throws:
java.io.IOException

readByte

byte readByte()
              throws java.io.IOException
Get the next byte in the stream. Requires 1 byte.

Throws:
java.io.IOException

readChar

char readChar()
              throws java.io.IOException
Get the next character in the stream. Requires 2 bytes.

Throws:
java.io.IOException

readShort

short readShort()
                throws java.io.IOException
Get the next short in the stream. Requires 2 bytes.

Throws:
java.io.IOException

readInt

int readInt()
            throws java.io.IOException
Get the next int in the stream. Requires 4 bytes.

Throws:
java.io.IOException

readLong

long readLong()
              throws java.io.IOException
Get the next long in the stream. Requires 8 bytes.

Throws:
java.io.IOException

readFloat

float readFloat()
                throws java.io.IOException
Get the next float in the stream. Requires 4 bytes.

Throws:
java.io.IOException

readDouble

double readDouble()
                  throws java.io.IOException
Get the next double in the stream. Requires 8 bytes.

Throws:
java.io.IOException

readBooleanArray

void readBooleanArray(boolean[] data)
                      throws java.io.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.

Throws:
java.io.IOException

readByteArray

void readByteArray(byte[] data)
                   throws java.io.IOException
Fill data with bytes from the stream. If this method returns normally, data has been filled completely. Requires data.length bytes.

Throws:
java.io.IOException

readByteArray

void readByteArray(byte[] data,
                   int offset,
                   int length)
                   throws java.io.IOException
Fill data with bytes from the stream. If this method returns normally, data has been filled completely. Requires data.length bytes.

Throws:
java.io.IOException

readBytes

void readBytes(Buffer buffer)
               throws java.io.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.

Throws:
java.io.IOException

readCharArray

void readCharArray(char[] data)
                   throws java.io.IOException
Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 2*data.length bytes.

Throws:
java.io.IOException

readShortArray

void readShortArray(short[] data)
                    throws java.io.IOException
Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 2*data.length bytes.

Throws:
java.io.IOException

readIntArray

void readIntArray(int[] data)
                  throws java.io.IOException
Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 4*data.length bytes.

Throws:
java.io.IOException

readLongArray

void readLongArray(long[] data)
                   throws java.io.IOException
Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 8*data.length bytes.

Throws:
java.io.IOException

readFloatArray

void readFloatArray(float[] data)
                    throws java.io.IOException
Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 4*data.length bytes.

Throws:
java.io.IOException

readDoubleArray

void readDoubleArray(double[] data)
                     throws java.io.IOException
Fill data with characters from the stream. If this method returns normally, data has been filled completely. Requires 8*data.length bytes.

Throws:
java.io.IOException

skip

void skip(int length)

decode

<E> GrizzlyFuture<E> decode(Transformer<Stream,E> decoder)
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

<E> GrizzlyFuture<E> decode(Transformer<Stream,E> decoder,
                            CompletionHandler<E> completionHandler)
Read and decode data from the StreamReader

Type Parameters:
E - decoded data type
Parameters:
decoder - Transformer
completionHandler - 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()


Copyright © 2011 Oracle Corpration. All Rights Reserved.