public class SequenceInputStream extends InputStream
InputStream
s. Reads are taken from the first stream until it ends, then the
next stream is used, until the last stream returns end of file.Constructor and Description |
---|
SequenceInputStream(ArrayList<InputStream> inputStreams)
Constructs a new SequenceInputStream using the elements returned from
inputStreams as the stream
sequence. |
SequenceInputStream(InputStream s1,
InputStream s2)
Constructs a new
SequenceInputStream using the two streams s1 and s2 as the sequence of
streams to read from. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes all streams in this sequence of input stream.
|
int |
read()
Reads a single byte from this sequence of input streams and returns it as an integer in the range from 0 to 255.
|
int |
read(byte[] buffer,
int offset,
int count)
Reads at most
count bytes from this sequence of input streams and stores them in the byte array buffer starting at offset . |
copyTo, copyToByteArray, finalize, read, readFully, readFully
public SequenceInputStream(InputStream s1, InputStream s2)
SequenceInputStream
using the two streams s1
and s2
as the sequence of
streams to read from.s1
- the first stream to get bytes from.s2
- the second stream to get bytes from.public SequenceInputStream(ArrayList<InputStream> inputStreams)
inputStreams
as the stream
sequence.inputStreams
- ArrayList
of InputStreams
to get bytes frompublic void close()
close
in interface java.lang.AutoCloseable
close
in class InputStream
public int read()
read
in class InputStream
public int read(byte[] buffer, int offset, int count)
count
bytes from this sequence of input streams and stores them in the byte array buffer
starting at offset
. Blocks only until at least 1 byte has been read, the end of the stream has
been reached, or an exception is thrown. This SequenceInputStream shows the same behavior as other
InputStreams. To do this it will read only as many bytes as a call to read on the current substream returns. If
that call does not return as many bytes as requested by count
, it will not retry to read more on its own
because subsequent reads might block. This would violate the rule that it will only block until at least one byte
has been read.
If a substream has already reached the end when this call is made, it will close that substream and start with the next one. If there are no more substreams it will return -1.
read
in class InputStream
buffer
- the array in which to store the bytes read.offset
- the initial position in buffer
to store the bytes read from this stream.count
- the maximum number of bytes to store in buffer
.java.lang.IndexOutOfBoundsException
- if offset < 0
or count < 0
, or if offset + count
is
greater than the size of buffer
.