org.restlet.engine.io
Class ReadableBufferedChannel

java.lang.Object
  extended by org.restlet.engine.io.WrapperChannel<T>
      extended by org.restlet.engine.io.WrapperSelectionChannel<T>
          extended by org.restlet.engine.io.BufferedSelectionChannel<ReadableSelectionChannel>
              extended by org.restlet.engine.io.ReadableBufferedChannel
All Implemented Interfaces:
Closeable, Channel, ReadableByteChannel, BlockableChannel, BufferProcessor, CompletionListener, ReadableSelectionChannel, SelectionChannel
Direct Known Subclasses:
ReadableChunkedChannel, ReadableSizedSelectionChannel

public class ReadableBufferedChannel
extends BufferedSelectionChannel<ReadableSelectionChannel>
implements ReadableSelectionChannel, CompletionListener

Readable byte channel based on a source socket channel that must only be partially read. It is capable of first using the remaining buffer before reading more.


Constructor Summary
ReadableBufferedChannel(CompletionListener completionListener, Buffer buffer, ReadableSelectionChannel source, WakeupListener wakeupListener)
          Constructor.
 
Method Summary
 boolean couldDrain(Buffer buffer, Object... args)
          Indicates if the buffer could be drained again.
 boolean couldFill(Buffer buffer, Object... args)
          Indicates if the buffer could be filled again.
protected  boolean isEndReached()
          Indicates if the end of the channel has been reached.
 int onDrain(Buffer buffer, int maxDrained, Object... args)
          Drains the byte buffer.
 int onFill(Buffer buffer, Object... args)
          Fills the byte buffer by writing the current message.
 void onMessageCompleted(boolean eofDetected)
          Callback invoked upon IO completion.
 int read(ByteBuffer targetBuffer)
          Reads some bytes and put them into the destination buffer.
protected  void setEndReached(boolean endReached)
          Indicates if the end of the channel has been reached.
 
Methods inherited from class org.restlet.engine.io.BufferedSelectionChannel
canLoop, close, getBuffer, onFillEof, postProcess, preProcess
 
Methods inherited from class org.restlet.engine.io.WrapperSelectionChannel
getRegistration, isBlocking, setRegistration, toString
 
Methods inherited from class org.restlet.engine.io.WrapperChannel
getWrappedChannel, isOpen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.restlet.engine.io.SelectionChannel
getRegistration
 
Methods inherited from interface org.restlet.engine.io.BlockableChannel
isBlocking
 
Methods inherited from interface java.nio.channels.Channel
close, isOpen
 

Constructor Detail

ReadableBufferedChannel

public ReadableBufferedChannel(CompletionListener completionListener,
                               Buffer buffer,
                               ReadableSelectionChannel source,
                               WakeupListener wakeupListener)
Constructor.

Parameters:
completionListener - The listener to callback upon reading completion.
buffer - The source byte buffer, typically remaining from previous read processing.
source - The source channel.
wakeupListener - The wakeup listener that will be notified.
Method Detail

couldDrain

public boolean couldDrain(Buffer buffer,
                          Object... args)
Indicates if the buffer could be drained again.

Parameters:
buffer - The IO buffer to drain.
args - The optional arguments to pass back to the callbacks.
Returns:
True if the buffer could be drained again.

couldFill

public boolean couldFill(Buffer buffer,
                         Object... args)
Indicates if the buffer could be filled again.

Specified by:
couldFill in interface BufferProcessor
Parameters:
buffer - The IO buffer to fill.
args - The optional arguments to pass back to the callbacks.
Returns:
True if the buffer could be filled again.

isEndReached

protected boolean isEndReached()
Indicates if the end of the channel has been reached.

Returns:
True if the end of the channel has been reached.

onMessageCompleted

public void onMessageCompleted(boolean eofDetected)
                        throws IOException
Callback invoked upon IO completion. Calls CompletionListener.onMessageCompleted(boolean) if the end has been reached.

Specified by:
onMessageCompleted in interface CompletionListener
Parameters:
eofDetected - Indicates if the end of network connection was detected.
Throws:
IOException

onDrain

public int onDrain(Buffer buffer,
                   int maxDrained,
                   Object... args)
            throws IOException
Drains the byte buffer.

Specified by:
onDrain in interface BufferProcessor
Parameters:
buffer - The IO buffer to drain.
maxDrained - The maximum number of bytes drained by this call.
args - The optional arguments to pass back to the callbacks.
Returns:
The number of bytes drained.
Throws:
IOException

onFill

public final int onFill(Buffer buffer,
                        Object... args)
                 throws IOException
Fills the byte buffer by writing the current message.

Specified by:
onFill in interface BufferProcessor
Parameters:
buffer - The IO buffer to drain.
args - The optional arguments to pass back to the callbacks.
Returns:
The number of bytes filled.
Throws:
IOException

read

public int read(ByteBuffer targetBuffer)
         throws IOException
Reads some bytes and put them into the destination buffer. The bytes come from the underlying channel.

Specified by:
read in interface ReadableByteChannel
Parameters:
targetBuffer - The target buffer.
Returns:
The number of bytes read, or -1 if the end of the channel has been reached.
Throws:
IOException

setEndReached

protected void setEndReached(boolean endReached)
                      throws IOException
Indicates if the end of the channel has been reached.

Parameters:
endReached - True if the end of the channel has been reached.
Throws:
IOException


Copyright © 2005-2013 Restlet.