Class DeflaterInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable
public class DeflaterInputStream extends FilterInputStream
Compressor Usage
ADeflaterInputStream 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 thetry-with-resources statement. - Since:
- 1.6
- See Also:
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
protected final byte[] |
buf |
Input buffer for reading compressed data. |
protected final Deflater |
def |
Compressor for this stream. |
Fields declared in class FilterInputStream
in
Constructor Summary
| 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. |
Method Summary
| 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. |
Methods declared in class FilterInputStream
read
Methods declared in class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
Field Details
def
protected final Deflater def
buf
protected final byte[] buf
Constructor Details
DeflaterInputStream
public DeflaterInputStream(InputStream in)
The compressor will be closed when this input stream is closed.
- Parameters:
-
in- input stream to read the uncompressed data to - Throws:
-
NullPointerException- ifinis null
DeflaterInputStream
public DeflaterInputStream(InputStream in, Deflater defl)
Closing this input stream will not close the given compressor.
- Parameters:
-
in- input stream to read the uncompressed data to -
defl- compressor ("deflater") for this stream - Throws:
-
NullPointerException- ifinordeflis null
DeflaterInputStream
public DeflaterInputStream(InputStream in, Deflater defl, int bufLen)
Closing this input stream will not close the given compressor.
- Parameters:
-
in- input stream to read the uncompressed data to -
defl- compressor ("deflater") for this stream -
bufLen- compression buffer size - Throws:
-
IllegalArgumentException- ifbufLen <= 0 -
NullPointerException- ifinordeflis null
Method Details
close
public void close() throws IOException
- Specified by:
-
closein interfaceAutoCloseable - Specified by:
-
closein interfaceCloseable - Overrides:
-
closein classFilterInputStream - Throws:
-
IOException- if an I/O error occurs - See Also:
read
public int read() throws IOException
- Overrides:
-
readin classFilterInputStream - Returns:
- a single byte of compressed data, or -1 if the end of the uncompressed input stream is reached
- Throws:
-
IOException- if an I/O error occurs or if this stream is already closed - See Also:
read
public int read(byte[] b, int off, int len) throws IOException
- Overrides:
-
readin classFilterInputStream - Parameters:
-
b- buffer into which the data is read -
off- starting offset of the data withinb -
len- maximum number of compressed bytes to read intob - Returns:
- the actual number of bytes read, or -1 if the end of the uncompressed input stream is reached
- Throws:
-
NullPointerException- ifbis null -
IndexOutOfBoundsException- iflen > b.length - off -
IOException- if an I/O error occurs or if this input stream is already closed - See Also:
skip
public long skip(long n) throws IOException
- Overrides:
-
skipin classFilterInputStream - Implementation Note:
- This method skips at most
Integer.MAX_VALUEbytes. - Parameters:
-
n- number of bytes to be skipped. Ifnis zero then no bytes are skipped. - Returns:
- the actual number of bytes skipped, which might be zero
- Throws:
-
IOException- if an I/O error occurs or if this stream is already closed -
IllegalArgumentException- ifn < 0 - See Also:
available
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
- Overrides:
-
availablein classFilterInputStream - Returns:
- zero after the end of the underlying input stream has been reached, otherwise always returns 1
- Throws:
-
IOException- if an I/O error occurs or if this stream is already closed
markSupported
public boolean markSupported()
- Overrides:
-
markSupportedin classFilterInputStream - Returns:
- false, always
- See Also:
mark
public void mark(int limit)
- Overrides:
-
markin classFilterInputStream - Parameters:
-
limit- maximum bytes that can be read before invalidating the position marker - See Also:
reset
public void reset() throws IOException
- Overrides:
-
resetin classFilterInputStream - Throws:
-
IOException- always thrown - See Also:
© 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