Class InflaterOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
public class InflaterOutputStream extends FilterOutputStream
Decompressor Usage
AnInflaterOutputStream created without specifying a decompressor will create a decompressor at construction time, and close the decompressor when the output stream is closed or when finish() is called. If a decompressor is specified when creating a InflaterOutputStream, it is the responsibility of the caller to close the decompressor after closing the output 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 |
Output buffer for writing decompressed data. |
protected final Inflater |
inf |
Decompressor for this stream. |
Fields declared in class FilterOutputStream
out | Modifier and Type | Field | Description |
|---|---|---|
protected OutputStream |
out |
The underlying output stream to be filtered. |
Constructor Summary
| Constructor | Description |
|---|---|
InflaterOutputStream |
Creates a new output stream and decompressor with a default buffer size. |
InflaterOutputStream |
Creates a new output stream with the specified decompressor and a default buffer size. |
InflaterOutputStream |
Creates a new output stream with the specified decompressor and buffer size. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Writes any remaining decompressed data to the output stream and closes the underlying output stream. |
void |
finish() |
Writes any pending buffered decompressed data to the underlying output stream, without closing the underlying stream. |
void |
flush() |
Flushes this output stream, writing any pending buffered decompressed data to the underlying output stream. |
void |
write |
Writes an array of bytes to the decompressed output stream. |
void |
write |
Writes a byte to the decompressed output stream. |
Methods declared in class FilterOutputStream
write | Modifier and Type | Method | Description |
|---|---|---|
void |
write |
Writes b.length bytes to this output stream. |
Methods declared in class OutputStream
nullOutputStream | Modifier and Type | Method | Description |
|---|---|---|
static OutputStream |
nullOutputStream() |
Returns a new OutputStream which discards all bytes. |
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
String |
toString() |
Returns a string representation of the object. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Field Details
inf
protected final Inflater inf
buf
protected final byte[] buf
Constructor Details
InflaterOutputStream
public InflaterOutputStream(OutputStream out)
The decompressor will be closed when this output stream is closed.
- Parameters:
-
out- output stream to write the decompressed data to - Throws:
-
NullPointerException- ifoutis null
InflaterOutputStream
public InflaterOutputStream(OutputStream out, Inflater infl)
Closing this output stream will not close the given decompressor.
- Parameters:
-
out- output stream to write the decompressed data to -
infl- decompressor ("inflater") for this stream - Throws:
-
NullPointerException- ifoutorinflis null
InflaterOutputStream
public InflaterOutputStream(OutputStream out, Inflater infl, int bufLen)
Closing this output stream will not close the given decompressor.
- Parameters:
-
out- output stream to write the decompressed data to -
infl- decompressor ("inflater") for this stream -
bufLen- decompression buffer size - Throws:
-
IllegalArgumentException- ifbufLen <= 0 -
NullPointerException- ifoutorinflis null
Method Details
close
public void close() throws IOException
- Specified by:
-
closein interfaceAutoCloseable - Specified by:
-
closein interfaceCloseable - Overrides:
-
closein classFilterOutputStream - Implementation Requirements:
- If not already closed, this method calls
finish()before closing the underlying output stream. - Throws:
-
IOException- if an I/O error occurs - See Also:
flush
public void flush() throws IOException
- Specified by:
-
flushin interfaceFlushable - Overrides:
-
flushin classFilterOutputStream - Throws:
-
IOException- if an I/O error occurs or this stream is already closed - See Also:
finish
public void finish() throws IOException
- Implementation Requirements:
- This method calls
flush()to write any pending buffered decompressed data.If this
InflaterOutputStreamwas created without specifying a decompressor, then this method closes the decompressor that was created at construction time. TheInflaterOutputStreamcannot then be used for any further writes. - Throws:
-
IOException- if an I/O error occurs or this stream is already closed
write
public void write(int b) throws IOException
- Overrides:
-
writein classFilterOutputStream - Parameters:
-
b- a single byte of compressed data to decompress and write to the output stream - Throws:
-
IOException- if an I/O error occurs or this stream is already closed -
ZipException- if a compression (ZIP) format error occurs
write
public void write(byte[] b, int off, int len) throws IOException
- Overrides:
-
writein classFilterOutputStream - Parameters:
-
b- buffer containing compressed data to decompress and write to the output stream -
off- starting offset of the compressed data withinb -
len- number of bytes to decompress fromb - Throws:
-
IndexOutOfBoundsException- ifoff < 0, or iflen < 0, or iflen > b.length - off -
IOException- if an I/O error occurs or this stream is already closed -
NullPointerException- ifbis null -
ZipException- if a compression (ZIP) format error occurs - 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.