Class ConcatReader
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable
- Since:
- ostermillerutils 1.04.00
- Author:
- Stephen Ostermiller https://ostermiller.org/contact.pl?regarding=Java+Utilities
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new reader that can dynamically accept new sources.ConcatReader(Reader in) Create a new reader with one source.ConcatReader(Reader[] in) Create a new reader with an arbitrary number of sources.ConcatReader(Reader in1, Reader in2) Create a new reader with two sources. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the given reader to the queue of readers from which to concatenate data.voidaddReaders(Reader[] in) Add the given reader to the queue of readers from which to concatenate data.voidclose()Close the stream and any underlying streams.voidCauses the addReader method to throw IllegalStateException and read() methods to return -1 (end of stream) when there is no more available data.voidmark(int readlimit) Mark not supported.booleanMark not supported.intread()Read a single character.intread(char[] cbuf) Read characters into an array.intread(char[] cbuf, int off, int len) Read characters into a portion of an array.booleanready()Tell whether this stream is ready to be read.voidreset()Reset not supported.longskip(long n) Skip characters.Methods inherited from class java.io.Reader
nullReader, read, transferTo
-
Constructor Details
-
ConcatReader
public ConcatReader()Create a new reader that can dynamically accept new sources.New sources should be added using the addReader() method. When all sources have been added the lastReaderAdded() should be called so that read methods can return -1 (end of stream).
Adding new sources may by interleaved with read calls.
- Since:
- ostermillerutils 1.04.01
-
ConcatReader
Create a new reader with one source.When using this constructor, more readers cannot be added later, and calling addReader() will throw an illegal state Exception.
- Parameters:
in- reader to use as a source.- Throws:
NullPointerException- if in is null- Since:
- ostermillerutils 1.04.00
-
ConcatReader
Create a new reader with two sources.When using this constructor, more readers cannot be added later, and calling addReader() will throw an illegal state Exception.
- Parameters:
in1- first reader to use as a source.in2- second reader to use as a source.- Throws:
NullPointerException- if either source is null.- Since:
- ostermillerutils 1.04.00
-
ConcatReader
Create a new reader with an arbitrary number of sources.When using this constructor, more readers cannot be added later, and calling addReader() will throw an illegal state Exception.
- Parameters:
in- readers to use as a sources.- Throws:
NullPointerException- if the input array on any element is null.- Since:
- ostermillerutils 1.04.00
-
-
Method Details
-
lastReaderAdded
public void lastReaderAdded()Causes the addReader method to throw IllegalStateException and read() methods to return -1 (end of stream) when there is no more available data.Calling this method when this class is no longer accepting more readers has no effect.
- Since:
- ostermillerutils 1.04.01
-
addReader
Add the given reader to the queue of readers from which to concatenate data.- Parameters:
in- Reader to add to the concatenation.- Throws:
IllegalStateException- if more readers can't be added because lastReaderAdded() has been called, close() has been called, or a constructor with reader parameters was used.- Since:
- ostermillerutils 1.04.01
-
addReaders
Add the given reader to the queue of readers from which to concatenate data.- Parameters:
in- Reader to add to the concatenation.- Throws:
IllegalStateException- if more readers can't be added because lastReaderAdded() has been called, close() has been called, or a constructor with reader parameters was used.NullPointerException- the array of readers, or any of the contents is null.- Since:
- ostermillerutils 1.04.01
-
read
Read a single character. This method will block until a character is available, an I/O error occurs, or the end of all underlying streams are reached.If this class in not done accepting readers and the end of the last known stream is reached, this method will block forever unless another thread adds a reader or interrupts.
- Overrides:
readin classReader- Returns:
- The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
- Throws:
IOException- - If an I/O error occurs- Since:
- ostermillerutils 1.04.00
-
read
Read characters into an array. This method will block until some input is available, an I/O error occurs, or the end of all underlying streams are reached.If this class in not done accepting readers and the end of the last known stream is reached, this method will block forever unless another thread adds a reader or interrupts.
- Overrides:
readin classReader- Parameters:
cbuf- - Destination buffer- Returns:
- The number of characters read, or -1 if the end of the stream has been reached
- Throws:
IOException- - If an I/O error occursNullPointerException- - If the buffer is null.- Since:
- ostermillerutils 1.04.00
-
read
Read characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of all underlying streams are reached.If this class in not done accepting readers and the end of the last known stream is reached, this method will block forever unless another thread adds a reader or interrupts.
- Specified by:
readin classReader- Parameters:
cbuf- Destination bufferoff- Offset at which to start storing characterslen- Maximum number of characters to read- Returns:
- The number of characters read, or -1 if the end of the stream has been reached
- Throws:
IOException- - If an I/O error occursNullPointerException- - If the buffer is null.IndexOutOfBoundsException- - if length or offset are not possible.- Since:
- ostermillerutils 1.04.00
-
skip
Skip characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached.If this class in not done accepting readers and the end of the last known stream is reached, this method will block forever unless another thread adds a reader or interrupts.
- Overrides:
skipin classReader- Parameters:
n- the number of characters to skip- Returns:
- The number of characters actually skipped
- Throws:
IllegalArgumentException- If n is negative.IOException- If an I/O error occurs- Since:
- ostermillerutils 1.04.00
-
ready
Tell whether this stream is ready to be read.- Overrides:
readyin classReader- Returns:
- True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.
- Throws:
IOException- If an I/O error occurs- Since:
- ostermillerutils 1.04.00
-
close
Close the stream and any underlying streams. Once a stream has been closed, further read(), ready(), mark(), or reset() invocations will throw an IOException. Closing a previously-closed stream, however, has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException- If an I/O error occurs- Since:
- ostermillerutils 1.04.00
-
mark
Mark not supported.- Overrides:
markin classReader- Throws:
IOException- because mark is not supported.- Since:
- ostermillerutils 1.04.00
-
reset
Reset not supported.- Overrides:
resetin classReader- Throws:
IOException- because reset is not supported.- Since:
- ostermillerutils 1.04.00
-
markSupported
public boolean markSupported()Mark not supported.- Overrides:
markSupportedin classReader- Returns:
- false
- Since:
- ostermillerutils 1.04.00
-