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 createdSequenceReaderby 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 TypeMethodDescriptionvoidclose()Closes this input stream and releases any system resources associated with the stream.intread()Reads the next char of data from this input stream.intread(char[] b, int off, int len) Reads up tolenbytes 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 createdSequenceReaderwith the list of be aListthat 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 createdSequenceReaderby 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-1is 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
closemethod of the current substream and begins reading from the next substream.- Overrides:
readin classReader- Returns:
- The next char of data, or
-1if the end of the stream is reached. - Throws:
IOException- if an I/O error occurs.
-
read
Reads up tolenbytes 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 tolenbytes are read and discarded.The
readmethod ofSequenceReadertries 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 theclosemethod of the current substream and begins reading from the next substream.- Specified by:
readin 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 closedSequenceReadercannot 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
closemethod returns. ofReader.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException- if an I/O error occurs.
-