Class InflaterInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
io.nayuki.deflate.InflaterInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public final class InflaterInputStream extends FilterInputStream
Decompresses a DEFLATE data stream (raw format without zlib or gzip headers or footers) into a byte stream.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Extra constructor added for org.eclipse.mat.hprof Only safe to use copy or original once the underlying stream has been positioned to the appropriate location.
    InflaterInputStream(InputStream in, boolean detachable)
    Constructs an inflater input stream over the specified underlying input stream, and with the specified option for detachability.
    InflaterInputStream(InputStream in, boolean detachable, int inBufLen)
    Constructs an inflater input stream over the specified underlying input stream, with the specified options for detachability and input buffer size.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Resume decompression.
    int
    The number of bytes which can be read without blocking.
    void
    Closes this input stream and the underlying stream.
    void
    Detaches the underlying input stream from this decompressor.
    void
    mark(int limit)
    Notes the current position of the output, so that later the caller can go back to this spot by calling reset.
    boolean
    Does this stream support mark(int) and reset() ? It does.
    int
    Reads the next byte of decompressed data from this stream.
    int
    read(byte[] b, int off, int len)
    Reads some bytes from the decompressed data of this stream into the specified array's subrange.
    void
    Goes back in the output to the point where mark(int) was called.
    long
    skip(long n)
     
     

    Methods inherited from class java.io.FilterInputStream

    read

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • InflaterInputStream

      public InflaterInputStream(InputStream in, boolean detachable)
      Constructs an inflater input stream over the specified underlying input stream, and with the specified option for detachability. The underlying stream must contain DEFLATE-compressed data with no headers or footers (e.g. must be unwrapped from the zlib or gzip container formats). Detachability allows detach() to be called, and requires the specified input stream to support marking.
      Parameters:
      in - the underlying input stream of raw DEFLATE-compressed data
      detachable - whether detach() can be called later
      Throws:
      NullPointerException - if the input stream is null
      IllegalArgumentException - if detach == true but in.markSupported() == false
    • InflaterInputStream

      public InflaterInputStream(InputStream in, boolean detachable, int inBufLen)
      Constructs an inflater input stream over the specified underlying input stream, with the specified options for detachability and input buffer size. The underlying stream must contain DEFLATE-compressed data with no headers or footers (e.g. must be unwrapped from the zlib or gzip container formats). Detachability allows detach() to be called, and requires the specified input stream to support marking.
      Parameters:
      in - the underlying input stream of raw DEFLATE-compressed data
      detachable - whether detach() can be called later
      inBufLen - the size of the internal read buffer, which must be positive
      Throws:
      NullPointerException - if the input stream is null
      IllegalArgumentException - if inBufLen < 1
      IllegalArgumentException - if detach == true but in.markSupported() == false
    • InflaterInputStream

      public InflaterInputStream(InflaterInputStream copy)
      Extra constructor added for org.eclipse.mat.hprof Only safe to use copy or original once the underlying stream has been positioned to the appropriate location. Added by Eclipse MAT.
      Parameters:
      copy - the original stream
  • Method Details

    • read

      public int read() throws IOException
      Reads the next byte of decompressed data from this stream. If data is available then a number in the range [0, 255] is returned (blocking if necessary); otherwise −1 is returned if the end of stream is reached.
      Overrides:
      read in class FilterInputStream
      Returns:
      the next unsigned byte of data, or −1 for the end of stream
      Throws:
      IOException - if an I/O exception occurred in the underlying input stream, the end of stream was encountered at an unexpected position, or the compressed data has a format error
      IllegalStateException - if the stream has already been closed
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Reads some bytes from the decompressed data of this stream into the specified array's subrange. This returns the number of data bytes that were stored into the array, and is in the range [−1, len]. Note that 0 can be returned even if the end of stream hasn't been reached yet.
      Overrides:
      read in class FilterInputStream
      Throws:
      NullPointerException - if the array is null
      ArrayIndexOutOfBoundsException - if the array subrange is out of bounds
      IOException - if an I/O exception occurred in the underlying input stream, the end of stream was encountered at an unexpected position, or the compressed data has a format error
      IllegalStateException - if the stream has already been closed
    • mark

      public void mark(int limit)
      Notes the current position of the output, so that later the caller can go back to this spot by calling reset. This uses the dictionary array as a cache of the last bytes returned to the caller. The dictionary is 32768 bytes in size, however when reading compressed data the inflator can generate an extra 257 bytes which are not returned to the caller but are stored in the dictionary. There is therefore a limit of 32768 - 257 = 32211 bytes that can be stored. Strictly speaking, the InputStream contract expects any value of limit to be honoured, and for implementation to add extra buffering to achieve this. Addition for Eclipse MAT.
      Overrides:
      mark in class FilterInputStream
      Parameters:
      limit - the caller can read at least this many bytes before calling reset()
      See Also:
    • reset

      public void reset() throws IOException
      Goes back in the output to the point where mark(int) was called. Addition for Eclipse MAT
      Overrides:
      reset in class FilterInputStream
      Throws:
      IOException - if it is not possible to go back to the mark point. The current position is then unchanged.
      See Also:
    • markSupported

      public boolean markSupported()
      Does this stream support mark(int) and reset() ? It does. Addition for Eclipse MAT.
      Overrides:
      markSupported in class FilterInputStream
      Returns:
      true
      See Also:
    • available

      public int available() throws IOException
      The number of bytes which can be read without blocking. With the underlying stream it is not clear how many bytes those will expand to so just rely on what is in the buffers. Addition for Eclipse MAT.
      Overrides:
      available in class FilterInputStream
      Returns:
      the number of bytes which can be read without blocking.
      Throws:
      IOException
    • skip

      public long skip(long n) throws IOException
      Overrides:
      skip in class FilterInputStream
      Throws:
      IOException
    • detach

      public void detach() throws IOException
      Detaches the underlying input stream from this decompressor. This puts the underlying stream at the position of the first byte after the data that this decompressor actually consumed. Calling detach() invalidates this stream object but doesn't close the underlying stream.

      This method exists because for efficiency, the decompressor may read more bytes from the underlying stream than necessary to produce the decompressed data. If you want to continue reading the underlying stream exactly after the point the DEFLATE-compressed data ends, then it is necessary to call this detach method.

      This can only be called once, and is mutually exclusive with respect to calling close(). It is illegal to call read() after detaching.

      Throws:
      IllegalStateException - if detach was already called or this stream has been closed
      IOException - if an I/O exception occurred
    • attach

      public void attach()
      Resume decompression. Addition for Eclipse MAT.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • close

      public void close() throws IOException
      Closes this input stream and the underlying stream. It is illegal to call read() or detach() after closing. It is idempotent to call this close() method more than once.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterInputStream
      Throws:
      IOException - if an I/O exception occurred in the underlying stream