Class SeekableStream

java.lang.Object
java.io.InputStream
org.eclipse.mat.hprof.SeekableStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class SeekableStream extends InputStream implements 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.
  • 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 with SeekableStream.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 use
      estlen - 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 with SeekableStream.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 use
      estlen - estimate of uncompressed length
      Throws:
      IOException
    • SeekableStream

      public SeekableStream(Supplier<InputStream> genstream, int cachesize) 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.
      cachesize - number of seekable streams to use
      Throws:
      IOException
  • Method Details