@MinDoc(copyright="Copyright 2001 - 2002, 2009 A. Weinert", author="Albrecht Weinert", version="V.44", lastModified="6.05.2021", usage="use for unbloody replacement of a Reader chain\'s element", purpose="a no-op Reader filter / decorator that can switch its input") public final class SwitchedReader extends Reader
InputStreamReader
can't change the encoding it
was constructed with, that part of the chain has to be replaced in the
process. With SwitchedReader
in front of the
InputStreamReader
no one else is troubled.TeeWriter
that
provides switching in an output chain.Modifier and Type | Field and Description |
---|---|
protected Reader |
in
The Reader to get input from.
|
Constructor and Description |
---|
SwitchedReader(Reader in)
Make a new SwitchedReader.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the associated input reader.
|
void |
mark(int readAheadLimit)
Mark the present position in the associated input reader.
|
boolean |
markSupported()
Does the associated input reader support the mark() operation.
|
int |
read()
Read a single character.
|
int |
read(char[] cbuf,
int off,
int len)
Read some characters into an array.
|
boolean |
ready()
Try to tell if the associated input reader is ready.
|
void |
reset()
Reset the associated input reader to the last marked position.
|
long |
skip(long n)
Skip some characters.
|
void |
switchInput(Reader in,
boolean closeOld)
Switch the Reader to get input from.
|
protected volatile Reader in
public SwitchedReader(Reader in)
in
- a Reader object providing the underlying input (not null).NullPointerException
- if in
is null
public final void switchInput(Reader in, boolean closeOld) throws IOException
in
- the new Reader to get input from (null or actual has no effect)closeOld
- if true and if switched to in do close the old inputIOException
- file or stream problemspublic int read() throws IOException
read
in class Reader
IOException
public int read(char[] cbuf, int off, int len) throws IOException
read
in class Reader
IOException
public long skip(long n) throws IOException
skip
in class Reader
IOException
public boolean ready() throws IOException
ready
in class Reader
IOException
public boolean markSupported()
markSupported
in class Reader
public void mark(int readAheadLimit) throws IOException
mark
in class Reader
IOException
public void reset() throws IOException
reset
in class Reader
IOException
public void close() throws IOException
switching
to another non
null input reader this SwitchedReader
would be operable again.
This might be an unwanted surprise.close
in interface Closeable
close
in interface AutoCloseable
close
in class Reader
IOException