APIdia Launch Partner
Top Description Fields Constructors Methods
java.util.zip

public Class DeflaterInputStream

extends FilterInputStream
Class Inheritance
Imports
java.io.FilterInputStream, .InputStream, .IOException, java.util.Objects

Implements an input stream filter for compressing data in the "deflate" compression format.

Compressor Usage

A DeflaterInputStream created without specifying a compressor will create a compressor at construction time, and close the compressor when the input stream is closed.

If a compressor is specified when creating a DeflaterInputStream, it is the responsibility of the caller to close the compressor after closing the input stream.

API Note

The close method should be called to release resources used by this stream, either directly, or with the try-with-resources statement.

Author
David R Tribble ([email protected])
Since
1.6
See Also
DeflaterOutputStream, InflaterOutputStream, InflaterInputStream

Field Summary

Modifier and TypeField and Description
protected final byte[]
buf

Input buffer for reading compressed data.

protected final Deflater
def

Compressor for this stream.

private byte[]
rbuf

Temporary read buffer.

private boolean
reachEOF

End of the underlying input stream has been reached.

private boolean
usesDefaultDeflater

Default compressor is used.

Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
DeflaterInputStream(InputStream
input stream to read the uncompressed data to
in
)

Creates a new input stream and compressor with the default compression level and a default buffer size.

public
DeflaterInputStream(InputStream
input stream to read the uncompressed data to
in
,
Deflater
compressor ("deflater") for this stream
defl
)

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

public
DeflaterInputStream(InputStream
input stream to read the uncompressed data to
in
,
Deflater
compressor ("deflater") for this stream
defl
,
int
compression buffer size
bufLen
)

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

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

zero after the end of the underlying input stream has been reached, otherwise always returns 1
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 its underlying input stream, discarding any pending uncompressed data.

private void
ensureOpen()

Check to make sure that this stream has not been closed.

public void
mark(int
maximum bytes that can be read before invalidating the position marker
limit
)

Overrides java.io.FilterInputStream.mark.

This operation is not supported.

public boolean

Returns:

false, always
markSupported
()

Overrides java.io.FilterInputStream.markSupported.

Always returns false because this input stream does not support the mark() and reset() methods.

public int

Returns:

a single byte of compressed data, or -1 if the end of the uncompressed input stream is reached
read
()

Overrides java.io.FilterInputStream.read.

Reads a single byte of compressed data from the input stream.

public int

Returns:

the actual number of bytes read, or -1 if the end of the uncompressed input stream is reached
read
(byte[]
buffer into which the data is read
b
,
int
starting offset of the data within b
off
,
int
maximum number of compressed bytes to read into b
len
)

Overrides java.io.FilterInputStream.read.

Reads compressed data into a byte array.

public void
reset()

Overrides java.io.FilterInputStream.reset.

This operation is not supported.

public long

Returns:

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

Overrides java.io.FilterInputStream.skip.

Skips over and discards data from the input stream.

Inherited from java.io.FilterInputStream:
read

Field Detail

bufback to summary
protected final byte[] buf

Input buffer for reading compressed data.

defback to summary
protected final Deflater def

Compressor for this stream.

rbufback to summary
private byte[] rbuf

Temporary read buffer.

reachEOFback to summary
private boolean reachEOF

End of the underlying input stream has been reached.

usesDefaultDeflaterback to summary
private boolean usesDefaultDeflater

Default compressor is used.

Constructor Detail

DeflaterInputStreamback to summary
public DeflaterInputStream(InputStream in)

Creates a new input stream and compressor with the default compression level and a default buffer size.

The compressor will be closed when this input stream is closed.

Parameters
in:InputStream

input stream to read the uncompressed data to

Exceptions
NullPointerException:
if in is null
DeflaterInputStreamback to summary
public DeflaterInputStream(InputStream in, Deflater defl)

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

Closing this input stream will not close the given compressor.

Parameters
in:InputStream

input stream to read the uncompressed data to

defl:Deflater

compressor ("deflater") for this stream

Exceptions
NullPointerException:
if in or defl is null
DeflaterInputStreamback to summary
public DeflaterInputStream(InputStream in, Deflater defl, int bufLen)

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

Closing this input stream will not close the given compressor.

Parameters
in:InputStream

input stream to read the uncompressed data to

defl:Deflater

compressor ("deflater") for this stream

bufLen:int

compression buffer size

Exceptions
IllegalArgumentException:
if bufLen <= 0
NullPointerException:
if in or defl is null

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

zero after the end of the underlying input stream has been reached, otherwise always returns 1

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs or if this stream is already closed
closeback to summary
public void close() throws IOException

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and its underlying input stream, discarding any pending uncompressed data.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
ensureOpenback to summary
private void ensureOpen() throws IOException

Check to make sure that this stream has not been closed.

markback to summary
public void mark(int limit)

Overrides java.io.FilterInputStream.mark.

This operation is not supported.

Parameters
limit:int

maximum bytes that can be read before invalidating the position marker

Annotations
@Override
markSupportedback to summary
public boolean markSupported()

Overrides java.io.FilterInputStream.markSupported.

Always returns false because this input stream does not support the mark() and reset() methods.

Returns:boolean

false, always

Annotations
@Override
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Reads a single byte of compressed data from the input stream. This method will block until some input can be read and compressed.

Returns:int

a single byte of compressed data, or -1 if the end of the uncompressed input stream is reached

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs or if this stream is already closed
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.FilterInputStream.read.

Reads compressed data into a byte array. This method will block until some input can be read and compressed.

Parameters
b:byte[]

buffer into which the data is read

off:int

starting offset of the data within b

len:int

maximum number of compressed bytes to read into b

Returns:int

the actual number of bytes read, or -1 if the end of the uncompressed input stream is reached

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs or if this input stream is already closed
NullPointerException:
if b is null
IndexOutOfBoundsException:
if len > b.length - off
resetback to summary
public void reset() throws IOException

Overrides java.io.FilterInputStream.reset.

This operation is not supported.

Annotations
@Override
Exceptions
IOException:
always thrown
skipback to summary
public long skip(long n) throws IOException

Overrides java.io.FilterInputStream.skip.

Skips over and discards data from the input stream. 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

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

Returns:long

the actual number of bytes skipped, which might be zero

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