joeq.ClassLib.Common.java.util.zip
Class Inflater

java.lang.Object
  extended by joeq.ClassLib.Common.java.util.zip.Inflater

public class Inflater
extends Object

Inflater

Version:
$Id: Inflater.java,v 1.12 2004/04/28 17:34:45 joewhaley Exp $
Author:
John Whaley

Constructor Summary
Inflater()
          Creates a new inflater.
Inflater(boolean nowrap)
          Creates a new inflater.
 
Method Summary
 void __init__(boolean nowrap)
           
 void end()
          Deprecated. Just clear all references to inflater instead.
protected  void finalize()
          Finalizes this object.
 boolean finished()
          Returns true, if the inflater has finished.
 int getAdler()
          Gets the adler checksum.
 int getRemaining()
          Gets the number of unprocessed input.
 int getTotalIn()
          Gets the total number of processed compressed input bytes.
 int getTotalOut()
          Gets the total number of output bytes returned by inflate().
 int inflate(byte[] buf)
          Inflates the compressed stream to the output buffer.
 int inflate(byte[] buf, int off, int len)
          Inflates the compressed stream to the output buffer.
 boolean needsDictionary()
          Returns true, if a preset dictionary is needed to inflate the input.
 boolean needsInput()
          Returns true, if the input buffer is empty.
 void reset()
          Resets the inflater so that a new stream can be decompressed.
 void setDictionary(byte[] buffer)
          Sets the preset dictionary.
 void setDictionary(byte[] buffer, int off, int len)
          Sets the preset dictionary.
 void setInput(byte[] buf)
          Sets the input.
 void setInput(byte[] buf, int off, int len)
          Sets the input.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Inflater

public Inflater()
Creates a new inflater.


Inflater

public Inflater(boolean nowrap)
Creates a new inflater.

Parameters:
nowrap - true if no header and checksum field appears in the stream. This is used for GZIPed input. For compatibility with Sun JDK you should provide one byte of input more than needed in this case.
Method Detail

__init__

public void __init__(boolean nowrap)

reset

public void reset()
Resets the inflater so that a new stream can be decompressed. All pending input and output will be discarded.


setDictionary

public void setDictionary(byte[] buffer)
Sets the preset dictionary. This should only be called, if needsDictionary() returns true and it should set the same dictionary, that was used for deflating. The getAdler() function returns the checksum of the dictionary needed.

Parameters:
buffer - the dictionary.
Throws:
IllegalStateException - if no dictionary is needed.
IllegalArgumentException - if the dictionary checksum is wrong.

setDictionary

public void setDictionary(byte[] buffer,
                          int off,
                          int len)
Sets the preset dictionary. This should only be called, if needsDictionary() returns true and it should set the same dictionary, that was used for deflating. The getAdler() function returns the checksum of the dictionary needed.

Parameters:
buffer - the dictionary.
off - the offset into buffer where the dictionary starts.
len - the length of the dictionary.
Throws:
IllegalStateException - if no dictionary is needed.
IllegalArgumentException - if the dictionary checksum is wrong.
IndexOutOfBoundsException - if the off and/or len are wrong.

setInput

public void setInput(byte[] buf)
Sets the input. This should only be called, if needsInput() returns true.

Parameters:
buf - the input.
Throws:
IllegalStateException - if no input is needed.

setInput

public void setInput(byte[] buf,
                     int off,
                     int len)
Sets the input. This should only be called, if needsInput() returns true.

Parameters:
buf - the input.
off - the offset into buffer where the input starts.
len - the length of the input.
Throws:
IllegalStateException - if no input is needed.
IndexOutOfBoundsException - if the off and/or len are wrong.

inflate

public int inflate(byte[] buf)
            throws DataFormatException
Inflates the compressed stream to the output buffer. If this returns 0, you should check, whether needsDictionary(), needsInput() or finished() returns true, to determine why no further output is produced.

Parameters:
buf - the output buffer.
Returns:
the number of bytes written to the buffer, 0 if no further output can be produced.
Throws:
DataFormatException - if deflated stream is invalid.
IllegalArgumentException - if buf has length 0.

inflate

public int inflate(byte[] buf,
                   int off,
                   int len)
            throws DataFormatException
Inflates the compressed stream to the output buffer. If this returns 0, you should check, whether needsDictionary(), needsInput() or finished() returns true, to determine why no further output is produced.

Parameters:
buf - the output buffer.
off - the offset into buffer where the output should start.
len - the maximum length of the output.
Returns:
the number of bytes written to the buffer, 0 if no further output can be produced.
Throws:
DataFormatException - if deflated stream is invalid.
IndexOutOfBoundsException - if the off and/or len are wrong.

needsInput

public boolean needsInput()
Returns true, if the input buffer is empty. You should then call setInput().
NOTE: This method also returns true when the stream is finished.


needsDictionary

public boolean needsDictionary()
Returns true, if a preset dictionary is needed to inflate the input.


finished

public boolean finished()
Returns true, if the inflater has finished. This means, that no input is needed and no output can be produced.


getAdler

public int getAdler()
Gets the adler checksum. This is either the checksum of all uncompressed bytes returned by inflate(), or if needsDictionary() returns true (and thus no output was yet produced) this is the adler checksum of the expected dictionary.

Returns:
the adler checksum.

getTotalOut

public int getTotalOut()
Gets the total number of output bytes returned by inflate().

Returns:
the total number of output bytes.

getTotalIn

public int getTotalIn()
Gets the total number of processed compressed input bytes.

Returns:
the total number of bytes of processed input bytes.

getRemaining

public int getRemaining()
Gets the number of unprocessed input. Useful, if the end of the stream is reached and you want to further process the bytes after the deflate stream.

Returns:
the number of bytes of the input which were not processed.

end

public void end()
Deprecated. Just clear all references to inflater instead.

Frees all objects allocated by the inflater. There's no reason to call this, since you can just rely on garbage collection (even for the Sun implementation). Exists only for compatibility with Sun's JDK, where the compressor allocates native memory. If you call any method (even reset) afterwards the behaviour is undefined.


finalize

protected void finalize()
                 throws Throwable
Finalizes this object.

Overrides:
finalize in class Object
Throws:
Throwable


Copyright © 2001-2005 John Whaley. All Rights Reserved.