public class SeekableStream extends InputStream implements Closeable, AutoCloseable
SeekableStream.RandomAccessInputStream stream.
This is used if the supplier does
not provided a fresh underlying stream each time. A seek is used to move the underlying
stream to the correct position when switching between unseekable streams. In this
case the supplier of non-seekable streams should wrap the innermost stream from
the underlying seekable stream with a SeekableStream.UnclosableInputStream so that the
non-seekable streams can be closed (to release resources) without closing the
underlying seekable.| Modifier and Type | Class and Description |
|---|---|
static class |
SeekableStream.RandomAccessInputStream
Used to wrap and indicate a underlying stream which has a position and has seek().
|
static class |
SeekableStream.UnclosableInputStream
Wraps an
InputStream so that
close does not propagate to the underlying stream. |
| Constructor and Description |
|---|
SeekableStream(Supplier<InputStream> genstream,
int cachesize)
Creates a seekable stream out of a non-seekable stream.
|
SeekableStream(Supplier<InputStream> genstream,
SeekableByteChannel underlying,
int cachesize,
long estlen)
Creates a seekable stream out of a non-seekable stream.
|
SeekableStream(Supplier<InputStream> genstream,
SeekableStream.RandomAccessInputStream underlying,
int cachesize,
long estlen)
Creates a seekable stream out of a non-seekable stream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes and cleans up the
SeekableStream, including
the non-seekable streams. |
long |
position() |
int |
read() |
int |
read(byte[] buffer,
int offset,
int length) |
void |
seek(long pos)
Move to a position in the seekable stream.
|
String |
toString() |
available, mark, markSupported, read, reset, skippublic SeekableStream(Supplier<InputStream> genstream, SeekableStream.RandomAccessInputStream underlying, int cachesize, long estlen) throws IOException
genstream - Supplier of a new non-seekable stream for the same resource,
underlying.
The streams are closed when no longer needed.
Wrap the innermost stream with UnclosableStream
to avoid closing the underlying stream when one of the
non-seekable streams is closed by this class.underlying - The underlying seekable stream.
Avoids having to open a file multiple times if a seek can be used instead.cachesize - number of seekable streams to useestlen - estimate of lengthIOExceptionpublic SeekableStream(Supplier<InputStream> genstream, SeekableByteChannel underlying, int cachesize, long estlen) throws IOException
genstream - Supplier of a new non-seekable stream for the same resource.
The streams are closed when no longer needed.
Wrap the innermost stream with UnclosableStream
to avoid closing the underlying stream when one of the
non-seekable streams is closed by this class.underlying - The underlying seekable stream.
Avoids having to open a file multiple times if a seek can be used instead.cachesize - number of seekable streams to useestlen - estimate of uncompressed lengthIOExceptionpublic SeekableStream(Supplier<InputStream> genstream, int cachesize) throws IOException
genstream - Supplier of a new non-seekable stream for the same resource.
The streams are closed when no longer needed.cachesize - number of seekable streams to useIOExceptionpublic void seek(long pos)
throws IOException
pos - IOExceptionpublic long position()
public int read()
throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] buffer,
int offset,
int length)
throws IOException
read in class InputStreamIOExceptionpublic void close()
throws IOException
SeekableStream, including
the non-seekable streams.
Does not close the underlying stream or channel, this should be
done explicitly.close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOException