org.bolet.jgz
Class Inflater

java.lang.Object
  extended by org.bolet.jgz.Inflater

public final class Inflater
extends java.lang.Object

An Inflater instance handles the transformation of compressed data bytes, read from a user-specified stream, into the corresponding uncompressed data bytes.

The engine can be reset at any time, and work over various stream instances. Deflated data is organized into successive blocks, the last block being marked as such. This class is not adequate for asynchronous non-blocking decompression: when a read request is issued, it will wait for incoming compressed data bytes until the end of the current block, as long as the provided output buffer is large enough.


Constructor Summary
Inflater()
          Create a new engine.
 
Method Summary
 boolean nextBlock()
          Get the next block header.
 void processDictionary(byte[] dict)
          Process a dictionary.
 void processDictionary(byte[] dict, int off, int len)
          Process a dictionary.
 void processDictionary(java.io.InputStream dict)
          Process a dictionary.
 int readAll(byte[] buf, int off, int len)
          Uncompress some data.
 int readBlock(byte[] buf, int off, int len)
          Uncompress some data from the current block.
 void reset(java.io.InputStream in)
          Reset the engine, to work over the provided stream.
 void setRawStream(java.io.InputStream in)
          Change the input stream, but keep the running state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Inflater

public Inflater()
Create a new engine.

Method Detail

reset

public void reset(java.io.InputStream in)
Reset the engine, to work over the provided stream.

Parameters:
in - the input stream for compressed data

setRawStream

public void setRawStream(java.io.InputStream in)
Change the input stream, but keep the running state. In particular, the currently read partial byte is kept; the new stream will be used for the next byte.

Parameters:
in - the new input stream for compressed data

processDictionary

public void processDictionary(java.io.InputStream dict)
                       throws java.io.IOException

Process a dictionary. This is stream of bytes which will be assumed to have just been decompressed. Conceptually, the compressor also used that dictionary; this allows some backwards references to byte sequences in that data stream.

The dictionary stream is read until its end.

Parameters:
dict - the dictionary stream
Throws:
java.io.IOException - on I/O error with the dictionary stream

processDictionary

public void processDictionary(byte[] dict)

Process a dictionary. This is stream of bytes which will be assumed to have just been decompressed. Conceptually, the compressor also used that dictionary; this allows some backwards references to byte sequences in that data stream.

Parameters:
dict - the dictionary

processDictionary

public void processDictionary(byte[] dict,
                              int off,
                              int len)

Process a dictionary. This is stream of bytes which will be assumed to have just been decompressed. Conceptually, the compressor also used that dictionary; this allows some backwards references to byte sequences in that data stream.

Parameters:
dict - the dictionary
off - the dictionary offset
len - the dictionary length

readBlock

public int readBlock(byte[] buf,
                     int off,
                     int len)
              throws java.io.IOException
Uncompress some data from the current block. Compressed bytes are read and processed until the current block is finished, or the output buffer for uncompressed data is full, whichever comes first. If the current block is finished, then 0 is returned.

Parameters:
buf - the output buffer
off - the output buffer offset
len - the output buffer length (in bytes)
Returns:
the uncompressed data length (in bytes)
Throws:
java.io.IOException

nextBlock

public boolean nextBlock()
                  throws java.io.IOException
Get the next block header. This call shall be issued only if the current block (if any) has been read completely. Returned value is true on success (next block header read and processed), false otherwise (the previous block was marked final). Format error, including unexpected end-of-stream from the underlying input stream, are reported as IOException or subclasses thereof (e.g. JGZException).

Returns:
true on success, false on logical end of compressed stream
Throws:
java.io.IOException - on I/O or format error

readAll

public int readAll(byte[] buf,
                   int off,
                   int len)
            throws java.io.IOException
Uncompress some data. Compressed bytes are read and processed until the end of the final block is reached, or the output buffer for uncompressed data is full, whichever comes first. Hence, the returned value is distinct from len only if the end of the final block was reached. If no uncompressed byte was read, then 0 is returned.

Parameters:
buf - the output buffer
off - the output buffer offset
len - the output buffer length (in bytes)
Returns:
the uncompressed data length (in bytes)
Throws:
java.io.IOException