- java.lang.Object
-
- java.io.InputStream
-
- org.xnio.streams.ChannelInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ChannelInputStream extends java.io.InputStreamAn 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 Modifier and Type Field Description protected StreamSourceChannelchannel
-
Constructor Summary
Constructors Constructor Description ChannelInputStream(StreamSourceChannel channel)Construct a new instance.ChannelInputStream(StreamSourceChannel channel, long timeout, java.util.concurrent.TimeUnit timeoutUnit)Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()longgetReadTimeout(java.util.concurrent.TimeUnit unit)Get the read timeout.intread()intread(byte[] b)intread(byte[] b, int off, int len)voidsetReadTimeout(long timeout, java.util.concurrent.TimeUnit unit)Set the read timeout.longskip(long n)Skip bytes in the stream.
-
-
-
Field Detail
-
channel
protected final StreamSourceChannel channel
-
-
Constructor Detail
-
ChannelInputStream
public ChannelInputStream(StreamSourceChannel channel)
Construct a new instance. The stream will have no read timeout.- Parameters:
channel- the channel to wrap
-
ChannelInputStream
public ChannelInputStream(StreamSourceChannel channel, long timeout, java.util.concurrent.TimeUnit timeoutUnit)
Construct a new instance.- Parameters:
channel- the channel to wraptimeout- the read timeout, or O for nonetimeoutUnit- the time unit for read timeouts
-
-
Method Detail
-
getReadTimeout
public long getReadTimeout(java.util.concurrent.TimeUnit unit)
Get the read timeout.- Parameters:
unit- the time unit- Returns:
- the timeout in the given unit
-
setReadTimeout
public void setReadTimeout(long timeout, java.util.concurrent.TimeUnit unit)Set the read timeout. Does not affect read operations in progress.- Parameters:
timeout- the read timeout, or 0 for noneunit- the time unit
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException- Overrides:
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
-
skip
public long skip(long n) throws java.io.IOExceptionSkip bytes in the stream.- Overrides:
skipin classjava.io.InputStream- Parameters:
n- the number of bytes to skip- Returns:
- the number of bytes skipped (0 if the end of stream has been reached)
- Throws:
java.io.IOException- if an I/O error occurs
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException
-
-