org.atmosphere.gwt.server.deflate
Class Deflater

java.lang.Object
  extended by org.atmosphere.gwt.server.deflate.Deflater

public final class Deflater
extends Object

This class implements the core DEFLATE process, i.e. the compression of data into DEFLATE blocks.

Version:
$Revision: 122 $
Author:
Thomas Pornin

Field Summary
static int COMPACT
          Compression level 4: try to achieve best compression ratio, possibly at the expense of compression speed.
static int HUFF
          Compression level 1: do not apply LZ77; only Huffman codes are computed.
static int MEDIUM
          Compression level 3: compromise between speed and compression ratio.
static int SPEED
          Compression level 2: optimize for speed.
 
Constructor Summary
Deflater()
          Build a deflater with the default parameters (MEDIUM level, 15-bit window).
Deflater(int level)
          Build a deflater with the provided compression strategy (either SPEED, MEDIUM or COMPACT).
Deflater(int level, int windowBits)
          Build a deflater with the provided compression strategy (either SPEED, MEDIUM or COMPACT) and the provided window size.
 
Method Summary
 void flushSync(boolean withData)
          Perform a "sync flush" in a way similar to what is done by zlib with option Z_SYNC_FLUSH.
 OutputStream getOut()
          Get the current output transport stream.
 void process(byte[] buf, int off, int len)
          Process some more data.
 void setOut(OutputStream out)
          Set the current output transport stream.
 void terminate()
          Terminate the current compression run.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HUFF

public static final int HUFF
Compression level 1: do not apply LZ77; only Huffman codes are computed. This is faster than SPEED but with a degraded compression ratio.

See Also:
Constant Field Values

SPEED

public static final int SPEED
Compression level 2: optimize for speed.

See Also:
Constant Field Values

MEDIUM

public static final int MEDIUM
Compression level 3: compromise between speed and compression ratio. This is the default level.

See Also:
Constant Field Values

COMPACT

public static final int COMPACT
Compression level 4: try to achieve best compression ratio, possibly at the expense of compression speed. This level may occasionaly yield slightly worse results than the MEDIUM level.

See Also:
Constant Field Values
Constructor Detail

Deflater

public Deflater()
Build a deflater with the default parameters (MEDIUM level, 15-bit window).


Deflater

public Deflater(int level)
Build a deflater with the provided compression strategy (either SPEED, MEDIUM or COMPACT). A standard 15-bit window is used. If the compression level is 0, then the default compression level is selected.

Parameters:
level - the compression strategy

Deflater

public Deflater(int level,
                int windowBits)
Build a deflater with the provided compression strategy (either SPEED, MEDIUM or COMPACT) and the provided window size. The window size is expressed in bits and may range from 9 to 15 (inclusive). The DEFLATE format uses a 15-bit window; by using a smaller window, the produced stream can be inflated with less memory (but compression ratio is lowered). If the compression level is 0, then the default compression level is selected.

Parameters:
level - the compression strategy
windowBits - the window bit size (9 to 15)
Method Detail

getOut

public OutputStream getOut()
Get the current output transport stream.

Returns:
the current output stream

setOut

public void setOut(OutputStream out)
Set the current output transport stream. This method must be called before compressing data.

Parameters:
out - the new transport stream

process

public void process(byte[] buf,
                    int off,
                    int len)
             throws IOException
Process some more data. When the internal buffer is full, or when the compressor code deems it appropriate, the data is compressed and sent on the transport stream. This method is most efficient when data is input by big enough chunks (at least a dozen bytes per call).

Parameters:
buf - the data buffer
off - the data offset
len - the data length (in bytes)
Throws:
IOException - on I/O error with the transport stream

terminate

public void terminate()
               throws IOException
Terminate the current compression run. Pending buffered data, if any, is compressed as a final block, and written out on the transport stream. If there is no pending buffered data, then an empty, final block is added. Either way, any remaining partial byte is padded with zeroes and written. The transport stream is NOT flushed.

Throws:
IOException - on I/O error with the transport stream

flushSync

public void flushSync(boolean withData)
               throws IOException
Perform a "sync flush" in a way similar to what is done by zlib with option Z_SYNC_FLUSH. The current block, if any, is closed, and one empty type 0 block is added. After this call, the stream is byte-aligned. The type 0 block ends with the aligned four-byte sequence 00 00 FF FF; these four bytes are omitted if withData is false. The transport stream is NOT flushed.

Parameters:
withData - false to omit the 00 00 FF FF bytes
Throws:
IOException - on I/O error with the transport stream


Copyright © 2014. All Rights Reserved.