Class MarkableSequenceReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
MarkableSequenceInputStream
but for characters.
This class implements mark
and reset
by calling the
corresponding methods on the underlying readers; it does not add buffering
or have any means of providing mark
and reset
support if
the underlying readers do not.
As with SequenceInputStream
, each underlying reader, when completely
read and no longer needed, is closed to free resources. This instance itself
will remain in "open at EOF" condition until explicitly closed, but does not
prevent reclamation of the underlying readers.
Unlike SequenceInputStream
, this class can keep underlying readers
open, after fully reading them, if a mark
has been set, so that
reset
will be possible. When a mark is no longer needed, it can be
canceled (by calling mark
with a readlimit
of 0) to again
allow the underlying readers to be reclaimed as soon as possible.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMarkableSequenceReader
(Reader... streams) Create aMarkableSequenceReader
from one or more existing readers. -
Method Summary
Methods inherited from class java.io.Reader
nullReader, read, read, ready, transferTo
-
Constructor Details
-
MarkableSequenceReader
Create aMarkableSequenceReader
from one or more existing readers.- Parameters:
streams
- Sequence ofReader
s that will be read from in order.- Throws:
NullPointerException
- ifstreams
isnull
, or containsnull
for any stream.
-
-
Method Details
-
read
- Overrides:
read
in classReader
- Throws:
IOException
-
read
- Specified by:
read
in classReader
- Throws:
IOException
-
skip
- Overrides:
skip
in classReader
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
-
mark
Marks the current position in this reader. In this implementation, it is possible to 'cancel' a mark, by passing this method areadlimit
of zero, returning the reader immediately to the state of having no mark.- Overrides:
mark
in classReader
- Throws:
IOException
-
reset
- Overrides:
reset
in classReader
- Throws:
IOException
-
markSupported
public boolean markSupported()Tests if this reader supports the mark and reset methods.For any instance of this class, the result is determined by the first call to this method, and does not change thereafter. At the first call, the result is determined only by the underlying readers remaining to be read (or, if a mark has been set, which is possible before checking this method, then by the underlying readers including and following the one that was current when the mark was set). The result will be
true
unless any of those underlying readers reports it asfalse
.- Overrides:
markSupported
in classReader
-