Deflater 

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 −

publicclassDeflaterextendsObject

Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

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
1Deflater()Creates a new compressor with the default compression level.
2Deflater(int level)Creates a new compressor using the specified compression level.
3Deflater(int level, boolean nowrap)Creates a new compressor using the specified compression level.

Class Methods

Sr.No.Method & Description
1int deflate(byte[] b)Compresses the input data and fills specified buffer with compressed data.
2int deflate(byte[] b, int off, int len)Compresses the input data and fills specified buffer with compressed data.
3int deflate(byte[] b, int off, int len, int flush)Compresses the input data and fills the specified buffer with compressed data.
4void end()Closes the compressor and discards any unprocessed input.
5void finish()When called, indicates that compression should end with the current contents of the input buffer.
6boolean finished()Returns true if the end of the compressed data output stream has been reached.
7int getAdler()Returns the ADLER-32 value of the uncompressed data.
8long getBytesRead()Returns the total number of uncompressed bytes input so far.
9long getBytesWritten()Returns the total number of compressed bytes output so far.
10int getTotalIn()Returns the total number of uncompressed bytes input so far.
11int getTotalOut()Returns the total number of compressed bytes output so far.
12boolean needsInput()Returns true if the input data buffer is empty and setInput() should be called in order to provide more input.
13void reset()Resets deflater so that a new set of input data can be processed.
14void setDictionary(byte[] b)Sets preset dictionary for compression.
15void setDictionary(byte[] b, int off, int len)Sets preset dictionary for compression.
16void setInput(byte[] b)Sets input data for compression.
17void setInput(byte[] b, int off, int len)Sets input data for compression.
18void setLevel(int level)Sets the current compression level to the specified value.
19void setStrategy(int strategy)Sets the compression strategy to the specified value.

Methods Inherited

This class inherits methods from the following classes −

  • java.lang.Object

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *