Package org.xnio.streams
Class ChannelInputStream
java.lang.Object
java.io.InputStream
org.xnio.streams.ChannelInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
An input stream which reads from a stream source channel. All read operations are directly
performed upon the channel, so for optimal performance, a buffering input stream should be
used to wrap this class.
- Since:
- 1.2
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionChannelInputStream(StreamSourceChannel channel) Construct a new instance.ChannelInputStream(StreamSourceChannel channel, long timeout, TimeUnit timeoutUnit) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()longgetReadTimeout(TimeUnit unit) Get the read timeout.intread()intread(byte[] b) intread(byte[] b, int off, int len) voidsetReadTimeout(long timeout, TimeUnit unit) Set the read timeout.longskip(long n) Skip bytes in the stream.Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skipNBytes, transferTo
-
Field Details
-
channel
-
-
Constructor Details
-
ChannelInputStream
Construct a new instance. The stream will have no read timeout.- Parameters:
channel- the channel to wrap
-
ChannelInputStream
Construct a new instance.- Parameters:
channel- the channel to wraptimeout- the read timeout, or O for nonetimeoutUnit- the time unit for read timeouts
-
-
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
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
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
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-