Package net.sf.jazzlib
Class Inflater
- java.lang.Object
-
- net.sf.jazzlib.Inflater
-
public class Inflater extends java.lang.ObjectInflater is used to decompress data that has been compressed according to the "deflate" standard described in rfc1950. The usage is as following. First you have to set some input withsetInput(), then inflate() it. If inflate doesn't inflate any bytes there may be three reasons:- needsInput() returns true because the input buffer is empty. You have to
provide more input with
setInput(). NOTE: needsInput() also returns true when, the stream is finished. - needsDictionary() returns true, you have to provide a preset dictionary
with
setDictionary(). - finished() returns true, the inflater has finished.
- Since:
- JDK 1.1
- needsInput() returns true because the input buffer is empty. You have to
provide more input with
-
-
Field Summary
Fields Modifier and Type Field Description private Adler32adlerprivate static int[]CPDEXTprivate static int[]CPDISTprivate static int[]CPLENSprivate static int[]CPLEXTprivate static intDECODE_BLOCKSprivate static intDECODE_CHKSUMprivate static intDECODE_DICTprivate static intDECODE_DYN_HEADERprivate static intDECODE_HEADERprivate static intDECODE_HUFFMANprivate static intDECODE_HUFFMAN_DISTprivate static intDECODE_HUFFMAN_DISTBITSprivate static intDECODE_HUFFMAN_LENBITSprivate static intDECODE_STOREDprivate static intDECODE_STORED_LEN1private static intDECODE_STORED_LEN2private InflaterHuffmanTreedistTreeprivate InflaterDynHeaderdynHeaderprivate static intFINISHEDprivate StreamManipulatorinputprivate booleanisLastBlockTrue, if the last block flag was set in the last block of the inflated stream.private InflaterHuffmanTreelitlenTreeprivate intmodeThis variable contains the current state.private intneededBitsThe number of bits needed to complete the current state.private booleannowrapThis variable stores the nowrap flag that was given to the constructor.private OutputWindowoutputWindowprivate intreadAdlerThe adler checksum of the dictionary or of the decompressed stream, as it is written in the header resp.private intrepDistprivate intrepLengthprivate inttotalInThe total number of bytes set with setInput().private inttotalOutThe total number of inflated bytes.private intuncomprLen
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private booleandecode()Decodes the deflated stream.private booleandecodeChksum()Decodes the adler checksum after the deflate stream.private booleandecodeDict()Decodes the dictionary checksum after the deflate header.private booleandecodeHeader()Decodes the deflate header.private booleandecodeHuffman()Decodes the huffman encoded symbols in the input stream.voidend()Deprecated.Just clear all references to inflater instead.protected voidfinalize()Finalizes this object.booleanfinished()Returns true, if the inflater has finished.intgetAdler()Gets the adler checksum.intgetRemaining()Gets the number of unprocessed input.intgetTotalIn()Gets the total number of processed compressed input bytes.intgetTotalOut()Gets the total number of output bytes returned by inflate().intinflate(byte[] buf)Inflates the compressed stream to the output buffer.intinflate(byte[] buf, int off, int len)Inflates the compressed stream to the output buffer.booleanneedsDictionary()Returns true, if a preset dictionary is needed to inflate the input.booleanneedsInput()Returns true, if the input buffer is empty.voidreset()Resets the inflater so that a new stream can be decompressed.voidsetDictionary(byte[] buffer)Sets the preset dictionary.voidsetDictionary(byte[] buffer, int off, int len)Sets the preset dictionary.voidsetInput(byte[] buf)Sets the input.voidsetInput(byte[] buf, int off, int len)Sets the input.
-
-
-
Field Detail
-
CPLENS
private static final int[] CPLENS
-
CPLEXT
private static final int[] CPLEXT
-
CPDIST
private static final int[] CPDIST
-
CPDEXT
private static final int[] CPDEXT
-
DECODE_HEADER
private static final int DECODE_HEADER
- See Also:
- Constant Field Values
-
DECODE_DICT
private static final int DECODE_DICT
- See Also:
- Constant Field Values
-
DECODE_BLOCKS
private static final int DECODE_BLOCKS
- See Also:
- Constant Field Values
-
DECODE_STORED_LEN1
private static final int DECODE_STORED_LEN1
- See Also:
- Constant Field Values
-
DECODE_STORED_LEN2
private static final int DECODE_STORED_LEN2
- See Also:
- Constant Field Values
-
DECODE_STORED
private static final int DECODE_STORED
- See Also:
- Constant Field Values
-
DECODE_DYN_HEADER
private static final int DECODE_DYN_HEADER
- See Also:
- Constant Field Values
-
DECODE_HUFFMAN
private static final int DECODE_HUFFMAN
- See Also:
- Constant Field Values
-
DECODE_HUFFMAN_LENBITS
private static final int DECODE_HUFFMAN_LENBITS
- See Also:
- Constant Field Values
-
DECODE_HUFFMAN_DIST
private static final int DECODE_HUFFMAN_DIST
- See Also:
- Constant Field Values
-
DECODE_HUFFMAN_DISTBITS
private static final int DECODE_HUFFMAN_DISTBITS
- See Also:
- Constant Field Values
-
DECODE_CHKSUM
private static final int DECODE_CHKSUM
- See Also:
- Constant Field Values
-
FINISHED
private static final int FINISHED
- See Also:
- Constant Field Values
-
mode
private int mode
This variable contains the current state.
-
readAdler
private int readAdler
The adler checksum of the dictionary or of the decompressed stream, as it is written in the header resp. footer of the compressed stream.
Only valid if mode is DECODE_DICT or DECODE_CHKSUM.
-
neededBits
private int neededBits
The number of bits needed to complete the current state. This is valid, if mode is DECODE_DICT, DECODE_CHKSUM, DECODE_HUFFMAN_LENBITS or DECODE_HUFFMAN_DISTBITS.
-
repLength
private int repLength
-
repDist
private int repDist
-
uncomprLen
private int uncomprLen
-
isLastBlock
private boolean isLastBlock
True, if the last block flag was set in the last block of the inflated stream. This means that the stream ends after the current block.
-
totalOut
private int totalOut
The total number of inflated bytes.
-
totalIn
private int totalIn
The total number of bytes set with setInput(). This is not the value returned by getTotalIn(), since this also includes the unprocessed input.
-
nowrap
private final boolean nowrap
This variable stores the nowrap flag that was given to the constructor. True means, that the inflated stream doesn't contain a header nor the checksum in the footer.
-
input
private StreamManipulator input
-
outputWindow
private OutputWindow outputWindow
-
dynHeader
private InflaterDynHeader dynHeader
-
litlenTree
private InflaterHuffmanTree litlenTree
-
distTree
private InflaterHuffmanTree distTree
-
adler
private Adler32 adler
-
-
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
-
finalize
protected void finalize()
Finalizes this object.- Overrides:
finalizein classjava.lang.Object
-
end
@Deprecated 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.
-
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.
-
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.
-
getTotalIn
public int getTotalIn()
Gets the total number of processed compressed input bytes.- Returns:
- the total number of bytes of processed input bytes.
-
getTotalOut
public int getTotalOut()
Gets the total number of output bytes returned by inflate().- Returns:
- the total number of output bytes.
-
inflate
public int inflate(byte[] buf) throws DataFormatExceptionInflates 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:
buffer- 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.java.lang.IllegalArgumentException- if buf has length 0.
-
inflate
public int inflate(byte[] buf, int off, int len) throws DataFormatExceptionInflates 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:
buffer- 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.java.lang.IndexOutOfBoundsException- if the off and/or len are wrong.
-
needsDictionary
public boolean needsDictionary()
Returns true, if a preset dictionary is needed to inflate the input.
-
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.
-
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:
java.lang.IllegalStateException- if no dictionary is needed.java.lang.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:
java.lang.IllegalStateException- if no dictionary is needed.java.lang.IllegalArgumentException- if the dictionary checksum is wrong.java.lang.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:
buffer- the input.- Throws:
java.lang.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:
buffer- the input.off- the offset into buffer where the input starts.len- the length of the input.- Throws:
java.lang.IllegalStateException- if no input is needed.java.lang.IndexOutOfBoundsException- if the off and/or len are wrong.
-
decodeHeader
private boolean decodeHeader() throws DataFormatExceptionDecodes the deflate header.- Returns:
- false if more input is needed.
- Throws:
DataFormatException- if header is invalid.
-
decodeDict
private boolean decodeDict()
Decodes the dictionary checksum after the deflate header.- Returns:
- false if more input is needed.
-
decodeHuffman
private boolean decodeHuffman() throws DataFormatExceptionDecodes the huffman encoded symbols in the input stream.- Returns:
- false if more input is needed, true if output window is full or the current block ends.
- Throws:
DataFormatException- if deflated stream is invalid.
-
decodeChksum
private boolean decodeChksum() throws DataFormatExceptionDecodes the adler checksum after the deflate stream.- Returns:
- false if more input is needed.
- Throws:
DataFormatException- if checksum doesn't match.
-
decode
private boolean decode() throws DataFormatExceptionDecodes the deflated stream.- Returns:
- false if more input is needed, or if finished.
- Throws:
DataFormatException- if deflated stream is invalid.
-
-