org.restlet.engine.io
Class WritableBufferedChannel

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<WritableSelectionChannel>
              extended by org.restlet.engine.io.WritableBufferedChannel
All Implemented Interfaces:
Closeable, Channel, WritableByteChannel, BlockableChannel, BufferProcessor, SelectionChannel, WritableSelectionChannel

public class WritableBufferedChannel
extends BufferedSelectionChannel<WritableSelectionChannel>
implements WritableSelectionChannel

Writable byte channel based on a target socket channel. It is capable of first filling a buffer before draining it to the target channel.


Constructor Summary
WritableBufferedChannel(Buffer buffer, WritableSelectionChannel target, 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.
 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.
 int write(ByteBuffer sourceBuffer)
          Reads some bytes and put them into the destination buffer.
 
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

WritableBufferedChannel

public WritableBufferedChannel(Buffer buffer,
                               WritableSelectionChannel target,
                               WakeupListener wakeupListener)
Constructor.

Parameters:
buffer - The source byte buffer, typically remaining from previous read processing.
target - The target 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.

onDrain

public final 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 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

write

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

Specified by:
write in interface WritableByteChannel
Parameters:
sourceBuffer - The source buffer.
Returns:
The number of bytes written, possibly 0.
Throws:
IOException


Copyright © 2005-2013 Restlet.