Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.streams

public abstract Class AbstractStreamReader

extends Object
implements StreamReader
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.streams.StreamReader, org.glassfish.grizzly.streams.Stream, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
org.glassfish.grizzly.streams.TransformerStreamReader, org.glassfish.grizzly.nio.transport.DefaultStreamReader
Imports
java.io.EOFException, .IOException, java.nio.BufferUnderflowException, java.util.concurrent.atomic.AtomicBoolean, java.util.logging.Logger, org.glassfish.grizzly.Buffer, .CompletionHandler, .Connection, .Grizzly, .GrizzlyFuture, .Transformer, org.glassfish.grizzly.impl.FutureImpl, .ReadyFutureImpl, .SafeFutureImpl, org.glassfish.grizzly.utils.CompletionHandlerAdapter, .ResultAware, org.glassfish.grizzly.utils.conditions.Condition

Each method reads data from the current ByteBuffer. If not enough data is present in the current ByteBuffer, discard is called on the current ByteBuffer and we advance to the next ByteBuffer, or block if not enough data is present. If close() is called, all subsequent method calls will throw an IllegalStateException, and any threads blocked waiting for more data will be unblocked, and continue with an IllegalStateException from the blocking method call.

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.

Authors
Ken Cavanaugh, Alexey Stashok

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
protected final Connection<L>
private static final boolean
protected final Input
protected final AtomicBoolean
private static final Logger

Constructor Summary

AccessConstructor and Description
protected
AbstractStreamReader(Connection<L>
the Connection to be associated with this AbstractStreamReader
connection
,
Input
the stream source
streamInput
)

Create a new ByteBufferReader.

Method Summary

Modifier and TypeMethod and Description
private void
arraySizeCheck(final int sizeInBytes)

public int
available()

Implements org.glassfish.grizzly.streams.StreamReader.available.

Return the number of bytes available for get calls.

public void
close()

Implements java.io.Closeable.close.

Closes the StreamReader and causes all subsequent method calls on this object to throw IllegalStateException.

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

Implements org.glassfish.grizzly.streams.StreamReader.decode.

Read and decode data from the StreamReader

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

Implements org.glassfish.grizzly.streams.StreamReader.decode.

Read and decode data from the StreamReader

public Buffer
public Connection<L>
getConnection()

Implements org.glassfish.grizzly.streams.Stream.getConnection.

Get the Connection this StreamReader belongs to.

public final boolean
hasAvailable()

Implements org.glassfish.grizzly.streams.StreamReader.hasAvailable.

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

public boolean
isClosed()

Implements org.glassfish.grizzly.streams.StreamReader.isClosed.

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

public boolean
public GrizzlyFuture<Integer>
notifyAvailable(int size)

Implements org.glassfish.grizzly.streams.StreamReader.notifyAvailable.

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

public GrizzlyFuture<Integer>
notifyAvailable(final int size, CompletionHandler<Integer> completionHandler)

Implements org.glassfish.grizzly.streams.StreamReader.notifyAvailable.

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

public GrizzlyFuture<Integer>
notifyCondition(Condition condition)

Implements org.glassfish.grizzly.streams.StreamReader.notifyCondition.

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

public synchronized GrizzlyFuture<Integer>
notifyCondition(final Condition condition, final CompletionHandler<Integer> completionHandler)

Implements org.glassfish.grizzly.streams.StreamReader.notifyCondition.

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

public boolean
readBoolean()

Implements org.glassfish.grizzly.streams.StreamReader.readBoolean.

Get the next boolean in the stream.

public void
readBooleanArray(boolean[] data)

Implements org.glassfish.grizzly.streams.StreamReader.readBooleanArray.

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

public byte
readByte()

Implements org.glassfish.grizzly.streams.StreamReader.readByte.

Get the next byte in the stream.

public void
readByteArray(final byte[] data)

Implements org.glassfish.grizzly.streams.StreamReader.readByteArray.

Fill data with bytes from the stream.

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

Implements org.glassfish.grizzly.streams.StreamReader.readByteArray.

Fill data with bytes from the stream.

public void
readBytes(final Buffer buffer)

Implements org.glassfish.grizzly.streams.StreamReader.readBytes.

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()

Implements org.glassfish.grizzly.streams.StreamReader.readChar.

Get the next character in the stream.

public void
readCharArray(final char[] data)

Implements org.glassfish.grizzly.streams.StreamReader.readCharArray.

Fill data with characters from the stream.

public final double
readDouble()

Implements org.glassfish.grizzly.streams.StreamReader.readDouble.

Get the next double in the stream.

public void
readDoubleArray(final double[] data)

Implements org.glassfish.grizzly.streams.StreamReader.readDoubleArray.

Fill data with characters from the stream.

public final float
readFloat()

Implements org.glassfish.grizzly.streams.StreamReader.readFloat.

Get the next float in the stream.

public void
readFloatArray(final float[] data)

Implements org.glassfish.grizzly.streams.StreamReader.readFloatArray.

Fill data with characters from the stream.

public int
readInt()

Implements org.glassfish.grizzly.streams.StreamReader.readInt.

Get the next int in the stream.

public void
readIntArray(final int[] data)

Implements org.glassfish.grizzly.streams.StreamReader.readIntArray.

Fill data with characters from the stream.

public long
readLong()

Implements org.glassfish.grizzly.streams.StreamReader.readLong.

Get the next long in the stream.

public void
readLongArray(final long[] data)

Implements org.glassfish.grizzly.streams.StreamReader.readLongArray.

Fill data with characters from the stream.

public short
readShort()

Implements org.glassfish.grizzly.streams.StreamReader.readShort.

Get the next short in the stream.

public void
readShortArray(final short[] data)

Implements org.glassfish.grizzly.streams.StreamReader.readShortArray.

Fill data with characters from the stream.

public void
public Buffer
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionback to summary
protected final Connection<L> connection
DEBUGback to summary
private static final boolean DEBUG
inputback to summary
protected final Input input
isClosedback to summary
protected final AtomicBoolean isClosed
LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

AbstractStreamReaderback to summary
protected AbstractStreamReader(Connection<L> connection, Input streamInput)

Create a new ByteBufferReader.

Parameters
connection:Connection<L>

the Connection to be associated with this AbstractStreamReader

streamInput:Input

the stream source

Method Detail

arraySizeCheckback to summary
private void arraySizeCheck(final int sizeInBytes)
availableback to summary
public int available()

Implements org.glassfish.grizzly.streams.StreamReader.available.

Doc from org.glassfish.grizzly.streams.StreamReader.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.

Annotations
@Override
closeback to summary
public void close()

Implements java.io.Closeable.close.

Closes the StreamReader and causes all subsequent method calls on this object to throw IllegalStateException.

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

Implements org.glassfish.grizzly.streams.StreamReader.decode.

Doc from org.glassfish.grizzly.streams.StreamReader.decode.

Read and decode data from the StreamReader

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

Implements org.glassfish.grizzly.streams.StreamReader.decode.

Doc from org.glassfish.grizzly.streams.StreamReader.decode.

Read and decode data from the StreamReader

Annotations
@Override
getBufferWindowback to summary
public Buffer getBufferWindow()

Implements org.glassfish.grizzly.streams.StreamReader.getBufferWindow.

Annotations
@Override
getConnectionback to summary
public Connection<L> getConnection()

Implements org.glassfish.grizzly.streams.Stream.getConnection.

Doc from org.glassfish.grizzly.streams.Stream.getConnection.

Get the Connection this StreamReader belongs to.

Annotations
@Override
hasAvailableback to summary
public final boolean hasAvailable()

Implements org.glassfish.grizzly.streams.StreamReader.hasAvailable.

Doc from org.glassfish.grizzly.streams.StreamReader.hasAvailable.

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

Annotations
@Override
isClosedback to summary
public boolean isClosed()

Implements org.glassfish.grizzly.streams.StreamReader.isClosed.

Doc from org.glassfish.grizzly.streams.StreamReader.isClosed.

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

Annotations
@Override
isSupportBufferWindowback to summary
public boolean isSupportBufferWindow()

Implements org.glassfish.grizzly.streams.StreamReader.isSupportBufferWindow.

Annotations
@Override
notifyAvailableback to summary
public GrizzlyFuture<Integer> notifyAvailable(int size)

Implements org.glassfish.grizzly.streams.StreamReader.notifyAvailable.

Doc from org.glassfish.grizzly.streams.StreamReader.notifyAvailable.

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

Annotations
@Override
notifyAvailableback to summary
public GrizzlyFuture<Integer> notifyAvailable(final int size, CompletionHandler<Integer> completionHandler)

Implements org.glassfish.grizzly.streams.StreamReader.notifyAvailable.

Doc from org.glassfish.grizzly.streams.StreamReader.notifyAvailable.

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.

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

Implements org.glassfish.grizzly.streams.StreamReader.notifyCondition.

Doc from org.glassfish.grizzly.streams.StreamReader.notifyCondition.

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

Annotations
@Override
notifyConditionback to summary
public synchronized GrizzlyFuture<Integer> notifyCondition(final Condition condition, final CompletionHandler<Integer> completionHandler)

Implements org.glassfish.grizzly.streams.StreamReader.notifyCondition.

Doc from org.glassfish.grizzly.streams.StreamReader.notifyCondition.

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.

Annotations
@Override
readBooleanback to summary
public boolean readBoolean() throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readBoolean.

Doc from org.glassfish.grizzly.streams.StreamReader.readBoolean.

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

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

Implements org.glassfish.grizzly.streams.StreamReader.readBooleanArray.

Doc from org.glassfish.grizzly.streams.StreamReader.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.

Annotations
@Override
readByteback to summary
public byte readByte() throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readByte.

Doc from org.glassfish.grizzly.streams.StreamReader.readByte.

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

Annotations
@Override
readByteArrayback to summary
public void readByteArray(final byte[] data) throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readByteArray.

Doc from org.glassfish.grizzly.streams.StreamReader.readByteArray.

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

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

Implements org.glassfish.grizzly.streams.StreamReader.readByteArray.

Doc from org.glassfish.grizzly.streams.StreamReader.readByteArray.

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

Annotations
@Override
readBytesback to summary
public void readBytes(final Buffer buffer) throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readBytes.

Doc from org.glassfish.grizzly.streams.StreamReader.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.

Annotations
@Override
readCharback to summary
public char readChar() throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readChar.

Doc from org.glassfish.grizzly.streams.StreamReader.readChar.

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

Annotations
@Override
readCharArrayback to summary
public void readCharArray(final char[] data) throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readCharArray.

Doc from org.glassfish.grizzly.streams.StreamReader.readCharArray.

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

Annotations
@Override
readDoubleback to summary
public final double readDouble() throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readDouble.

Doc from org.glassfish.grizzly.streams.StreamReader.readDouble.

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

Annotations
@Override
readDoubleArrayback to summary
public void readDoubleArray(final double[] data) throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readDoubleArray.

Doc from org.glassfish.grizzly.streams.StreamReader.readDoubleArray.

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

Annotations
@Override
readFloatback to summary
public final float readFloat() throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readFloat.

Doc from org.glassfish.grizzly.streams.StreamReader.readFloat.

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

Annotations
@Override
readFloatArrayback to summary
public void readFloatArray(final float[] data) throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readFloatArray.

Doc from org.glassfish.grizzly.streams.StreamReader.readFloatArray.

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

Annotations
@Override
readIntback to summary
public int readInt() throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readInt.

Doc from org.glassfish.grizzly.streams.StreamReader.readInt.

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

Annotations
@Override
readIntArrayback to summary
public void readIntArray(final int[] data) throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readIntArray.

Doc from org.glassfish.grizzly.streams.StreamReader.readIntArray.

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

Annotations
@Override
readLongback to summary
public long readLong() throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readLong.

Doc from org.glassfish.grizzly.streams.StreamReader.readLong.

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

Annotations
@Override
readLongArrayback to summary
public void readLongArray(final long[] data) throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readLongArray.

Doc from org.glassfish.grizzly.streams.StreamReader.readLongArray.

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

Annotations
@Override
readShortback to summary
public short readShort() throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readShort.

Doc from org.glassfish.grizzly.streams.StreamReader.readShort.

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

Annotations
@Override
readShortArrayback to summary
public void readShortArray(final short[] data) throws IOException

Implements org.glassfish.grizzly.streams.StreamReader.readShortArray.

Doc from org.glassfish.grizzly.streams.StreamReader.readShortArray.

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

Annotations
@Override
skipback to summary
public void skip(int length)

Implements org.glassfish.grizzly.streams.StreamReader.skip.

Annotations
@Override
takeBufferWindowback to summary
public Buffer takeBufferWindow()

Implements org.glassfish.grizzly.streams.StreamReader.takeBufferWindow.

Annotations
@Override
org.glassfish.grizzly.streams back to summary

private Class AbstractStreamReader.DecodeCompletionHandler<A, B>

extends CompletionHandlerAdapter<A, B>
implements ResultAware<A>
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.utils.ResultAware

Field Summary

Modifier and TypeField and Description
private volatile A

Constructor Summary

AccessConstructor and Description
public
DecodeCompletionHandler(FutureImpl<A> future, CompletionHandler<A> completionHandler)

Method Summary

Modifier and TypeMethod and Description
protected A
public void
Inherited from org.glassfish.grizzly.utils.CompletionHandlerAdapter:
cancelledcompletedfailedupdated

Field Detail

resultback to summary
private volatile A result

Constructor Detail

DecodeCompletionHandlerback to summary
public DecodeCompletionHandler(FutureImpl<A> future, CompletionHandler<A> completionHandler)

Method Detail

adaptback to summary
protected A adapt(B result)

Overrides org.glassfish.grizzly.utils.CompletionHandlerAdapter.adapt.

Annotations
@Override
setResultback to summary
public void setResult(A result)

Implements org.glassfish.grizzly.utils.ResultAware.setResult.

Annotations
@Override