Class SequenceReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
The standard java.io package does not provide this capability so this
class does the same as SequenceInputStream
except for
Reader
derived classes.
It starts out with an ordered collection of input streams and reads from the first one until end of file is reached,whereupon it reads from the second one, and so on, until end of file is reached on the last of the contained input streams.
- Version:
- $Revision: 1.1 $
- Author:
- Justin Couch
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionSequenceReader
(Reader s1, Reader s2) Initializes a newly createdSequenceReader
by remembering the two arguments, which will be read as s1 then s2 order to provide the bytes to be read from thisSequenceReader
.SequenceReader
(List<Reader> readers) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this input stream and releases any system resources associated with the stream.int
read()
Reads the next char of data from this input stream.int
read
(char[] b, int off, int len) Reads up tolen
bytes of data from this input stream into an array of bytes.Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, read, ready, reset, skip, transferTo
-
Constructor Details
-
SequenceReader
Initializes a newly createdSequenceReader
with the list of be aList
that produces objects whose run-time type isReader
. The readers that are produced by the list will be read in order defined in the list to provide the bytes to be read from thisSequenceReader
. After each input stream from the list is exhausted, it is closed by calling itsclose()
method.- Parameters:
readers
- A list of input streams to process- See Also:
-
SequenceReader
Initializes a newly createdSequenceReader
by remembering the two arguments, which will be read as s1 then s2 order to provide the bytes to be read from thisSequenceReader
.- Parameters:
s1
- The first input stream to read.s2
- The second input stream to read.
-
-
Method Details
-
read
Reads the next char of data from this input stream. If no char is available because the end of the stream has been reached, the value-1
is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.This method tries to read one character from the current substream. If it reaches the end of the stream, it calls the
close
method of the current substream and begins reading from the next substream.- Overrides:
read
in classReader
- Returns:
- The next char of data, or
-1
if the end of the stream is reached. - Throws:
IOException
- if an I/O error occurs.
-
read
Reads up tolen
bytes of data from this input stream into an array of bytes. This method blocks until at least 1 byte of input is available. If the first argument isnull
, up tolen
bytes are read and discarded.The
read
method ofSequenceReader
tries to read the data from the current substream. If it fails to read any characters because the substream has reached the end of the stream, it calls theclose
method of the current substream and begins reading from the next substream.- Specified by:
read
in classReader
- Parameters:
b
- The buffer into which the data is read.off
- The start offset of the data.len
- The maximum number of bytes read.- Returns:
- The number of bytes read.
- Throws:
IOException
- if an I/O error occurs.
-
close
Closes this input stream and releases any system resources associated with the stream. A closedSequenceReader
cannot perform input operations and cannot be reopened.If this stream was created from an list, all remaining elements are requested from the list and closed before the
close
method returns. ofReader
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
- if an I/O error occurs.
-