Reads at most {@code count} bytes from this sequence of input streams and
stores them in the byte array {@code buffer} starting at {@code 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 {@code 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.
if (in == null) {
return -1;
}
// BEGIN android-changed
if (buffer == null) {
throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
}
// avoid int overflow
// Exception priorities (in case of multiple errors) differ from
// RI, but are spec-compliant.
// used (offset | count) < 0 instead of (offset < 0) || (count < 0)
// to safe one operation
if ((offset | count) < 0 || offset > buffer.length - count) {
throw new IndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
}
// END android-changed
while (in != null) {
int result = in.read(buffer, offset, count);
if (result >= 0) {
return result;
}
nextStream();
}
return -1;