Package org.eclipse.mat.hprof
Class SeekableStream
java.lang.Object
java.io.InputStream
org.eclipse.mat.hprof.SeekableStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Used to wrap an non-seekable stream to make it seekable.
Constructed with a supplier of the non-seekable stream (which could be a decompression
stream or decryption stream). Multiple instances of this stream are then constructed
and each starts at the beginning.
Optionally supplied underlying seekable
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.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Used to wrap and indicate a underlying stream which has a position and has seek().static class
Wraps anInputStream
so that close does not propagate to the underlying stream. -
Constructor Summary
ConstructorDescriptionSeekableStream
(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. -
Method Summary
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skipNBytes, transferTo
-
Constructor Details
-
SeekableStream
public SeekableStream(Supplier<InputStream> genstream, SeekableStream.RandomAccessInputStream underlying, int cachesize, long estlen) throws IOException Creates a seekable stream out of a non-seekable stream.- Parameters:
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 withSeekableStream.UnclosableInputStream
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 length- Throws:
IOException
-
SeekableStream
public SeekableStream(Supplier<InputStream> genstream, SeekableByteChannel underlying, int cachesize, long estlen) throws IOException Creates a seekable stream out of a non-seekable stream.- Parameters:
genstream
- Supplier of a new non-seekable stream for the same resource. The streams are closed when no longer needed. Wrap the innermost stream withSeekableStream.UnclosableInputStream
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 length- Throws:
IOException
-
SeekableStream
Creates a seekable stream out of a non-seekable stream.- Parameters:
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 use- Throws:
IOException
-
-
Method Details
-
seek
Move to a position in the seekable stream. Locates the stream closest before the seek point. Skip to the seek point. If no underlying stream is before the seek point, create another and discard an existing stream if required.- Parameters:
pos
-- Throws:
IOException
-
position
public long position() -
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
close
Closes and cleans up theSeekableStream
, including the non-seekable streams. Does not close the underlying stream or channel, this should be done explicitly.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
toString
-