org.restlet.engine.io
Class ReadableSizedChannel

java.lang.Object
  extended by org.restlet.engine.io.WrapperChannel<ReadableByteChannel>
      extended by org.restlet.engine.io.ReadableSizedChannel
All Implemented Interfaces:
Closeable, Channel, ReadableByteChannel

public class ReadableSizedChannel
extends WrapperChannel<ReadableByteChannel>
implements ReadableByteChannel

Readable byte channel enforcing a maximum size.


Constructor Summary
ReadableSizedChannel(ReadableByteChannel source, long availableSize)
          Constructor.
 
Method Summary
protected  long getAvailableSize()
          Returns the remaining size that should be read from the source channel.
protected  boolean isEndDetected()
          Indicates if the end of the channel has been detected.
 int read(ByteBuffer dst)
          Reads some bytes and put them into the destination buffer.
protected  void setAvailableSize(long availableSize)
          Sets the remaining size that should be read from the source channel.
protected  void setEndDetected(boolean endDetected)
          Indicates if the end of the channel has been detected.
 
Methods inherited from class org.restlet.engine.io.WrapperChannel
close, getWrappedChannel, isOpen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.nio.channels.Channel
close, isOpen
 

Constructor Detail

ReadableSizedChannel

public ReadableSizedChannel(ReadableByteChannel source,
                            long availableSize)
Constructor.

Parameters:
source - The source channel.
availableSize - The total available size that can be read from the source channel.
Method Detail

getAvailableSize

protected long getAvailableSize()
Returns the remaining size that should be read from the source channel.

Returns:
The remaining size that should be read from the source channel.

isEndDetected

protected boolean isEndDetected()
Indicates if the end of the channel has been detected.

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

read

public int read(ByteBuffer dst)
         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:
dst - The destination buffer.
Returns:
The number of bytes read, or -1 if the end of the channel has been reached.
Throws:
IOException

setAvailableSize

protected void setAvailableSize(long availableSize)
Sets the remaining size that should be read from the source channel.

Parameters:
availableSize - The remaining size that should be read from the source channel.

setEndDetected

protected void setEndDetected(boolean endDetected)
                       throws IOException
Indicates if the end of the channel has been detected.

Parameters:
endDetected - True if the end of the channel has been detected.
Throws:
IOException


Copyright © 2005-2013 Restlet.