java.util.zip - Deflater Class


Advertisements

Introduction

The java.util.zip.Deflater 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.

Class declaration

Following is the declaration for java.util.zip.Deflater class −

public class Deflater
   extends Object

Fields

Following are the fields for java.util.zip.Deflater class −

  • static int BEST_COMPRESSION − Compression level for best compression.

  • static int BEST_SPEED − Compression level for fastest compression.

  • static int DEFAULT_COMPRESSION − Default compression level.

  • static int DEFAULT_STRATEGY − Default compression strategy.

  • static int DEFLATED − Compression method for the deflate algorithm (the only one currently supported).

  • static int FILTERED − Compression strategy best used for data consisting mostly of small values with a somewhat random distribution.

  • static int FULL_FLUSH − Compression flush mode used to flush out all pending output and reset the deflater.

  • static int HUFFMAN_ONLY − Compression strategy for Huffman coding only.

  • static int NO_COMPRESSION − Compression level for no compression.

  • static int NO_FLUSH − Compression flush mode used to achieve best compression result.

  • static int SYNC_FLUSH − Compression flush mode used to flush out all pending output; may degrade compression for some compression algorithms.

Constructors

Sr.No. Constructor & Description
1

Deflater()

Creates a new compressor with the default compression level.

2

Deflater(int level)

Creates a new compressor using the specified compression level.

3

Deflater(int level, boolean nowrap)

Creates a new compressor using the specified compression level.

Class methods

Sr.No. Method & Description
1 int deflate(byte[] b)

Compresses the input data and fills specified buffer with compressed data.

2 int deflate(byte[] b, int off, int len)

Compresses the input data and fills specified buffer with compressed data.

3 int deflate(byte[] b, int off, int len, int flush)

Compresses the input data and fills the specified buffer with compressed data.

4 void end()

Closes the compressor and discards any unprocessed input.

5 void finish()

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

6 boolean finished()

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

7 int getAdler()

Returns the ADLER-32 value of the uncompressed data.

8 long getBytesRead()

Returns the total number of uncompressed bytes input so far.

9 long getBytesWritten()

Returns the total number of compressed bytes output so far.

10 int getTotalIn()

Returns the total number of uncompressed bytes input so far.

11 int getTotalOut()

Returns the total number of compressed bytes output so far.

12 boolean needsInput()

Returns true if the input data buffer is empty and setInput() should be called in order to provide more input.

13 void reset()

Resets deflater so that a new set of input data can be processed.

14 void setDictionary(byte[] b)

Sets preset dictionary for compression.

15 void setDictionary(byte[] b, int off, int len)

Sets preset dictionary for compression.

16 void setInput(byte[] b)

Sets input data for compression.

17 void setInput(byte[] b, int off, int len)

Sets input data for compression.

18 void setLevel(int level)

Sets the current compression level to the specified value.

19 void setStrategy(int strategy)

Sets the compression strategy to the specified value.

Methods inherited

This class inherits methods from the following classes −

  • java.lang.Object
Print