com.sun.grizzly.streams
Interface StreamReader

All Superinterfaces:
Closeable
All Known Subinterfaces:
AddressableStreamReader<A>
All Known Implementing Classes:
AbstractStreamReader, SSLStreamReader, StreamReaderDecorator, TCPNIOStreamReader, UDPNIOStreamReader

public interface StreamReader
extends Closeable

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
 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 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.
 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.
 Future<Integer> notifyCondition(Condition<StreamReader> condition, CompletionHandler<Integer> completionHandler)
          Method returns Future, using which it's possible check if StreamReader meets specific Condition.
 boolean prependBuffer(Buffer buffer)
          Add more data to the beginning of the stream.
 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 setTimeout(long timeout, TimeUnit timeunit)
          Set the timeout for StreamReader I/O operations.
 
Methods inherited from interface java.io.Closeable
close
 

Method Detail

isBlocking

boolean isBlocking()
Returns the StreamReader mode. true, if StreamReader is operating in blocking mode, or false otherwise.

Returns:
the StreamReader mode.

setBlocking

void setBlocking(boolean isBlocking)
Sets the StreamReader mode.

Parameters:
isBlocking - true, if StreamReader is operating in blocking mode, or false otherwise.

notifyAvailable

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.

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

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

Future<Integer> notifyCondition(Condition<StreamReader> 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

Future<Integer> notifyCondition(Condition<StreamReader> 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 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.

prependBuffer

boolean prependBuffer(Buffer buffer)
Add more data to the beginning of the stream.

Returns:
true, if buffer was prepended to the StreamReader, or false otherwise

appendBuffer

boolean appendBuffer(Buffer buffer)
Add more data to the end of the stream.

Returns:
true, if buffer was appended to the StreamReader, or false otherwise

hasAvailableData

boolean hasAvailableData()
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.

availableDataSize

int availableDataSize()
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 IOException
Get the next boolean in the stream. Requires 1 byte.

Throws:
IOException

readByte

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

Throws:
IOException

readChar

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

Throws:
IOException

readShort

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

Throws:
IOException

readInt

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

Throws:
IOException

readLong

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

Throws:
IOException

readFloat

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

Throws:
IOException

readDouble

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

Throws:
IOException

readBooleanArray

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.

Throws:
IOException

readByteArray

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.

Throws:
IOException

readByteArray

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.

Throws:
IOException

readBytes

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.

Throws:
IOException

readCharArray

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.

Throws:
IOException

readShortArray

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.

Throws:
IOException

readIntArray

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.

Throws:
IOException

readLongArray

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.

Throws:
IOException

readFloatArray

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.

Throws:
IOException

readDoubleArray

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.

Throws:
IOException

isClosed

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

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

readBuffer

Buffer readBuffer()
                  throws IOException
Returns the current StreamReader's source Buffer and makes next available Buffer current.

Returns:
the current StreamReader's source Buffer
Throws:
IOException

getBuffer

Buffer getBuffer()
Return the current StreamReader's source Buffer. Unlike readBuffer(), this method doesn't make any internal updates of current Buffer.

Returns:
the current StreamReader's source Buffer.

finishBuffer

void finishBuffer()
Finishes processing of the current StreamReader's source Buffer. This method doesn't call Buffer.dispose().


getConnection

Connection getConnection()
Get the Connection this StreamReader belongs to.

Returns:
the Connection this StreamReader belongs to.

getBufferSize

int getBufferSize()
Get the preferred Buffer size to be used for StreamReader read operations.

Returns:
the preferred Buffer size to be used for StreamReader read operations.

setBufferSize

void setBufferSize(int size)
Set the preferred Buffer size to be used for StreamReader read operations.

Parameters:
size - the preferred Buffer size to be used for StreamReader read operations.

getTimeout

long getTimeout(TimeUnit timeunit)
Get the timeout for StreamReader I/O operations.

Parameters:
timeunit - timeout unit TimeUnit.
Returns:
the timeout for StreamReader I/O operations.

setTimeout

void setTimeout(long timeout,
                TimeUnit timeunit)
Set the timeout for StreamReader I/O operations.

Parameters:
timeout - the timeout for StreamReader I/O operations.
timeunit - timeout unit TimeUnit.


Copyright © 2009 SUN Microsystems. All Rights Reserved.