io.nayuki.deflate

## 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 and Description
`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.
`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

All Methods Instance Methods Concrete Methods
`void` `close()` Closes this input stream and the underlying stream.
`void` `detach()` Detaches the underlying input stream from this decompressor.
`int` `read()` 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.

### Methods inherited from class java.io.FilterInputStream

`available, mark, markSupported, read, reset, skip`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### 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.

### Method Detail

#### 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

#### 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

#### 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 `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Overrides:
  `close` in class `FilterInputStream`
Throws:
  `IOException` - if an I/O exception occurred in the underlying stream