public class ChannelInputStream extends InputStream
InputStream operations backed by a
java.nio.Channel. This allows programs to use the flexibility
of the channel API (such as random seeks on FileChannel)
while still using the java.io class hierarchy (in particular,
InputStreamReader).
This class does not attempt to replicate channel functionality. The program
shouldmaintain an independent reference to the channel to support operations
such as position(). See method docs for cases where stream
functionality overlaps channel functionality.
Single instances of this class are not safe for concurrent use by multiple threads. Multiple instances that share a channel are thread-safe if the channel is thread-safe.
| Constructor and Description |
|---|
ChannelInputStream(ReadableByteChannel channel) |
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Deprecated.
|
void |
close()
Deprecated.
|
boolean |
markSupported()
Always returns
false. |
int |
read()
Reads a single byte from the channel.
|
int |
read(byte[] b)
Attempts to fill the passed array from the channel, returning the number of
bytes read (which may be 0), or -1 to indicate end-of-file.
|
int |
read(byte[] b,
int off,
int len)
Attempts to fill a section of the passed array from the channel, returning
the number of bytes read (which may be 0), or -1 to indicate end-of-file.
|
long |
skip(long n)
Deprecated.
|
mark, resetpublic ChannelInputStream(ReadableByteChannel channel)
public boolean markSupported()
false. If the underlying channel supports
marks and positioning, you should perform those operations there.markSupported in class InputStreampublic int read()
throws IOException
Unlike the InputStream implementations in java.io,
end-of-file is "soft": some channels will increase their size. As a result,
you can call this method after receiving end-of-file notification and get
valid data.
read in class InputStreamIOExceptionpublic int read(byte[] b)
throws IOException
Unlike the InputStream implementations in java.io,
end-of-file is "soft": some channels will increase their size. As a result,
you can call this method after receiving end-of-file notification and get
valid data.
read in class InputStreamIOExceptionpublic int read(byte[] b,
int off,
int len)
throws IOException
Unlike the InputStream implementations in java.io,
end-of-file is "soft": some channels will increase their size. As a result,
you can call this method after receiving end-of-file notification and get
valid data.
read in class InputStreamIOException@Deprecated public void close() throws IOException
It is generally a better idea to close the channel explicitly; there is no need to close the stream (which is a decorator).
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOException@Deprecated public int available() throws IOException
available in class InputStreamIOException@Deprecated public long skip(long n) throws IOException
This method is deprecated; you should adjust the channel's position rather than skipping bytes (the former is guaranteed, unlike the latter).
skip in class InputStreamIOException