Top Description Fields Constructors Methods
java.util.zip

public Class InflaterInputStream

extends FilterInputStream
Class Inheritance
Known Direct Subclasses
java.util.zip.ZipFile.ZipFileInflaterInputStream, java.util.zip.ZipInputStream, java.util.zip.GZIPInputStream
Imports
java.io.FilterInputStream, .InputStream, .IOException, .EOFException, java.util.Objects

This class implements a stream filter for uncompressing data in the "deflate" compression format. It is also used as the basis for other decompression filters, such as GZIPInputStream.

Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.

Author
David Connelly
Since
1.1
See Also
Inflater

Field Summary

Modifier and TypeField and Description
protected byte[]
buf

Input buffer for decompression.

private boolean
protected Inflater
inf

Decompressor for this stream.

protected int
len

The total number of bytes read into the input buffer.

private boolean
private final byte[]
pack-priv boolean
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
InflaterInputStream(InputStream
the input stream
in
,
Inflater
the decompressor ("inflater")
inf
,
int
the input buffer size
size
)

Creates a new input stream with the specified decompressor and buffer size.

public
InflaterInputStream(InputStream
the input stream
in
,
Inflater
the decompressor ("inflater")
inf
)

Creates a new input stream with the specified decompressor and a default buffer size.

public
InflaterInputStream(InputStream
the input stream
in
)

Creates a new input stream with a default decompressor and buffer size.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

1 before EOF and 0 after EOF.
available
()

Overrides java.io.FilterInputStream.available.

Returns 0 after EOF has been reached, otherwise always return 1.

public void
close()

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

private void
ensureOpen()

Check to make sure that this stream has not been closed

protected void
fill()

Fills input buffer with more data to decompress.

public void
mark(int
the maximum limit of bytes that can be read before the mark position becomes invalid.
readlimit
)

Overrides java.io.FilterInputStream.mark.

Marks the current position in this input stream.

public boolean

Returns:

a boolean indicating if this stream type supports the mark and reset methods.
markSupported
()

Overrides java.io.FilterInputStream.markSupported.

Tests if this input stream supports the mark and reset methods.

public int

Returns:

the byte read, or -1 if end of compressed input is reached
read
()

Overrides java.io.FilterInputStream.read.

Reads a byte of uncompressed data.

public int

Returns:

the actual number of bytes inflated, or -1 if the end of the compressed input is reached or a preset dictionary is needed
read
(byte[]
the buffer into which the data is read
b
,
int
the start offset in the destination array b
off
,
int
the maximum number of bytes read
len
)

Overrides java.io.FilterInputStream.read.

Reads uncompressed data into an array of bytes, returning the number of inflated bytes.

public void
reset()

Overrides java.io.FilterInputStream.reset.

Repositions this stream to the position at the time the mark method was last called on this input stream.

public long

Returns:

the actual number of bytes skipped, which might be zero
skip
(long
the number of bytes to skip. If n is zero then no bytes are skipped.
n
)

Overrides java.io.FilterInputStream.skip.

Skips specified number of bytes of uncompressed data.

Inherited from java.io.FilterInputStream:
read

Field Detail

bufback to summary
protected byte[] buf

Input buffer for decompression.

closedback to summary
private boolean closed
infback to summary
protected Inflater inf

Decompressor for this stream.

lenback to summary
protected int len

The total number of bytes read into the input buffer.

reachEOFback to summary
private boolean reachEOF
singleByteBufback to summary
private final byte[] singleByteBuf
usesDefaultInflaterback to summary
pack-priv boolean usesDefaultInflater

Constructor Detail

InflaterInputStreamback to summary
public InflaterInputStream(InputStream in, Inflater inf, int size)

Creates a new input stream with the specified decompressor and buffer size.

Parameters
in:InputStream

the input stream

inf:Inflater

the decompressor ("inflater")

size:int

the input buffer size

Exceptions
IllegalArgumentException:
if size <= 0
InflaterInputStreamback to summary
public InflaterInputStream(InputStream in, Inflater inf)

Creates a new input stream with the specified decompressor and a default buffer size.

Parameters
in:InputStream

the input stream

inf:Inflater

the decompressor ("inflater")

InflaterInputStreamback to summary
public InflaterInputStream(InputStream in)

Creates a new input stream with a default decompressor and buffer size.

Parameters
in:InputStream

the input stream

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.FilterInputStream.available.

Returns 0 after EOF has been reached, otherwise always return 1.

Programs should not count on this method to return the actual number of bytes that could be read without blocking.

Returns:int

1 before EOF and 0 after EOF.

Exceptions
IOException:
if an I/O error occurs.
closeback to summary
public void close() throws IOException

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

Exceptions
IOException:
if an I/O error has occurred
ensureOpenback to summary
private void ensureOpen() throws IOException

Check to make sure that this stream has not been closed

fillback to summary
protected void fill() throws IOException

Fills input buffer with more data to decompress.

Implementation Specification

This method will read up to buf.length bytes into the input buffer, buf, starting at element 0. The len field will be set to the number of bytes read.

Exceptions
IOException:
if an I/O error has occurred
EOFException:
if the end of input stream has been reached unexpectedly
markback to summary
public void mark(int readlimit)

Overrides java.io.FilterInputStream.mark.

Marks the current position in this input stream.

Implementation Specification

The mark method of InflaterInputStream does nothing.

Parameters
readlimit:int

the maximum limit of bytes that can be read before the mark position becomes invalid.

Annotations
@Override
See Also
java.io.InputStream#reset()
markSupportedback to summary
public boolean markSupported()

Overrides java.io.FilterInputStream.markSupported.

Tests if this input stream supports the mark and reset methods. The markSupported method of InflaterInputStream returns false.

Returns:boolean

a boolean indicating if this stream type supports the mark and reset methods.

See Also
java.io.InputStream#mark(int), java.io.InputStream#reset()
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Reads a byte of uncompressed data. This method will block until enough input is available for decompression.

Returns:int

the byte read, or -1 if end of compressed input is reached

Exceptions
IOException:
if an I/O error has occurred
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.FilterInputStream.read.

Reads uncompressed data into an array of bytes, returning the number of inflated bytes. If len is not zero, the method will block until some input can be decompressed; otherwise, no bytes are read and 0 is returned.

If this method returns a nonzero integer n then buf[off] through buf[off+n-1] contain the uncompressed data. The content of elements buf[off+n] through buf[off+len-1] is undefined, contrary to the specification of the InputStream superclass, so an implementation is free to modify these elements during the inflate operation. If this method returns -1 or throws an exception then the content of buf[off] through buf[off+len-1] is undefined.

Parameters
b:byte[]

the buffer into which the data is read

off:int

the start offset in the destination array b

len:int

the maximum number of bytes read

Returns:int

the actual number of bytes inflated, or -1 if the end of the compressed input is reached or a preset dictionary is needed

Exceptions
IOException:
if an I/O error has occurred
IndexOutOfBoundsException:
If off is negative, len is negative, or len is greater than b.length - off
ZipException:
if a ZIP format error has occurred
resetback to summary
public void reset() throws IOException

Overrides java.io.FilterInputStream.reset.

Repositions this stream to the position at the time the mark method was last called on this input stream.

Implementation Specification

The method reset for class InflaterInputStream does nothing except throw an IOException.

Annotations
@Override
Exceptions
IOException:
if this method is invoked.
See Also
java.io.InputStream#mark(int), java.io.IOException
skipback to summary
public long skip(long n) throws IOException

Overrides java.io.FilterInputStream.skip.

Skips specified number of bytes of uncompressed data. This method may block until the specified number of bytes are skipped or end of stream is reached.

Implementation Note

This method skips at most Integer.MAX_VALUE bytes.

Parameters
n:long

the number of bytes to skip. If n is zero then no bytes are skipped.

Returns:long

the actual number of bytes skipped, which might be zero

Exceptions
IOException:
if an I/O error occurs or if this stream is already closed
IllegalArgumentException:
if n < 0