public class CombiningInputStream extends InputStream
The behavior of several of the standard InputStream methods
changes; see available() and mark(int) for details. Also, note
that this class will not close its consituent streams unless you call
close().
This class is not thread-safe.
| Constructor and Description |
|---|
CombiningInputStream(InputStream... constituents)
Combines one or more constituent streams.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Returns the number of bytes available without blocking, from the
current stream.
|
void |
close()
Attempts to close all constituent streams.
|
void |
mark(int readlimit)
Sets a mark on the current stream.
|
boolean |
markSupported()
Determines whether a mark can be placed at this point in the stream.
|
int |
read()
Reads a single byte of data, transparently switching between input
streams as necessary.
|
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len)
Reads up to
len bytes, transparently swtching between
input streams as necessary. |
void |
reset() |
long |
skip(long n)
Attempts to skip up to N bytes, transparently switching streams
as needed.
|
public CombiningInputStream(InputStream... constituents)
Note that we directly use the passed array. If you want to play games with changing its elements after constructing the stream, you're on your own.
public int available()
throws IOException
available in class InputStreamIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionpublic int read()
throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] b,
int off,
int len)
throws IOException
len bytes, transparently swtching between
input streams as necessary. Will block when reading from the current
stream, but does not block when switching streams; if no
data is available from the new stream, will not attempt to read it.read in class InputStreamIOExceptionpublic int read(byte[] b)
throws IOException
read in class InputStreamIOExceptionpublic boolean markSupported()
Note that this will return false if you have exhausted a stream that does not support marking, but have not yet performed a read that switches streams. This method will not block.
markSupported in class InputStreampublic void mark(int readlimit)
reset().mark in class InputStreampublic void reset()
throws IOException
reset in class InputStreamIOExceptionpublic long skip(long n)
throws IOException
This method is implemented by repeatedly calling skip()
on the constituent streams. If any such call returns 0, we try to
read from the stream to verify EOF. This can lead to an inefficient
loop, in which skip() constantly indicates zero bytes,
but we're able to read from the file. Shouldn't happen in practice.
skip in class InputStreamIOException