Class InflaterInputStream in Java

digitization, transformation, binary

Class InflaterInputStream in Java

The InflaterInputStream class represents an InputStream with an associated Inflater. In other words, an InflaterInputStream wraps a regular input stream, so that data read from the stream is read from an underlying stream and decompressed. Two subclasses, GZIPInputStream and ZipInputStream, read compressed data in widely recognized formats.

The structure of the class is given by

public class java.util.zip.InflaterInputStream
extends java.io.FilterInputStream {
// Variables
protected byte[] buf;
protected Inflater inf;
protected int len;
// Constructors
public InflaterInputStream(InputStream in);
public InflaterInputStream(InputStream in, Inflater inf);
public InflaterInputStream(InputStream in, Inflater inf, int size);
// Public Instance Methods
public int read();
public int read(byte[] b, int off, int len);
public long skip(long n);
// Protected Instance Methods
protected void fill();
}

The details of the class structure are given as follows:

Ads code goes here
protected byte[] buf;

protected byte[] buf represents a buffer that holds the compressed data that is written to the underlying stream.

protected Inflater inf;

protected Inflater inf represents the Inflater that is used internally.

protected int len;

protected int len represents the amount of data that is in the input buffer.

public InflaterInputStream(InputStream in);

public InflaterInputStream(InputStream in) constructor creates an InflaterInputStream that reads data from the given InputStream. Before being read, the data is decompressed by a default Inflater. The InflaterInputStream uses a decompression buffer with the default size of 512 bytes.

Parameter
in –  The underlying input stream.

public InflaterInputStream(InputStream in, Inflater inf);

public InflaterInputStream(InputStream in, Inflater inf) method constructor creates an InflaterInputStream that reads data from the given InputStream. Before being read, the data is decompressed by the given Inflater. The InflaterInputStream uses a decompression buffer with the default size of 512 bytes.

READ  Class InvocationTargetException in java

Parameter
in – The underlying input stream.
inf – The Inflater object.

public InflaterInputStream(InputStream in, Inflater inf, int size);

public InflaterInputStream(InputStream in, Inflater inf, int size) constructor creates an InflaterInputStream that reads data from the given InputStream. Before being read, the data is decompressed by the given Inflater. The
InflaterInputStream uses a decompression buffer of the given size.

Parameter
in – The underlying input stream.
inf – The Inflater object.
size -The size of the input buffer.

public int read();

public int read() method reads enough data from the underlying InputStream to return a byte of uncompressed data. The method blocks until enough data is available for decompression, the end of the stream is detected, or an exception is thrown.

This method returns the next uncompressed byte or -1 if the end of the stream is encountered.

public int read(byte[] b, int off, int len);

public int read(byte[] b, int off, int len) method reads enough data from the underlying InputStream to return len bytes of uncompressed data. The uncompressed data is placed into the given array starting at off. The method blocks until some data are available for decompression.

This method returns the number of bytes read or -1 if the end of the stream is encountered immediately.

Parameter
b – An array of bytes to be filled from the stream.
off – An offset into the byte array.
len – The number of bytes to read.

public long skip(long n);

public long skip(long n) method skips over the specified number of uncompressed data bytes by reading data from the
underlying InputStream and decompressing it.

READ  Class Random in Java

This method returns the actual number of bytes skipped.

protected void fill();

protected void fill() method fills the input buffer with compressed data from the underlying InputStream.

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

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

InflaterInputStream class also has inherited methods from FilterInputStream. They are as follows:

  • available()
  • close()
  • markSupported()
  • read(byte[])
  • mark(int)
  • reset()

InflaterInputStream class also has inherited a method from InflaterInputStream. That is as follows:

  • read()

Share and Enjoy !

Leave a Comment

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