Class MarkableSequenceInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
SequenceInputStream
that supports
mark
and reset
, to the extent its constituent input streams
do.
This class implements mark
and reset
by calling the
corresponding methods on the underlying streams; it does not add buffering
or have any means of providing mark
and reset
support if
the underlying streams do not.
As with SequenceInputStream
, each underlying stream, 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 streams.
Unlike SequenceInputStream
, this class can keep underlying streams
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 streams to be reclaimed as soon as possible.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
AListIterator
that will fetch an element from aBlockingQueue
wheneverhasNext
would (otherwise) returnfalse
, adding it to the end of the list where the nextnext()
will retrieve it. -
Field Summary
Modifier and TypeFieldDescriptionstatic final InputStream
A sentinel value, needed because aBlockingQueue
does not allow a null value to be enqueued. -
Constructor Summary
ConstructorDescriptionMarkableSequenceInputStream
(InputStream... streams) Create aMarkableSequenceInputStream
from one or more existing input streams.AMarkableSequenceInputStream
that will receive streams to read, in order, over aBlockingQueue
. -
Method Summary
Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
NO_MORE
A sentinel value, needed because aBlockingQueue
does not allow a null value to be enqueued.
-
-
Constructor Details
-
MarkableSequenceInputStream
Create aMarkableSequenceInputStream
from one or more existing input streams.- Parameters:
streams
- Sequence ofInputStream
s that will be read from in order.- Throws:
NullPointerException
- ifstreams
isnull
, or containsnull
for any stream.
-
MarkableSequenceInputStream
AMarkableSequenceInputStream
that will receive streams to read, in order, over aBlockingQueue
.The thread supplying the queue should enqueue the value
NO_MORE
following the last actualInputStream
to read. (The sentinel is needed because aBlockingQueue
does not allow null values.)- Parameters:
queue
- Source of input streams to read.- Throws:
NullPointerException
- ifqueue
isnull
.
-
-
Method Details
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
mark
public void mark(int readlimit) Marks the current position in this input stream. In this implementation, it is possible to 'cancel' a mark, by passing this method areadlimit
of zero, returning the stream immediately to the state of having no mark.- Overrides:
mark
in classInputStream
-
reset
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
markSupported
public boolean markSupported()Tests if this input stream supports the mark and reset methods.By the API spec, this method's return is "an invariant property of a particular input stream instance." 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 input streams remaining to be read (or, if a mark has been set, which is possible before checking this method, then by the underlying input streams including and following the one that was current when the mark was set). The result will be
true
unless any of those underlying streams reports it asfalse
.- Overrides:
markSupported
in classInputStream
-