Closeable, AutoCloseablepublic class DeflaterInputStream extends FilterInputStream
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.
close() method should be called to release resources used by this stream, either directly, or with the try-with-resources statement.| Modifier and Type | Field | Description |
|---|---|---|
protected final byte[] |
buf |
Input buffer for reading compressed data. |
protected final Deflater |
def |
Compressor for this stream. |
in
| Constructor | Description |
|---|---|
DeflaterInputStream |
Creates a new input stream and compressor with the default compression level and a default buffer size. |
DeflaterInputStream |
Creates a new input stream with the specified compressor and a default buffer size. |
DeflaterInputStream |
Creates a new input stream with the specified compressor and buffer size. |
| Modifier and Type | Method | Description |
|---|---|---|
int |
available() |
Returns 0 after EOF has been reached, otherwise always return 1. |
void |
close() |
Closes this input stream and its underlying input stream, discarding any pending uncompressed data. |
void |
mark |
This operation is not supported. |
boolean |
markSupported() |
|
int |
read() |
Reads a single byte of compressed data from the input stream. |
int |
read |
Reads compressed data into a byte array. |
void |
reset() |
This operation is not supported. |
long |
skip |
Skips over and discards data from the input stream. |
read
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
protected final Deflater def
protected final byte[] buf
public DeflaterInputStream(InputStream in)
The compressor will be closed when this input stream is closed.
in - input stream to read the uncompressed data toNullPointerException - if in is nullpublic DeflaterInputStream(InputStream in, Deflater defl)
Closing this input stream will not close the given compressor.
in - input stream to read the uncompressed data todefl - compressor ("deflater") for this streamNullPointerException - if in or defl is nullpublic DeflaterInputStream(InputStream in, Deflater defl, int bufLen)
Closing this input stream will not close the given compressor.
in - input stream to read the uncompressed data todefl - compressor ("deflater") for this streambufLen - compression buffer sizeIllegalArgumentException - if bufLen <= 0
NullPointerException - if in or defl is nullpublic void close() throws IOException
close in interface AutoCloseable
close in interface Closeable
close in class FilterInputStream
IOException - if an I/O error occurspublic int read() throws IOException
read in class FilterInputStream
IOException - if an I/O error occurs or if this stream is already closedpublic int read(byte[] b, int off, int len) throws IOException
read in class FilterInputStream
b - buffer into which the data is readoff - starting offset of the data within b
len - maximum number of compressed bytes to read into b
NullPointerException - if b is nullIndexOutOfBoundsException - if len > b.length - off
IOException - if an I/O error occurs or if this input stream is already closedpublic long skip(long n) throws IOException
skip in class FilterInputStream
Integer.MAX_VALUE bytes.n - number of bytes to be skipped. If n is zero then no bytes are skipped.IOException - if an I/O error occurs or if this stream is already closedIllegalArgumentException - if n < 0
public int available() throws IOException
Programs should not count on this method to return the actual number of bytes that could be read without blocking
available in class FilterInputStream
IOException - if an I/O error occurs or if this stream is already closedpublic boolean markSupported()
markSupported in class FilterInputStream
public void mark(int limit)
mark in class FilterInputStream
limit - maximum bytes that can be read before invalidating the position markerpublic void reset() throws IOException
reset in class FilterInputStream
IOException - always thrown
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/zip/DeflaterInputStream.html