Spread the love

Class Inflater in Java

Spread the love

Class Inflater in Java

The Inflater class provides support for general-purpose data decompression. The class uses the ZLIB compression algorithms described in RFC 1950, RFC 1951, and RFC 1952.

The Deflater class compresses data that can be uncompressed using Inflater.

The InflaterInputStream uses an internal Inflater to decompress data. Typically, ee do not need to create an Inflater; instead, we can just use an instance of one of the subclasses of InflaterInputStream: GZIPInputStream or ZipInputStream.

The structure of the class Inflater is given by

public class java.util.zip.Inflater extends java.lang.Object {
// Constructors
public Inflater();
public Inflater(boolean nowrap);
// Public Instance Methods
public synchronized native void end();
public synchronized boolean finished();
public synchronized native int getAdler();
public synchronized int getRemaining();
public synchronized native int getTotalIn();
public synchronized native int getTotalOut();
public int inflate(byte[] b);
public synchronized native int inflate(byte[] b, int off, int len);
public synchronized boolean needsDictionary();
public synchronized boolean needsInput();
public synchronized native void reset();
public void setDictionary(byte[] b);
public synchronized native void setDictionary(byte[] b, int off, int len);
public void setInput(byte[] b);
public synchronized void setInput(byte[] b, int off, int len);
// Protected Instance Methods
protected void finalize();
}

The details of the class structure are given as follows:

public Inflater();

public Inflater() constructor creates an Inflater that decompresses data in the ZLIB format.

public Inflater(boolean nowrap);

public Inflater(boolean nowrap) constructor creates an Inflater that decompresses data. If nowrap is true, the ZLIB header and checksum fields are not expected, which means that the compressed data is in the format used by GZIP and PKZIP. If the parameter is false, the data is decompressed in the ZLIB format.

Parameter
nowrap – A boolean value that specifies whether or not the ZLIB header and checksum data are expected in the compressed data.

public synchronized native void end();

public synchronized native void end() method discards any unprocessed input data and frees up internal buffers.

public synchronized boolean finished();

public synchronized boolean finished() method returns true if the last of the compressed data has been read using inflate(). Otherwise, it returns false.

READ  How To Write A Function That Will Read Data From Excel Using POI Jar
READ  Learn Abstract Class in Java in a Simple and Fast Manner

This method returns a boolean value that indicates whether or not the end of the compressed data has been reached.

public synchronized native int getAdler();

public synchronized native int getAdler() method returns an Adler32 checksum value that is calculated from the uncompressed data returned by inflate().

This method returns the Adler32 checksum value of the uncompressed data.

public synchronized int getRemaining();

public synchronized int getRemaining() method returns the number of bytes that are in the input buffer. It can be called to find out how much data remains after a call to inflate().

This method returns the number of bytes remaining in the input buffer.

public synchronized native int getTotalIn();

public synchronized native int getTotalIn() method returns the number of bytes that have been passed to setInput() since this Inflater was created or since reset() was last called.

This method returns the total number of bytes that have been input so far.

public synchronized native int getTotalOut();

public synchronized native int getTotalOut() method returns the number of bytes that have been read from inflate() since this Inflater was created or since reset() was last called.

This method returns the total number of bytes that have been output so far.

public int inflate(byte[] b);

public int inflate(byte[] b) method decompresses the data passed to setInput() and fills the given array with decompressed data. If this method returns 0, needsInput() and needsDictionary() should be called in order to determine whether the Inflater needs more data in its input buffer or whether it needs a preset dictionary.

READ  Class StringBuffer in Java

This method returns the number of decompressed bytes actually written to the array or 0 if more data may be required.

Parameter
b – A byte array to be filled.

public synchronized native int inflate(byte[] b, int off, int len);

public synchronized native int inflate(byte[] b, int off, int len) method decompresses the data passed to setInput() and writes len bytes of the decompressed data into the given array, starting at off. If this method returns 0, needsInput() and needsDictionary() should be called in order to determine whether the Inflater needs more data in its input buffer or whether it needs a preset dictionary.

This method returns the number of decompressed bytes written to the array or 0 if more data may be required.

READ  Abstract Interface DataOutput in Java

Parameter
b – A byte array to be filled.
off – An offset into the byte array.
len – The number of bytes to fill.

public synchronized boolean needsDictionary();

public synchronized boolean needsDictionary() method returns true if a preset dictionary is needed for decompression. Otherwise, it returns false.

This method returns a boolean value that indicates whether or not a preset dictionary is needed.

public synchronized boolean needsInput();

public synchronized boolean needsInput() method returns true if the input buffer is empty. Otherwise, it returns false.

This method returns a boolean value that indicates whether or not the input buffer is empty.

public synchronized native void reset();

public synchronized native void reset() method resets the Inflater to the state it was in when it was created, which means that a new set of data can be decompressed.

public void setDictionary(byte[] b);

public void setDictionary(byte[] b) method sets the preset dictionary for decompression using the data in the given array.

READ  Deflater class in Java

Parameter
b – An array of byte values.

public synchronized native void setDictionary(byte[] b, int off, int len);

public synchronized native void setDictionary(byte[] b, int off, int len) method sets the preset dictionary for decompression using len bytes from the given array, starting from off.

Parameter
b – An array of byte values.
off – An offset into the byte array.
len – The number of bytes to use.

public void setInput(byte[] b);

public void setInput(byte[] b) method places the contents of the given array into the input buffer of this Inflater.

Parameter
b – An array of byte values.

public synchronized void setInput(byte[] b, int off, int len);

public synchronized void setInput(byte[] b, int off, int len) method places len bytes from the given array, starting at off, into the input buffer of this Inflater. Use the inflate() method to decompress the data and retrieve it in decompressed form.

Parameter
b – An array of byte values.
off – An offset into the byte array.
len – The number of bytes to use.

protected void finalize();

protected void finalize() method calls end() when this Inflater is garbage collected.

Apart from these Inflater class also has inherited methods from class- Object. They are as follows:

  • clone()
  • hashCode()
  • notifyAll()
  • wait()
  • wait(long, int)
  • equals(Object)
  • getClass()
  • notify()
  • toString()
  • wait(long)




Spread the love
READ  Class NoSuchElementException in Java
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Super Keyword in Java Simplified

Super Keyword Super Keyword in Java Simplified: Java defines a special keyword called...

Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Super Keyword in Java Simplified

Super Keyword Super Keyword in Java Simplified: Java defines a special...

Learn Object Repository in UFT in An Efficient and Fast Manner

Object Repository in UFT The post will cover the following...

Learn What Primary Tools For Test Automation

Primary Tools For Test Automation According to the Gartner report...

EDITOR PICKS


Spread the love