# DeflaterOutputStream

public class **DeflaterOutputStream** extends [FilterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html)  

|---|---|---|
| Known Direct Subclasses [GZIPOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/GZIPOutputStream.html), [ZipOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/ZipOutputStream.html) |---|---| | [GZIPOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/GZIPOutputStream.html) | This class implements a stream filter for writing compressed data in the GZIP file format. | | [ZipOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/ZipOutputStream.html) | This class implements an output stream filter for writing files in the ZIP file format. | |||

|---|---|---|
| Known Indirect Subclasses [JarOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/jar/JarOutputStream.html) |---|---| | [JarOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/jar/JarOutputStream.html) | The `JarOutputStream` class is used to write the contents of a JAR file to any output stream. | |||

This class implements an output stream filter for compressing data in
the "deflate" compression format. It is also used as the basis for other
types of compression filters, such as GZIPOutputStream.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html`

### Field Summary

|---|---|---|
| protected byte\[\] | [buf](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#buf) | Output buffer for writing compressed data. |
| protected [Deflater](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html) | [def](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#def) | Compressor for this stream. |

### Inherited Field Summary

From class [java.io.FilterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html)

|---|---|---|
| protected [OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) | [out](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html#out) | The underlying output stream to be filtered. |

### Public Constructor Summary

|---|---|
|   | [DeflaterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#DeflaterOutputStream(java.io.OutputStream,%20java.util.zip.Deflater,%20int,%20boolean))([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out, [Deflater](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html) def, int size, boolean syncFlush) Creates a new output stream with the specified compressor, buffer size and flush mode. |
|   | [DeflaterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#DeflaterOutputStream(java.io.OutputStream,%20java.util.zip.Deflater,%20int))([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out, [Deflater](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html) def, int size) Creates a new output stream with the specified compressor and buffer size. |
|   | [DeflaterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#DeflaterOutputStream(java.io.OutputStream,%20java.util.zip.Deflater,%20boolean))([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out, [Deflater](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html) def, boolean syncFlush) Creates a new output stream with the specified compressor, flush mode and a default buffer size. |
|   | [DeflaterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#DeflaterOutputStream(java.io.OutputStream,%20java.util.zip.Deflater))([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out, [Deflater](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html) def) Creates a new output stream with the specified compressor and a default buffer size. |
|   | [DeflaterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#DeflaterOutputStream(java.io.OutputStream,%20boolean))([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out, boolean syncFlush) Creates a new output stream with a default compressor, a default buffer size and the specified flush mode. |
|   | [DeflaterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#DeflaterOutputStream(java.io.OutputStream))([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out) Creates a new output stream with a default compressor and buffer size. |

### Public Method Summary

|---|---|
| void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#close())() Writes remaining compressed data to the output stream and closes the underlying stream. |
| void | [finish](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#finish())() Finishes writing compressed data to the output stream without closing the underlying stream. |
| void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#flush())() Flushes the compressed output stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#write(byte[],%20int,%20int))(byte\[\] b, int off, int len) Writes an array of bytes to the compressed output stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#write(int))(int b) Writes a byte to the compressed output stream. |

### Protected Method Summary

|---|---|
| void | [deflate](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#deflate())() Writes next block of compressed data to the output stream. |

### Inherited Method Summary

From class [java.io.FilterOutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html)

|---|---|
| void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html#close())() Closes this output stream and releases any system resources associated with the stream. |
| void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html#flush())() Flushes this output stream and forces any buffered output bytes to be written out to the stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html#write(byte[]))(byte\[\] b) Writes `b.length` bytes to this output stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html#write(byte[],%20int,%20int))(byte\[\] b, int off, int len) Writes `len` bytes from the specified `byte` array starting at offset `off` to this output stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FilterOutputStream.html#write(int))(int b) Writes the specified `byte` to this output stream. |

From class [java.io.OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html)

|---|---|
| void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#close())() Closes this output stream and releases any system resources associated with this stream. |
| void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#flush())() Flushes this output stream and forces any buffered output bytes to be written out. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#write(byte[]))(byte\[\] b) Writes `b.length` bytes from the specified byte array to this output stream. |
| void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#write(byte[],%20int,%20int))(byte\[\] b, int off, int len) Writes `len` bytes from the specified byte array starting at offset `off` to this output stream. |
| abstract void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html#write(int))(int b) Writes the specified byte to this output stream. |

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.io.Closeable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html#close())() Closes this stream and releases any system resources associated with it. |

From interface [java.io.Flushable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Flushable.html)

|---|---|
| abstract void | [flush](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Flushable.html#flush())() Flushes this stream by writing any buffered output to the underlying stream. |

From interface [java.lang.AutoCloseable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html#close())() Closes this resource, relinquishing any underlying resources. |

## Fields

#### protected byte\[\]
**buf**

Output buffer for writing compressed data.

#### protected [Deflater](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html)
**def**

Compressor for this stream.

## Public Constructors

#### public
**DeflaterOutputStream**
([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out, [Deflater](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html) def, int size, boolean syncFlush)

Creates a new output stream with the specified compressor,
buffer size and flush mode.

##### Parameters

| out | the output stream |
| def | the compressor ("deflater") |
| size | the output buffer size |
| syncFlush | if `true` the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#flush()` method of this instance flushes the compressor with flush mode `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html#SYNC_FLUSH` before flushing the output stream, otherwise only flushes the output stream |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if `size <= 0` |
|---|---|

#### public
**DeflaterOutputStream**
([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out, [Deflater](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html) def, int size)

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

The new output stream instance is created as if by invoking
the 4-argument constructor DeflaterOutputStream(out, def, size, false).

##### Parameters

| out | the output stream |
| def | the compressor ("deflater") |
| size | the output buffer size |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if `size <= 0` |
|---|---|

#### public
**DeflaterOutputStream**
([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out, [Deflater](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html) def, boolean syncFlush)

Creates a new output stream with the specified compressor, flush
mode and a default buffer size.

##### Parameters

| out | the output stream |
| def | the compressor ("deflater") |
| syncFlush | if `true` the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#flush()` method of this instance flushes the compressor with flush mode `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html#SYNC_FLUSH` before flushing the output stream, otherwise only flushes the output stream |
|---|---|

#### public
**DeflaterOutputStream**
([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out, [Deflater](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html) def)

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

The new output stream instance is created as if by invoking
the 3-argument constructor DeflaterOutputStream(out, def, false).

##### Parameters

| out | the output stream |
| def | the compressor ("deflater") |
|---|---|

#### public
**DeflaterOutputStream**
([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out, boolean syncFlush)

Creates a new output stream with a default compressor, a default
buffer size and the specified flush mode.

##### Parameters

| out | the output stream |
| syncFlush | if `true` the `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#flush()` method of this instance flushes the compressor with flush mode `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html#SYNC_FLUSH` before flushing the output stream, otherwise only flushes the output stream |
|---|---|

#### public
**DeflaterOutputStream**
([OutputStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/OutputStream.html) out)

Creates a new output stream with a default compressor and buffer size.

The new output stream instance is created as if by invoking
the 2-argument constructor DeflaterOutputStream(out, false).

##### Parameters

| out | the output stream |
|---|---|

## Public Methods

#### public void
**close**
()

Writes remaining compressed data to the output stream and closes the
underlying stream.

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error has occurred |
|---|---|

#### public void
**finish**
()

Finishes writing compressed data to the output stream without closing
the underlying stream. Use this method when applying multiple filters
in succession to the same output stream.

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error has occurred |
|---|---|

#### public void
**flush**
()

Flushes the compressed output stream.

If `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/DeflaterOutputStream.html#DeflaterOutputStream(java.io.OutputStream,%20java.util.zip.Deflater,%20int,%20boolean)` is `true` when this compressed output stream is
constructed, this method first flushes the underlying `compressor`
with the flush mode `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/zip/Deflater.html#SYNC_FLUSH` to force
all pending data to be flushed out to the output stream and then
flushes the output stream. Otherwise this method only flushes the
output stream without flushing the `compressor`.

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error has occurred |
|---|---|

#### public void
**write**
(byte\[\] b, int off, int len)

Writes an array of bytes to the compressed output stream. This
method will block until all the bytes are written.

##### Parameters

| b | the data to be written |
| off | the start offset of the data |
| len | the length of the data |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error has occurred |
|---|---|

#### public void
**write**
(int b)

Writes a byte to the compressed output stream. This method will
block until the byte can be written.

##### Parameters

| b | the byte to be written |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error has occurred |
|---|---|

## Protected Methods

#### protected void
**deflate**
()

Writes next block of compressed data to the output stream.

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error has occurred |
|---|---|