public class

Inflater

extends Object
java.lang.Object
   ↳ java.util.zip.Inflater

Class Overview

This class uncompresses data that was compressed using the DEFLATE algorithm (see specification).

Basically this class is part of the API to the stream based ZLIB compression library and is used as such by InflaterInputStream and its descendants.

The typical usage of a Inflater outside this package consists of a specific call to one of its constructors before being passed to an instance of InflaterInputStream.

Summary

Public Constructors
Inflater()
This constructor creates an inflater that expects a header from the input stream.
Inflater(boolean noHeader)
This constructor allows to create an inflater that expects no header from the input stream.
Public Methods
synchronized void end()
Release any resources associated with this Inflater.
synchronized boolean finished()
Indicates if the Inflater has inflated the entire deflated stream.
synchronized int getAdler()
Returns the Adler32 checksum of either all bytes inflated, or the checksum of the preset dictionary if one has been supplied.
synchronized long getBytesRead()
Returns the total number of bytes read by the Inflater.
synchronized long getBytesWritten()
Returns a the total number of bytes read by the Inflater.
synchronized int getRemaining()
Returns the number of bytes of current input remaining to be read by the inflater.
synchronized int getTotalIn()
Returns total number of bytes of input read by the Inflater.
synchronized int getTotalOut()
Returns total number of bytes written to the output buffer by the Inflater.
int inflate(byte[] buf)
Inflates bytes from current input and stores them in buf.
synchronized int inflate(byte[] buf, int off, int nbytes)
Inflates up to n bytes from the current input and stores them in buf starting at off.
synchronized boolean needsDictionary()
Indicates whether the input bytes were compressed with a preset dictionary.
synchronized boolean needsInput()
Indicates that input has to be passed to the inflater.
synchronized void reset()
Resets the Inflater.
synchronized void setDictionary(byte[] buf, int off, int nbytes)
Like setDictionary(byte[]), allowing to define a specific region inside buf to be used as a dictionary.
synchronized void setDictionary(byte[] buf)
Sets the preset dictionary to be used for inflation to buf.
synchronized void setInput(byte[] buf, int off, int nbytes)
Sets the current input to the region of the input buffer starting at off and ending at nbytes - 1 where data is written after decompression.
synchronized void setInput(byte[] buf)
Sets the current input to to be decrompressed.
Protected Methods
void finalize()
Is called before the object's memory is being reclaimed by the VM.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Inflater ()

This constructor creates an inflater that expects a header from the input stream. Use Inflater(boolean) if the input comes without a ZLIB header.

public Inflater (boolean noHeader)

This constructor allows to create an inflater that expects no header from the input stream.

Parameters
noHeader true indicates that no ZLIB header comes with the input.

Public Methods

public synchronized void end ()

Release any resources associated with this Inflater. Any unused input/output is discarded. This is also called by the finalize method.

public synchronized boolean finished ()

Indicates if the Inflater has inflated the entire deflated stream. If deflated bytes remain and needsInput() returns true this method will return false. This method should be called after all deflated input is supplied to the Inflater.

Returns
  • true if all input has been inflated, false otherwise.

public synchronized int getAdler ()

Returns the Adler32 checksum of either all bytes inflated, or the checksum of the preset dictionary if one has been supplied.

Returns
  • The Adler32 checksum associated with this Inflater.

public synchronized long getBytesRead ()

Returns the total number of bytes read by the Inflater. This method performs the same as getTotalIn() except that it returns a long value instead of an integer.

Returns
  • the total number of bytes read.

public synchronized long getBytesWritten ()

Returns a the total number of bytes read by the Inflater. This method performs the same as getTotalOut except it returns a long value instead of an integer.

Returns
  • the total bytes written to the output buffer.

public synchronized int getRemaining ()

Returns the number of bytes of current input remaining to be read by the inflater.

Returns
  • the number of bytes of unread input.

public synchronized int getTotalIn ()

Returns total number of bytes of input read by the Inflater. The result value is limited by Integer.MAX_VALUE.

Returns
  • the total number of bytes read.

public synchronized int getTotalOut ()

Returns total number of bytes written to the output buffer by the Inflater. The result value is limited by Integer.MAX_VALUE.

Returns
  • the total bytes of output data written.

public int inflate (byte[] buf)

Inflates bytes from current input and stores them in buf.

Parameters
buf the buffer where decompressed data bytes are written.
Returns
  • the number of bytes inflated.
Throws
DataFormatException if the underlying stream is corrupted or was not compressed using a Deflater.

public synchronized int inflate (byte[] buf, int off, int nbytes)

Inflates up to n bytes from the current input and stores them in buf starting at off.

Parameters
buf the buffer to write inflated bytes to.
off the offset in buffer where to start writing decompressed data.
nbytes the number of inflated bytes to write to buf.
Returns
  • the number of bytes inflated.
Throws
DataFormatException if the underlying stream is corrupted or was not compressed using a Deflater.

public synchronized boolean needsDictionary ()

Indicates whether the input bytes were compressed with a preset dictionary. This method should be called prior to inflate() to determine whether a dictionary is required. If so setDictionary() should be called with the appropriate dictionary prior to calling inflate().

Returns
  • true if a preset dictionary is required for inflation.

public synchronized boolean needsInput ()

Indicates that input has to be passed to the inflater.

Returns
  • true if setInput has to be called before inflation can proceed.
See Also

public synchronized void reset ()

Resets the Inflater. Should be called prior to inflating a new set of data.

public synchronized void setDictionary (byte[] buf, int off, int nbytes)

Like setDictionary(byte[]), allowing to define a specific region inside buf to be used as a dictionary.

Parameters
buf the buffer containing the dictionary data bytes.
off the offset of the data.
nbytes the length of the data.

public synchronized void setDictionary (byte[] buf)

Sets the preset dictionary to be used for inflation to buf. needsDictionary() can be called to determine whether the current input was deflated using a preset dictionary.

Parameters
buf The buffer containing the dictionary bytes.

public synchronized void setInput (byte[] buf, int off, int nbytes)

Sets the current input to the region of the input buffer starting at off and ending at nbytes - 1 where data is written after decompression. This method should only be called if needsInput() returns true.

Parameters
buf the input buffer.
off the offset to read from the input buffer.
nbytes the number of bytes to read.
See Also

public synchronized void setInput (byte[] buf)

Sets the current input to to be decrompressed. This method should only be called if needsInput() returns true.

Parameters
buf the input buffer.
See Also

Protected Methods

protected void finalize ()

Is called before the object's memory is being reclaimed by the VM. This can only happen once the VM has detected, during a run of the garbage collector, that the object is no longer reachable by any thread of the running application.

The method can be used to free system resources or perform other cleanup before the object is garbage collected. The default implementation of the method is empty, which is also expected by the VM, but subclasses can override finalize() as required. Uncaught exceptions which are thrown during the execution of this method cause it to terminate immediately but are otherwise ignored.

Note that the VM does guarantee that finalize() is called at most once for any object, but it doesn't guarantee when (if at all) finalize() will be called. For example, object B's finalize() can delay the execution of object A's finalize() method and therefore it can delay the reclamation of A's memory. To be safe, use a ReferenceQueue, because it provides more control over the way the VM deals with references during garbage collection.