Package org.restlet.engine.io
Class InputStreamChannel
- java.lang.Object
-
- org.restlet.engine.io.InputStreamChannel
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.Channel,java.nio.channels.ReadableByteChannel,BlockableChannel
public class InputStreamChannel extends java.lang.Object implements java.nio.channels.ReadableByteChannel, BlockableChannel
Readable byte channel wrapping an input stream.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanblockingIndicates if the channel is blocking.private byte[]bufferOptional byte array buffer.private java.io.InputStreaminputStreamThe underlying input stream.private booleanopenIndicates if the underlying stream is still open.
-
Constructor Summary
Constructors Constructor Description InputStreamChannel(java.io.InputStream inputStream)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the underlying input stream.protected java.io.InputStreamgetInputStream()Returns the underlying input stream.booleanisBlocking()True if the underlying input stream is able to indicate available bytes upfront.booleanisOpen()Indicates if the channel and its underlying stream are open.intread(java.nio.ByteBuffer target)Reads bytes from the underlying stream to the target buffer.private intread(java.nio.ByteBuffer target, int readLength)Reads a given number of bytes into a target byte buffer.
-
-
-
Field Detail
-
inputStream
private final java.io.InputStream inputStream
The underlying input stream.
-
blocking
private final boolean blocking
Indicates if the channel is blocking.
-
buffer
private volatile byte[] buffer
Optional byte array buffer.
-
open
private volatile boolean open
Indicates if the underlying stream is still open.
-
-
Method Detail
-
close
public void close() throws java.io.IOExceptionCloses the underlying input stream.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
getInputStream
protected java.io.InputStream getInputStream()
Returns the underlying input stream.- Returns:
- The underlying input stream.
-
isBlocking
public boolean isBlocking()
True if the underlying input stream is able to indicate available bytes upfront.- Specified by:
isBlockingin interfaceBlockableChannel- Returns:
- True if the channel is blocking.
-
isOpen
public boolean isOpen()
Indicates if the channel and its underlying stream are open.- Specified by:
isOpenin interfacejava.nio.channels.Channel- Returns:
- True if the channel and its underlying stream are open.
-
read
public int read(java.nio.ByteBuffer target) throws java.io.IOExceptionReads bytes from the underlying stream to the target buffer.- Specified by:
readin interfacejava.nio.channels.ReadableByteChannel- Parameters:
target- The target byte buffer.- Returns:
- The number of bytes read.
- Throws:
java.io.IOException
-
read
private int read(java.nio.ByteBuffer target, int readLength) throws java.io.IOExceptionReads a given number of bytes into a target byte buffer.- Parameters:
target- The target byte buffer.readLength- The maximum number of bytes to read.- Returns:
- The number of bytes effectively read or -1 if end reached.
- Throws:
java.io.IOException
-
-