public class ConcatReader
extends java.io.Reader
Constructor and Description |
---|
ConcatReader()
Create a new reader that can dynamically accept new sources.
|
ConcatReader(java.io.Reader in)
Create a new reader with one source.
|
ConcatReader(java.io.Reader[] in)
Create a new reader with an arbitrary number of sources.
|
ConcatReader(java.io.Reader in1,
java.io.Reader in2)
Create a new reader with two sources.
|
Modifier and Type | Method and Description |
---|---|
void |
addReader(java.io.Reader in)
Add the given reader to the queue of readers from which to
concatenate data.
|
void |
addReaders(java.io.Reader[] in)
Add the given reader to the queue of readers from which to
concatenate data.
|
void |
close()
Close the stream and any underlying streams.
|
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.
|
void |
mark(int readlimit)
Mark not supported.
|
boolean |
markSupported()
Mark not supported.
|
int |
read()
Read a single character.
|
int |
read(char[] cbuf)
Read characters into an array.
|
int |
read(char[] cbuf,
int off,
int len)
Read characters into a portion of an array.
|
boolean |
ready()
Tell whether this stream is ready to be read.
|
void |
reset()
Reset not supported.
|
long |
skip(long n)
Skip characters.
|
public ConcatReader()
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.
public ConcatReader(java.io.Reader in)
When using this constructor, more readers cannot be added later, and calling addReader() will throw an illegal state Exception.
in
- reader to use as a source.java.lang.NullPointerException
- if in is nullpublic ConcatReader(java.io.Reader in1, java.io.Reader in2)
When using this constructor, more readers cannot be added later, and calling addReader() will throw an illegal state Exception.
in1
- first reader to use as a source.in2
- second reader to use as a source.java.lang.NullPointerException
- if either source is null.public ConcatReader(java.io.Reader[] in)
When using this constructor, more readers cannot be added later, and calling addReader() will throw an illegal state Exception.
in
- readers to use as a sources.java.lang.NullPointerException
- if the input array on any element is null.public void lastReaderAdded()
Calling this method when this class is no longer accepting more readers has no effect.
public void addReader(java.io.Reader in)
in
- Reader to add to the concatenation.java.lang.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.public void addReaders(java.io.Reader[] in)
in
- Reader to add to the concatenation.java.lang.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.java.lang.NullPointerException
- the array of readers, or any of the contents is null.public int read() throws java.io.IOException
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.
read
in class java.io.Reader
java.io.IOException
- - If an I/O error occurspublic int read(char[] cbuf) throws java.io.IOException
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.
read
in class java.io.Reader
cbuf
- - Destination bufferjava.io.IOException
- - If an I/O error occursjava.lang.NullPointerException
- - If the buffer is null.public int read(char[] cbuf, int off, int len) throws java.io.IOException
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.
read
in class java.io.Reader
cbuf
- Destination bufferoff
- Offset at which to start storing characterslen
- Maximum number of characters to readjava.io.IOException
- - If an I/O error occursjava.lang.NullPointerException
- - If the buffer is null.java.lang.IndexOutOfBoundsException
- - if length or offset are not possible.public long skip(long n) throws java.io.IOException
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.
skip
in class java.io.Reader
n
- the number of characters to skipjava.lang.IllegalArgumentException
- If n is negative.java.io.IOException
- If an I/O error occurspublic boolean ready() throws java.io.IOException
ready
in class java.io.Reader
java.io.IOException
- If an I/O error occurspublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.Reader
java.io.IOException
- If an I/O error occurspublic void mark(int readlimit) throws java.io.IOException
mark
in class java.io.Reader
java.io.IOException
- because mark is not supported.public void reset() throws java.io.IOException
reset
in class java.io.Reader
java.io.IOException
- because reset is not supported.public boolean markSupported()
markSupported
in class java.io.Reader
Copyright (c) 2001-2020 by Stephen Ostermiller