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

# Deflater

` public class Deflater `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.util.zip.Deflater |

<br />

*** ** * ** ***

This class provides support for general purpose compression using the popular ZLIB compression library. The ZLIB compression library was initially developed as part of the PNG graphics standard and is not protected by patents. It is fully described in the specifications at the [java.util.zip package description](https://developer.android.com/reference/java/util/zip/package-summary#package-description).

This class deflates sequences of bytes into ZLIB compressed data format. The input byte sequence is provided in either byte array or byte buffer, via one of the `setInput()` methods. The output byte sequence is written to the output byte array or byte buffer passed to the `deflate()` methods.

The following code fragment demonstrates a trivial compression and decompression of a string using `Deflater` and `Inflater`.
>
> ```
> try {
>     // Encode a String into bytes
>     String inputString = "blahblahblah";
>     byte[] input = inputString.getBytes("UTF-8");
>
>     // Compress the bytes
>     byte[] output = new byte[100];
>     Deflater compresser = new Deflater();
>     compresser.setInput(input);
>     compresser.finish();
>     int compressedDataLength = compresser.deflate(output);
>     compresser.end();
>
>     // Decompress the bytes
>     Inflater decompresser = new Inflater();
>     decompresser.setInput(output, 0, compressedDataLength);
>     byte[] result = new byte[100];
>     int resultLength = decompresser.inflate(result);
>     decompresser.end();
>
>     // Decode the bytes into a String
>     String outputString = new String(result, 0, resultLength, "UTF-8");
> } catch (java.io.UnsupportedEncodingException ex) {
>     // handle
> } catch (java.util.zip.DataFormatException ex) {
>     // handle
> }
> ```

<br />

**See also:**

- `https://developer.android.com/reference/java/util/zip/Inflater`

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/java/util/zip/Deflater#BEST_COMPRESSION` Compression level for best compression. |
| `int` | `https://developer.android.com/reference/java/util/zip/Deflater#BEST_SPEED` Compression level for fastest compression. |
| `int` | `https://developer.android.com/reference/java/util/zip/Deflater#DEFAULT_COMPRESSION` Default compression level. |
| `int` | `https://developer.android.com/reference/java/util/zip/Deflater#DEFAULT_STRATEGY` Default compression strategy. |
| `int` | `https://developer.android.com/reference/java/util/zip/Deflater#DEFLATED` Compression method for the deflate algorithm (the only one currently supported). |
| `int` | `https://developer.android.com/reference/java/util/zip/Deflater#FILTERED` Compression strategy best used for data consisting mostly of small values with a somewhat random distribution. |
| `int` | `https://developer.android.com/reference/java/util/zip/Deflater#FULL_FLUSH` Compression flush mode used to flush out all pending output and reset the deflater. |
| `int` | `https://developer.android.com/reference/java/util/zip/Deflater#HUFFMAN_ONLY` Compression strategy for Huffman coding only. |
| `int` | `https://developer.android.com/reference/java/util/zip/Deflater#NO_COMPRESSION` Compression level for no compression. |
| `int` | `https://developer.android.com/reference/java/util/zip/Deflater#NO_FLUSH` Compression flush mode used to achieve best compression result. |
| `int` | `https://developer.android.com/reference/java/util/zip/Deflater#SYNC_FLUSH` Compression flush mode used to flush out all pending output; may degrade compression for some compression algorithms. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/util/zip/Deflater#Deflater()() ` Creates a new compressor with the default compression level. |
| ` https://developer.android.com/reference/java/util/zip/Deflater#Deflater(int)(int level) ` Creates a new compressor using the specified compression level. |
| ` https://developer.android.com/reference/java/util/zip/Deflater#Deflater(int,%20boolean)(int level, boolean nowrap) ` Creates a new compressor using the specified compression level. |

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/java/util/zip/Deflater#deflate(byte[],%20int,%20int)(byte[] output, int off, int len) ` Compresses the input data and fills specified buffer with compressed data. |
| ` int` | ` https://developer.android.com/reference/java/util/zip/Deflater#deflate(byte[])(byte[] output) ` Compresses the input data and fills specified buffer with compressed data. |
| ` int` | ` https://developer.android.com/reference/java/util/zip/Deflater#deflate(byte[],%20int,%20int,%20int)(byte[] output, int off, int len, int flush) ` Compresses the input data and fills the specified buffer with compressed data. |
| ` int` | ` https://developer.android.com/reference/java/util/zip/Deflater#deflate(java.nio.ByteBuffer,%20int)(https://developer.android.com/reference/java/nio/ByteBuffer output, int flush) ` Compresses the input data and fills the specified buffer with compressed data. |
| ` int` | ` https://developer.android.com/reference/java/util/zip/Deflater#deflate(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer output) ` Compresses the input data and fills specified buffer with compressed data. |
| ` void` | ` https://developer.android.com/reference/java/util/zip/Deflater#end()() ` Closes the compressor and discards any unprocessed input. |
| ` void` | ` https://developer.android.com/reference/java/util/zip/Deflater#finish()() ` When called, indicates that compression should end with the current contents of the input buffer. |
| ` boolean` | ` https://developer.android.com/reference/java/util/zip/Deflater#finished()() ` Returns true if the end of the compressed data output stream has been reached. |
| ` int` | ` https://developer.android.com/reference/java/util/zip/Deflater#getAdler()() ` Returns the ADLER-32 value of the uncompressed data. |
| ` long` | ` https://developer.android.com/reference/java/util/zip/Deflater#getBytesRead()() ` Returns the total number of uncompressed bytes input so far. |
| ` long` | ` https://developer.android.com/reference/java/util/zip/Deflater#getBytesWritten()() ` Returns the total number of compressed bytes output so far. |
| ` int` | ` https://developer.android.com/reference/java/util/zip/Deflater#getTotalIn()() ` Returns the total number of uncompressed bytes input so far. |
| ` int` | ` https://developer.android.com/reference/java/util/zip/Deflater#getTotalOut()() ` Returns the total number of compressed bytes output so far. |
| ` boolean` | ` https://developer.android.com/reference/java/util/zip/Deflater#needsInput()() ` Returns true if no data remains in the input buffer. |
| ` void` | ` https://developer.android.com/reference/java/util/zip/Deflater#reset()() ` Resets deflater so that a new set of input data can be processed. |
| ` void` | ` https://developer.android.com/reference/java/util/zip/Deflater#setDictionary(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer dictionary) ` Sets preset dictionary for compression. |
| ` void` | ` https://developer.android.com/reference/java/util/zip/Deflater#setDictionary(byte[],%20int,%20int)(byte[] dictionary, int off, int len) ` Sets preset dictionary for compression. |
| ` void` | ` https://developer.android.com/reference/java/util/zip/Deflater#setDictionary(byte[])(byte[] dictionary) ` Sets preset dictionary for compression. |
| ` void` | ` https://developer.android.com/reference/java/util/zip/Deflater#setInput(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer input) ` Sets input data for compression. |
| ` void` | ` https://developer.android.com/reference/java/util/zip/Deflater#setInput(byte[],%20int,%20int)(byte[] input, int off, int len) ` Sets input data for compression. |
| ` void` | ` https://developer.android.com/reference/java/util/zip/Deflater#setInput(byte[])(byte[] input) ` Sets input data for compression. |
| ` void` | ` https://developer.android.com/reference/java/util/zip/Deflater#setLevel(int)(int level) ` Sets the compression level to the specified value. |
| ` void` | ` https://developer.android.com/reference/java/util/zip/Deflater#setStrategy(int)(int strategy) ` Sets the compression strategy to the specified value. |

### Inherited methods

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

## Constants

### BEST_COMPRESSION

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

```
public static final int BEST_COMPRESSION
```

Compression level for best compression.

<br />

Constant Value: 9 (0x00000009)

### BEST_SPEED

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

```
public static final int BEST_SPEED
```

Compression level for fastest compression.

<br />

Constant Value: 1 (0x00000001)

### DEFAULT_COMPRESSION

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

```
public static final int DEFAULT_COMPRESSION
```

Default compression level.

<br />

Constant Value: -1 (0xffffffff)

### DEFAULT_STRATEGY

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

```
public static final int DEFAULT_STRATEGY
```

Default compression strategy.

<br />

Constant Value: 0 (0x00000000)

### DEFLATED

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

```
public static final int DEFLATED
```

Compression method for the deflate algorithm (the only one currently supported).

<br />

Constant Value: 8 (0x00000008)

### FILTERED

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

```
public static final int FILTERED
```

Compression strategy best used for data consisting mostly of small values with a somewhat random distribution. Forces more Huffman coding and less string matching.

<br />

Constant Value: 1 (0x00000001)

### FULL_FLUSH

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

```
public static final int FULL_FLUSH
```

Compression flush mode used to flush out all pending output and reset the deflater. Using this mode too often can seriously degrade compression.

<br />

**See also:**

- `https://developer.android.com/reference/java/util/zip/Deflater#deflate(byte[],%20int,%20int,%20int)`

Constant Value: 3 (0x00000003)

### HUFFMAN_ONLY

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

```
public static final int HUFFMAN_ONLY
```

Compression strategy for Huffman coding only.

<br />

Constant Value: 2 (0x00000002)

### NO_COMPRESSION

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

```
public static final int NO_COMPRESSION
```

Compression level for no compression.

<br />

Constant Value: 0 (0x00000000)

### NO_FLUSH

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

```
public static final int NO_FLUSH
```

Compression flush mode used to achieve best compression result.

<br />

**See also:**

- `https://developer.android.com/reference/java/util/zip/Deflater#deflate(byte[],%20int,%20int,%20int)`

Constant Value: 0 (0x00000000)

### SYNC_FLUSH

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

```
public static final int SYNC_FLUSH
```

Compression flush mode used to flush out all pending output; may degrade compression for some compression algorithms.

<br />

**See also:**

- `https://developer.android.com/reference/java/util/zip/Deflater#deflate(byte[],%20int,%20int,%20int)`

Constant Value: 2 (0x00000002)

## Public constructors

### Deflater

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

```
public Deflater ()
```

Creates a new compressor with the default compression level. Compressed data will be generated in ZLIB format.

<br />

### Deflater

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

```
public Deflater (int level)
```

Creates a new compressor using the specified compression level. Compressed data will be generated in ZLIB format.

<br />

| Parameters ||
|---|---|
| `level` | `int`: the compression level (0-9) <br /> |

### Deflater

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

```
public Deflater (int level, 
                boolean nowrap)
```

Creates a new compressor using the specified compression level. If 'nowrap' is true then the ZLIB header and checksum fields will not be used in order to support the compression format used in both GZIP and PKZIP.

<br />

| Parameters ||
|---|---|
| `level` | `int`: the compression level (0-9) <br /> |
| `nowrap` | `boolean`: if true then use GZIP compatible compression <br /> |

## Public methods

### deflate

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

```
public int deflate (byte[] output, 
                int off, 
                int len)
```

Compresses the input data and fills specified buffer with compressed data. Returns actual number of bytes of compressed data. A return value of 0 indicates that `https://developer.android.com/reference/java/util/zip/Deflater#needsInput()` should be called in order to determine if more input data is required.

This method uses `https://developer.android.com/reference/java/util/zip/Deflater#NO_FLUSH` as its compression flush mode. An invocation of this method of the form `deflater.deflate(b, off, len)` yields the same result as the invocation of `deflater.deflate(b, off, len, Deflater.NO_FLUSH)`.

<br />

| Parameters ||
|---|---|
| `output` | `byte`: the buffer for the compressed data <br /> |
| `off` | `int`: the start offset of the data <br /> |
| `len` | `int`: the maximum number of bytes of compressed data <br /> |

| Returns ||
|---|---|
| `int` | the actual number of bytes of compressed data written to the output buffer <br /> |

### deflate

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

```
public int deflate (byte[] output)
```

Compresses the input data and fills specified buffer with compressed data. Returns actual number of bytes of compressed data. A return value of 0 indicates that `https://developer.android.com/reference/java/util/zip/Deflater#needsInput()` should be called in order to determine if more input data is required.

This method uses `https://developer.android.com/reference/java/util/zip/Deflater#NO_FLUSH` as its compression flush mode. An invocation of this method of the form `deflater.deflate(b)` yields the same result as the invocation of `deflater.deflate(b, 0, b.length, Deflater.NO_FLUSH)`.

<br />

| Parameters ||
|---|---|
| `output` | `byte`: the buffer for the compressed data <br /> |

| Returns ||
|---|---|
| `int` | the actual number of bytes of compressed data written to the output buffer <br /> |

### deflate

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

```
public int deflate (byte[] output, 
                int off, 
                int len, 
                int flush)
```

Compresses the input data and fills the specified buffer with compressed data. Returns actual number of bytes of data compressed.

Compression flush mode is one of the following three modes:

- `https://developer.android.com/reference/java/util/zip/Deflater#NO_FLUSH`: allows the deflater to decide how much data to accumulate, before producing output, in order to achieve the best compression (should be used in normal use scenario). A return value of 0 in this flush mode indicates that `https://developer.android.com/reference/java/util/zip/Deflater#needsInput()` should be called in order to determine if more input data is required.
- `https://developer.android.com/reference/java/util/zip/Deflater#SYNC_FLUSH`: all pending output in the deflater is flushed, to the specified output buffer, so that an inflater that works on compressed data can get all input data available so far (In particular the `https://developer.android.com/reference/java/util/zip/Deflater#needsInput()` returns `true` after this invocation if enough output space is provided). Flushing with `https://developer.android.com/reference/java/util/zip/Deflater#SYNC_FLUSH` may degrade compression for some compression algorithms and so it should be used only when necessary.
- `https://developer.android.com/reference/java/util/zip/Deflater#FULL_FLUSH`: all pending output is flushed out as with `https://developer.android.com/reference/java/util/zip/Deflater#SYNC_FLUSH`. The compression state is reset so that the inflater that works on the compressed output data can restart from this point if previous compressed data has been damaged or if random access is desired. Using `https://developer.android.com/reference/java/util/zip/Deflater#FULL_FLUSH` too often can seriously degrade compression.

In the case of `https://developer.android.com/reference/java/util/zip/Deflater#FULL_FLUSH` or `https://developer.android.com/reference/java/util/zip/Deflater#SYNC_FLUSH`, if the return value is `len`, the space available in output buffer `b`, this method should be invoked again with the same `flush` parameter and more output space. Make sure that `len` is greater than 6 to avoid flush marker (5 bytes) being repeatedly output to the output buffer every time this method is invoked.

If the `https://developer.android.com/reference/java/util/zip/Deflater#setInput(java.nio.ByteBuffer)` method was called to provide a buffer for input, the input buffer's position will be advanced by the number of bytes consumed by this operation.

<br />

| Parameters ||
|---|---|
| `output` | `byte`: the buffer for the compressed data <br /> |
| `off` | `int`: the start offset of the data <br /> |
| `len` | `int`: the maximum number of bytes of compressed data <br /> |
| `flush` | `int`: the compression flush mode <br /> |

| Returns ||
|---|---|
| `int` | the actual number of bytes of compressed data written to the output buffer <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the flush mode is invalid |

### deflate

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

```
public int deflate (ByteBuffer output, 
                int flush)
```

Compresses the input data and fills the specified buffer with compressed data. Returns actual number of bytes of data compressed.

Compression flush mode is one of the following three modes:

- `https://developer.android.com/reference/java/util/zip/Deflater#NO_FLUSH`: allows the deflater to decide how much data to accumulate, before producing output, in order to achieve the best compression (should be used in normal use scenario). A return value of 0 in this flush mode indicates that `https://developer.android.com/reference/java/util/zip/Deflater#needsInput()` should be called in order to determine if more input data is required.
- `https://developer.android.com/reference/java/util/zip/Deflater#SYNC_FLUSH`: all pending output in the deflater is flushed, to the specified output buffer, so that an inflater that works on compressed data can get all input data available so far (In particular the `https://developer.android.com/reference/java/util/zip/Deflater#needsInput()` returns `true` after this invocation if enough output space is provided). Flushing with `https://developer.android.com/reference/java/util/zip/Deflater#SYNC_FLUSH` may degrade compression for some compression algorithms and so it should be used only when necessary.
- `https://developer.android.com/reference/java/util/zip/Deflater#FULL_FLUSH`: all pending output is flushed out as with `https://developer.android.com/reference/java/util/zip/Deflater#SYNC_FLUSH`. The compression state is reset so that the inflater that works on the compressed output data can restart from this point if previous compressed data has been damaged or if random access is desired. Using `https://developer.android.com/reference/java/util/zip/Deflater#FULL_FLUSH` too often can seriously degrade compression.

In the case of `https://developer.android.com/reference/java/util/zip/Deflater#FULL_FLUSH` or `https://developer.android.com/reference/java/util/zip/Deflater#SYNC_FLUSH`, if the return value is equal to the [remaining space](https://developer.android.com/reference/java/nio/Buffer#remaining()) of the buffer, this method should be invoked again with the same `flush` parameter and more output space. Make sure that the buffer has at least 6 bytes of remaining space to avoid the flush marker (5 bytes) being repeatedly output to the output buffer every time this method is invoked.

On success, the position of the given `output` byte buffer will be advanced by as many bytes as were produced by the operation, which is equal to the number returned by this method.

If the `https://developer.android.com/reference/java/util/zip/Deflater#setInput(java.nio.ByteBuffer)` method was called to provide a buffer for input, the input buffer's position will be advanced by the number of bytes consumed by this operation.

<br />

| Parameters ||
|---|---|
| `output` | `ByteBuffer`: the buffer for the compressed data <br /> |
| `flush` | `int`: the compression flush mode <br /> |

| Returns ||
|---|---|
| `int` | the actual number of bytes of compressed data written to the output buffer <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the flush mode is invalid |

### deflate

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

```
public int deflate (ByteBuffer output)
```

Compresses the input data and fills specified buffer with compressed data. Returns actual number of bytes of compressed data. A return value of 0 indicates that `https://developer.android.com/reference/java/util/zip/Deflater#needsInput()` should be called in order to determine if more input data is required.

This method uses `https://developer.android.com/reference/java/util/zip/Deflater#NO_FLUSH` as its compression flush mode. An invocation of this method of the form `deflater.deflate(output)` yields the same result as the invocation of `deflater.deflate(output, Deflater.NO_FLUSH)`.

<br />

| Parameters ||
|---|---|
| `output` | `ByteBuffer`: the buffer for the compressed data <br /> |

| Returns ||
|---|---|
| `int` | the actual number of bytes of compressed data written to the output buffer <br /> |

### end

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

```
public void end ()
```

Closes the compressor and discards any unprocessed input. This method should be called when the compressor is no longer being used. Once this method is called, the behavior of the Deflater object is undefined.

<br />

### finish

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

```
public void finish ()
```

When called, indicates that compression should end with the current contents of the input buffer.

<br />

### finished

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

```
public boolean finished ()
```

Returns true if the end of the compressed data output stream has been reached.

<br />

| Returns ||
|---|---|
| `boolean` | true if the end of the compressed data output stream has been reached <br /> |

### getAdler

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

```
public int getAdler ()
```

Returns the ADLER-32 value of the uncompressed data.

<br />

| Returns ||
|---|---|
| `int` | the ADLER-32 value of the uncompressed data <br /> |

### getBytesRead

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

```
public long getBytesRead ()
```

Returns the total number of uncompressed bytes input so far.

<br />

| Returns ||
|---|---|
| `long` | the total (non-negative) number of uncompressed bytes input so far <br /> |

### getBytesWritten

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

```
public long getBytesWritten ()
```

Returns the total number of compressed bytes output so far.

<br />

| Returns ||
|---|---|
| `long` | the total (non-negative) number of compressed bytes output so far <br /> |

### getTotalIn

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

```
public int getTotalIn ()
```

Returns the total number of uncompressed bytes input so far.

Since the number of bytes may be greater than Integer.MAX_VALUE, the `https://developer.android.com/reference/java/util/zip/Deflater#getBytesRead()` method is now the preferred means of obtaining this information.

<br />

<br />

| Returns ||
|---|---|
| `int` | the total number of uncompressed bytes input so far <br /> |

### getTotalOut

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

```
public int getTotalOut ()
```

Returns the total number of compressed bytes output so far.

Since the number of bytes may be greater than Integer.MAX_VALUE, the `https://developer.android.com/reference/java/util/zip/Deflater#getBytesWritten()` method is now the preferred means of obtaining this information.

<br />

<br />

| Returns ||
|---|---|
| `int` | the total number of compressed bytes output so far <br /> |

### needsInput

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

```
public boolean needsInput ()
```

Returns true if no data remains in the input buffer. This can be used to determine if one of the `setInput()` methods should be called in order to provide more input.

<br />

| Returns ||
|---|---|
| `boolean` | true if the input data buffer is empty and setInput() should be called in order to provide more input <br /> |

### reset

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

```
public void reset ()
```

Resets deflater so that a new set of input data can be processed. Keeps current compression level and strategy settings.

<br />

### setDictionary

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

```
public void setDictionary (ByteBuffer dictionary)
```

Sets preset dictionary for compression. A preset dictionary is used when the history buffer can be predetermined. When the data is later uncompressed with Inflater.inflate(), Inflater.getAdler() can be called in order to get the Adler-32 value of the dictionary required for decompression.

The bytes in given byte buffer will be fully consumed by this method. On return, its position will equal its limit.

<br />

| Parameters ||
|---|---|
| `dictionary` | `ByteBuffer`: the dictionary data bytes <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/zip/Inflater#inflate(byte[])`
- `https://developer.android.com/reference/java/util/zip/Inflater#getAdler()`

### setDictionary

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

```
public void setDictionary (byte[] dictionary, 
                int off, 
                int len)
```

Sets preset dictionary for compression. A preset dictionary is used when the history buffer can be predetermined. When the data is later uncompressed with Inflater.inflate(), Inflater.getAdler() can be called in order to get the Adler-32 value of the dictionary required for decompression.

<br />

| Parameters ||
|---|---|
| `dictionary` | `byte`: the dictionary data bytes <br /> |
| `off` | `int`: the start offset of the data <br /> |
| `len` | `int`: the length of the data <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/zip/Inflater#inflate(byte[])`
- `https://developer.android.com/reference/java/util/zip/Inflater#getAdler()`

### setDictionary

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

```
public void setDictionary (byte[] dictionary)
```

Sets preset dictionary for compression. A preset dictionary is used when the history buffer can be predetermined. When the data is later uncompressed with Inflater.inflate(), Inflater.getAdler() can be called in order to get the Adler-32 value of the dictionary required for decompression.

<br />

| Parameters ||
|---|---|
| `dictionary` | `byte`: the dictionary data bytes <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/zip/Inflater#inflate(byte[])`
- `https://developer.android.com/reference/java/util/zip/Inflater#getAdler()`

### setInput

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

```
public void setInput (ByteBuffer input)
```

Sets input data for compression.

One of the `setInput()` methods should be called whenever `needsInput()` returns true indicating that more input data is required.

The given buffer's position will be advanced as deflate operations are performed, up to the buffer's limit. The input buffer may be modified (refilled) between deflate operations; doing so is equivalent to creating a new buffer and setting it with this method.

Modifying the input buffer's contents, position, or limit concurrently with an deflate operation will result in undefined behavior, which may include incorrect operation results or operation failure.

<br />

| Parameters ||
|---|---|
| `input` | `ByteBuffer`: the input data bytes <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/zip/Deflater#needsInput()`

### setInput

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

```
public void setInput (byte[] input, 
                int off, 
                int len)
```

Sets input data for compression.

One of the `setInput()` methods should be called whenever `needsInput()` returns true indicating that more input data is required.

<br />

| Parameters ||
|---|---|
| `input` | `byte`: the input data bytes <br /> |
| `off` | `int`: the start offset of the data <br /> |
| `len` | `int`: the length of the data <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/zip/Deflater#needsInput()`

### setInput

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

```
public void setInput (byte[] input)
```

Sets input data for compression.

One of the `setInput()` methods should be called whenever `needsInput()` returns true indicating that more input data is required.

<br />

| Parameters ||
|---|---|
| `input` | `byte`: the input data bytes <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/zip/Deflater#needsInput()`

### setLevel

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

```
public void setLevel (int level)
```

Sets the compression level to the specified value.

If the compression level is changed, the next invocation of `deflate` will compress the input available so far with the old level (and may be flushed); the new level will take effect only after that invocation.

<br />

| Parameters ||
|---|---|
| `level` | `int`: the new compression level (0-9) <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the compression level is invalid |

### setStrategy

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

```
public void setStrategy (int strategy)
```

Sets the compression strategy to the specified value.

If the compression strategy is changed, the next invocation of `deflate` will compress the input available so far with the old strategy (and may be flushed); the new strategy will take effect only after that invocation.

<br />

| Parameters ||
|---|---|
| `strategy` | `int`: the new compression strategy <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the compression strategy is invalid |