Package org.restlet.engine.io
Class NbChannelInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.restlet.engine.io.NbChannelInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class NbChannelInputStream extends java.io.InputStreamInput stream connected to a non-blocking readable channel.
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.ByteBufferbyteBufferThe internal byte buffer.private java.nio.channels.ReadableByteChannelchannelThe channel to read from.private booleanendReachedIndicates if further reads can be attempted.private java.nio.channels.SelectableChannelselectableChannelThe optional selectable channel to read from.private SelectionChannelselectionChannelThe optional selection channel to read from.private SelectionRegistrationselectionRegistrationThe registered selection registration.
-
Constructor Summary
Constructors Constructor Description NbChannelInputStream(java.nio.channels.ReadableByteChannel channel)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intread()intread(byte[] b, int off, int len)private intreadChannel()Reads the available bytes from the channel into the byte buffer.private voidrefill()Refill the byte buffer by attempting to read the channel.
-
-
-
Field Detail
-
byteBuffer
private final java.nio.ByteBuffer byteBuffer
The internal byte buffer.
-
channel
private final java.nio.channels.ReadableByteChannel channel
The channel to read from.
-
endReached
private volatile boolean endReached
Indicates if further reads can be attempted.
-
selectionRegistration
private volatile SelectionRegistration selectionRegistration
The registered selection registration.
-
selectableChannel
private final java.nio.channels.SelectableChannel selectableChannel
The optional selectable channel to read from.
-
selectionChannel
private final SelectionChannel selectionChannel
The optional selection channel to read from.
-
-
Method Detail
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
readChannel
private int readChannel() throws java.io.IOExceptionReads the available bytes from the channel into the byte buffer.- Returns:
- The number of bytes read or -1 if the end of channel has been reached.
- Throws:
java.io.IOException
-
refill
private void refill() throws java.io.IOExceptionRefill the byte buffer by attempting to read the channel.- Throws:
java.io.IOException
-
-