Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Fields](https://developer.android.com/reference/java/util/zip/GZIPOutputStream#lfields) \| [Inherited Fields](https://developer.android.com/reference/java/util/zip/GZIPOutputStream#inhfields) \| [Ctors](https://developer.android.com/reference/java/util/zip/GZIPOutputStream#pubctors) \| [Methods](https://developer.android.com/reference/java/util/zip/GZIPOutputStream#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/util/zip/GZIPOutputStream#inhmethods)

# GZIPOutputStream


`
public


class
GZIPOutputStream
`


`


`

`


`

`


`

`

extends https://developer.android.com/reference/java/util/zip/DeflaterOutputStream


`

`


`

|---|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||||
| ↳ | [java.io.OutputStream](https://developer.android.com/reference/java/io/OutputStream) ||||
|   | ↳ | [java.io.FilterOutputStream](https://developer.android.com/reference/java/io/FilterOutputStream) |||
|   |   | ↳ | [java.util.zip.DeflaterOutputStream](https://developer.android.com/reference/java/util/zip/DeflaterOutputStream) ||
|   |   |   | ↳ | java.util.zip.GZIPOutputStream |

<br />

*** ** * ** ***

This class implements a stream filter for writing compressed data in
the GZIP file format.

## Summary

| ### Fields ||
|---|---|
| ` protected https://developer.android.com/reference/java/util/zip/CRC32` | `https://developer.android.com/reference/java/util/zip/GZIPOutputStream#crc` CRC-32 of uncompressed data. |

| ### Inherited fields |
|---|
| From class `https://developer.android.com/reference/java/util/zip/DeflaterOutputStream` |---|---| | ` protected byte[]` | `https://developer.android.com/reference/java/util/zip/DeflaterOutputStream#buf` Output buffer for writing compressed data. | | ` protected https://developer.android.com/reference/java/util/zip/Deflater` | `https://developer.android.com/reference/java/util/zip/DeflaterOutputStream#def` Compressor for this stream. | |
| From class `https://developer.android.com/reference/java/io/FilterOutputStream` |---|---| | ` protected https://developer.android.com/reference/java/io/OutputStream` | `https://developer.android.com/reference/java/io/FilterOutputStream#out` The underlying output stream to be filtered. | |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/util/zip/GZIPOutputStream#GZIPOutputStream(java.io.OutputStream)(https://developer.android.com/reference/java/io/OutputStream out) ` Creates a new output stream with a default buffer size. |
| ` https://developer.android.com/reference/java/util/zip/GZIPOutputStream#GZIPOutputStream(java.io.OutputStream,%20boolean)(https://developer.android.com/reference/java/io/OutputStream out, boolean syncFlush) ` Creates a new output stream with a default buffer size and the specified flush mode. |
| ` https://developer.android.com/reference/java/util/zip/GZIPOutputStream#GZIPOutputStream(java.io.OutputStream,%20int)(https://developer.android.com/reference/java/io/OutputStream out, int size) ` Creates a new output stream with the specified buffer size. |
| ` https://developer.android.com/reference/java/util/zip/GZIPOutputStream#GZIPOutputStream(java.io.OutputStream,%20int,%20boolean)(https://developer.android.com/reference/java/io/OutputStream out, int size, boolean syncFlush) ` Creates a new output stream with the specified buffer size and flush mode. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/java/util/zip/GZIPOutputStream#finish()() ` Finishes writing compressed data to the output stream without closing the underlying stream. |
| ` void` | ` https://developer.android.com/reference/java/util/zip/GZIPOutputStream#write(byte[],%20int,%20int)(byte[] buf, int off, int len) ` Writes array of bytes to the compressed output stream. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/util/zip/DeflaterOutputStream ` |---|---| | ` void` | ` https://developer.android.com/reference/java/util/zip/DeflaterOutputStream#close()() ` Writes remaining compressed data to the output stream and closes the underlying stream. | | ` void` | ` https://developer.android.com/reference/java/util/zip/DeflaterOutputStream#deflate()() ` Writes next block of compressed data to the output stream. | | ` void` | ` https://developer.android.com/reference/java/util/zip/DeflaterOutputStream#finish()() ` Finishes writing compressed data to the output stream without closing the underlying stream. | | ` void` | ` https://developer.android.com/reference/java/util/zip/DeflaterOutputStream#flush()() ` Flushes the compressed output stream. | | ` void` | ` https://developer.android.com/reference/java/util/zip/DeflaterOutputStream#write(byte[],%20int,%20int)(byte[] b, int off, int len) ` Writes an array of bytes to the compressed output stream. | | ` void` | ` https://developer.android.com/reference/java/util/zip/DeflaterOutputStream#write(int)(int b) ` Writes a byte to the compressed output stream. | ||
| From class ` https://developer.android.com/reference/java/io/FilterOutputStream ` |---|---| | ` void` | ` https://developer.android.com/reference/java/io/FilterOutputStream#close()() ` Closes this output stream and releases any system resources associated with the stream. | | ` void` | ` https://developer.android.com/reference/java/io/FilterOutputStream#flush()() ` Flushes this output stream and forces any buffered output bytes to be written out to the stream. | | ` void` | ` https://developer.android.com/reference/java/io/FilterOutputStream#write(byte[])(byte[] b) ` Writes `b.length` bytes to this output stream. | | ` void` | ` https://developer.android.com/reference/java/io/FilterOutputStream#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` | ` https://developer.android.com/reference/java/io/FilterOutputStream#write(int)(int b) ` Writes the specified `byte` to this output stream. | ||
| From class ` https://developer.android.com/reference/java/io/OutputStream ` |---|---| | ` void` | ` https://developer.android.com/reference/java/io/OutputStream#close()() ` Closes this output stream and releases any system resources associated with this stream. | | ` void` | ` https://developer.android.com/reference/java/io/OutputStream#flush()() ` Flushes this output stream and forces any buffered output bytes to be written out. | | ` static https://developer.android.com/reference/java/io/OutputStream` | ` https://developer.android.com/reference/java/io/OutputStream#nullOutputStream()() ` Returns a new `OutputStream` which discards all bytes. | | ` void` | ` https://developer.android.com/reference/java/io/OutputStream#write(byte[])(byte[] b) ` Writes `b.length` bytes from the specified byte array to this output stream. | | ` void` | ` https://developer.android.com/reference/java/io/OutputStream#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` | ` https://developer.android.com/reference/java/io/OutputStream#write(int)(int b) ` Writes the specified byte to this output stream. | ||
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` 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` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` 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` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/java/io/Closeable ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/io/Closeable#close()() ` Closes this stream and releases any system resources associated with it. | ||
| From interface ` https://developer.android.com/reference/java/io/Flushable ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/io/Flushable#flush()() ` Flushes this stream by writing any buffered output to the underlying stream. | ||
| From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() ` Closes this resource, relinquishing any underlying resources. | ||

## Fields

### crc

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected CRC32 crc
```

CRC-32 of uncompressed data.

<br />

## Public constructors

### GZIPOutputStream

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public GZIPOutputStream (OutputStream out)
```

Creates a new output stream with a default buffer size.

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

<br />

| Parameters ||
|---|---|
| `out` | `OutputStream`: the output stream <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error has occurred. |

### GZIPOutputStream

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public GZIPOutputStream (OutputStream out, 
                boolean syncFlush)
```

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

<br />

| Parameters ||
|---|---|
| `out` | `OutputStream`: the output stream <br /> |
| `syncFlush` | `boolean`: if `true` invocation of the inherited `https://developer.android.com/reference/java/util/zip/DeflaterOutputStream#flush()` method of this instance flushes the compressor with flush mode `https://developer.android.com/reference/java/util/zip/Deflater#SYNC_FLUSH` before flushing the output stream, otherwise only flushes the output stream <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error has occurred. |

### GZIPOutputStream

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public GZIPOutputStream (OutputStream out, 
                int size)
```

Creates a new output stream with the specified buffer size.

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

Android-note: Android limits the number of UnbufferedIO operations that can be performed, so
consider using buffered inputs with this class. More information can be found in the
[UnbufferedIO](https://developer.android.com/reference/android/os/StrictMode.ThreadPolicy.Builder#detectUnbufferedIo()) and
[StrictMode](https://developer.android.com/reference/android/os/StrictMode)
documentation.

<br />

| Parameters ||
|---|---|
| `out` | `OutputStream`: the output stream <br /> |
| `size` | `int`: the output buffer size <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error has occurred. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `size <= 0` |

### GZIPOutputStream

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public GZIPOutputStream (OutputStream out, 
                int size, 
                boolean syncFlush)
```

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

<br />

| Parameters ||
|---|---|
| `out` | `OutputStream`: the output stream <br /> |
| `size` | `int`: the output buffer size <br /> |
| `syncFlush` | `boolean`: if `true` invocation of the inherited `https://developer.android.com/reference/java/util/zip/DeflaterOutputStream#flush()` method of this instance flushes the compressor with flush mode `https://developer.android.com/reference/java/util/zip/Deflater#SYNC_FLUSH` before flushing the output stream, otherwise only flushes the output stream <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error has occurred. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `size <= 0` |

## Public methods

### finish

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error has occurred |

### write

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void write (byte[] buf, 
                int off, 
                int len)
```

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

<br />

| Parameters ||
|---|---|
| `buf` | `byte`: the data to be written <br /> |
| `off` | `int`: the start offset of the data <br /> |
| `len` | `int`: the length of the data <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an I/O error has occurred. |