Package org.xnio.streams
Class BufferedChannelInputStream
java.lang.Object
java.io.InputStream
org.xnio.streams.BufferedChannelInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
An input stream which reads from a stream source channel with a buffer. In addition, the
available() method can be used to determine whether the next read will or will not block.- Since:
- 2.1
-
Constructor Summary
ConstructorsConstructorDescriptionBufferedChannelInputStream(StreamSourceChannel channel, int bufferSize) Construct a new instance.BufferedChannelInputStream(StreamSourceChannel channel, int bufferSize, long timeout, TimeUnit unit) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionintReturn the number of bytes available to read, or 0 if a subsequentread()operation would block.voidclose()Close the stream.longgetReadTimeout(TimeUnit unit) Get the read timeout.intread()Read a byte, blocking if necessary.intread(byte[] b, int off, int len) Read bytes into an array.voidsetReadTimeout(long timeout, TimeUnit unit) Set the read timeout.longskip(long n) Skip bytes in the stream.Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skipNBytes, transferTo
-
Constructor Details
-
BufferedChannelInputStream
Construct a new instance.- Parameters:
channel- the channel to wrapbufferSize- the size of the internal buffer
-
BufferedChannelInputStream
public BufferedChannelInputStream(StreamSourceChannel channel, int bufferSize, long timeout, TimeUnit unit) Construct a new instance.- Parameters:
channel- the channel to wrapbufferSize- the size of the internal buffertimeout- the initial read timeout, or O for noneunit- the time unit for the read timeout
-
-
Method Details
-
getReadTimeout
Get the read timeout.- Parameters:
unit- the time unit- Returns:
- the timeout in the given unit
-
setReadTimeout
Set the read timeout. Does not affect read operations in progress.- Parameters:
timeout- the read timeout, or 0 for noneunit- the time unit
-
read
Read a byte, blocking if necessary.- Specified by:
readin classInputStream- Returns:
- the byte read, or -1 if the end of the stream has been reached
- Throws:
IOException- if an I/O error occurs
-
read
Read bytes into an array.- Overrides:
readin classInputStream- Parameters:
b- the destination arrayoff- the offset into the array at which bytes should be filledlen- the number of bytes to fill- Returns:
- the number of bytes read, or -1 if the end of the stream has been reached
- Throws:
IOException- if an I/O error occurs
-
skip
Skip bytes in the stream.- Overrides:
skipin classInputStream- Parameters:
n- the number of bytes to skip- Returns:
- the number of bytes skipped (0 if the end of stream has been reached)
- Throws:
IOException- if an I/O error occurs
-
available
Return the number of bytes available to read, or 0 if a subsequentread()operation would block. If a 0 is returned, the channel'sresumeReads()method may be used to register for read-readiness.- Overrides:
availablein classInputStream- Returns:
- the number of ready bytes, or 0 for none
- Throws:
IOException- if an I/O error occurs
-
close
Close the stream. Shuts down the channel's read side.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException- if an I/O error occurs
-