org.restlet.engine.io
Class NbChannelInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.restlet.engine.io.NbChannelInputStream
All Implemented Interfaces:
Closeable, BufferProcessor

public class NbChannelInputStream
extends InputStream
implements BufferProcessor

Input stream connected to a non-blocking readable channel.

Author:
Jerome Louvel

Constructor Summary
NbChannelInputStream(ReadableByteChannel channel)
          Constructor.
 
Method Summary
 boolean canLoop(Buffer buffer, Object... args)
          Indicates if the processing loop can continue.
 boolean couldFill(Buffer buffer, Object... args)
          Indicates if the buffer could be filled again.
protected  Buffer getBuffer()
          Returns the internal byte buffer.
 int onDrain(Buffer buffer, int maxDrained, Object... args)
          Drains the byte buffer by returning available bytes as InputStream bytes.
 int onFill(Buffer buffer, Object... args)
          Fills the byte buffer by reading the source channel.
 void onFillEof()
          Called back when a fill operation returns with an EOF status.
 void postProcess(int drained)
          Does nothing by default.
 int preProcess(int maxDrained, Object... args)
          Does nothing by default.
 int read()
           
 int read(byte[] targetArray, int offset, int length)
           
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NbChannelInputStream

public NbChannelInputStream(ReadableByteChannel channel)
Constructor.

Parameters:
channel - The channel to read from.
Method Detail

canLoop

public boolean canLoop(Buffer buffer,
                       Object... args)
Indicates if the processing loop can continue.

Specified by:
canLoop in interface BufferProcessor
Parameters:
buffer - The IO buffer to drain.
args - The optional arguments to pass back to the callbacks.
Returns:
True if the processing loop can continue.

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.

getBuffer

protected Buffer getBuffer()
Returns the internal byte buffer.

Returns:
The internal byte buffer.

onDrain

public int onDrain(Buffer buffer,
                   int maxDrained,
                   Object... args)
            throws IOException
Drains the byte buffer by returning available bytes as InputStream bytes.

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 reading the source channel.

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

onFillEof

public void onFillEof()
Called back when a fill operation returns with an EOF status.

Specified by:
onFillEof in interface BufferProcessor

postProcess

public void postProcess(int drained)
                 throws IOException
Does nothing by default.

Specified by:
postProcess in interface BufferProcessor
Parameters:
drained - The number of bytes drained or -1 if the filling source has ended.
Throws:
IOException

preProcess

public int preProcess(int maxDrained,
                      Object... args)
               throws IOException
Does nothing by default.

Specified by:
preProcess in interface BufferProcessor
Parameters:
maxDrained - The maximum number of bytes drained by this call or 0 for unlimited length.
args - The optional arguments to pass back to the callbacks.
Returns:
The number of bytes drained or -1 if the filling source has ended.
Throws:
IOException

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] targetArray,
                int offset,
                int length)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException


Copyright © 2005-2013 Restlet.