Class DeflaterInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.util.zip.DeflaterInputStream
- All Implemented Interfaces:
-
Closeable
,AutoCloseable
public class DeflaterInputStream extends FilterInputStream
Implements an input stream filter for compressing data in the "deflate" compression format.
- 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 java.io.FilterInputStream
in
Constructor Summary
Constructor | Description |
---|---|
DeflaterInputStream |
Creates a new input stream with a default compressor and 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 java.io.FilterInputStream
read
Methods declared in class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
Field Details
def
protected final Deflater def
Compressor for this stream.
buf
protected final byte[] buf
Input buffer for reading compressed data.
Constructor Details
DeflaterInputStream
public DeflaterInputStream(InputStream in)
Creates a new input stream with a default compressor and buffer size.
- Parameters:
-
in
- input stream to read the uncompressed data to - Throws:
-
NullPointerException
- ifin
is null
DeflaterInputStream
public DeflaterInputStream(InputStream in, Deflater defl)
Creates a new input stream with the specified compressor and a default buffer size.
- Parameters:
-
in
- input stream to read the uncompressed data to -
defl
- compressor ("deflater") for this stream - Throws:
-
NullPointerException
- ifin
ordefl
is null
DeflaterInputStream
public DeflaterInputStream(InputStream in, Deflater defl, int bufLen)
Creates a new input stream with the specified compressor and buffer size.
- 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
- ifin
ordefl
is null
Method Details
close
public void close() throws IOException
Closes this input stream and its underlying input stream, discarding any pending uncompressed data.
- Specified by:
-
close
in interfaceAutoCloseable
- Specified by:
-
close
in interfaceCloseable
- Overrides:
-
close
in classFilterInputStream
- Throws:
-
IOException
- if an I/O error occurs - See Also:
read
public int read() throws IOException
Reads a single byte of compressed data from the input stream. This method will block until some input can be read and compressed.
- Overrides:
-
read
in 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
Reads compressed data into a byte array. This method will block until some input can be read and compressed.
- Overrides:
-
read
in 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:
-
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
Skips over and discards data from the input stream. This method may block until the specified number of bytes are read and skipped. Note: While
n
is given as a long
, the maximum number of bytes which can be skipped is Integer.MAX_VALUE
.- Overrides:
-
skip
in classFilterInputStream
- Parameters:
-
n
- number of bytes to be skipped - Returns:
- the actual number of bytes skipped
- Throws:
-
IOException
- if an I/O error occurs or if this stream is already closed - See Also:
available
public int available() throws IOException
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
- Overrides:
-
available
in 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:
-
markSupported
in classFilterInputStream
- Returns:
- false, always
- See Also:
mark
public void mark(int limit)
This operation is not supported.
- Overrides:
-
mark
in classFilterInputStream
- Parameters:
-
limit
- maximum bytes that can be read before invalidating the position marker - See Also:
reset
public void reset() throws IOException
This operation is not supported.
- Overrides:
-
reset
in classFilterInputStream
- Throws:
-
IOException
- always thrown - See Also:
© 1993, 2021, 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/17/docs/api/java.base/java/util/zip/DeflaterInputStream.html