org.at4j.comp.bzip2
Class BZip2OutputStreamSettings

java.lang.Object
  extended by org.at4j.comp.bzip2.BZip2OutputStreamSettings
All Implemented Interfaces:
Cloneable

public class BZip2OutputStreamSettings
extends Object
implements Cloneable

This object contains settings for the BZip2OutputStream.

When created, this object contains the default settings. Modify the settings by calling setter methods on this object.

Since:
1.1
Author:
Karl Gustafsson
See Also:
BZip2OutputStream

Field Summary
static int DEFAULT_BLOCK_SIZE
          The default block size.
static int DEFAULT_NO_OF_ENCODER_THREADS
          The default number of encoder threads.
static int DEFAULT_NO_OF_HUFFMAN_TREE_REFINEMENT_ITERATIONS
          The default number of Huffman tree refinement iterations.
static int MAX_BLOCK_SIZE
          The maximum size of an encoded data block in hundreds of kilobytes.
static int MIN_BLOCK_SIZE
          The minimum size of an encoded data block in hundreds of kilobytes.
 
Constructor Summary
BZip2OutputStreamSettings()
           
 
Method Summary
 BZip2OutputStreamSettings clone()
          Make a copy of this object.
 int getBlockSize()
          Get the block size for a compressed data block.
 BZip2EncoderExecutorService getExecutorService()
           
 LogAdapter getLogAdapter()
          Get the log adapter used for logging diagnostic output to.
 int getNumberOfEncoderThreads()
           
 int getNumberOfHuffmanTreeRefinementIterations()
          Get the number of Huffman tree refinement iterations.
 BZip2OutputStreamSettings setBlockSize(int bs)
          Set the size of compressed data blocks.
 BZip2OutputStreamSettings setExecutorService(BZip2EncoderExecutorService executorService)
          Set an executor service that the BZip2OutputStream will use to spread the encoding over several threads.
 BZip2OutputStreamSettings setLogAdapter(LogAdapter la)
          Set a LogAdapter for logging diagnostic output to.
 BZip2OutputStreamSettings setNumberOfEncoderThreads(int no)
          Set the number of encoder threads used for bzip2 compressing data.
 BZip2OutputStreamSettings setNumberOfHuffmanTreeRefinementIterations(int no)
          Set the number of tree refinement iterations that are run when creating Huffman trees for each compressed data block.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_BLOCK_SIZE

public static final int MIN_BLOCK_SIZE
The minimum size of an encoded data block in hundreds of kilobytes. Using a small block size gives faster but worse compression.

See Also:
Constant Field Values

MAX_BLOCK_SIZE

public static final int MAX_BLOCK_SIZE
The maximum size of an encoded data block in hundreds of kilobytes. Using a large block size gives slower but better compression.

See Also:
Constant Field Values

DEFAULT_BLOCK_SIZE

public static final int DEFAULT_BLOCK_SIZE
The default block size.

See Also:
Constant Field Values

DEFAULT_NO_OF_HUFFMAN_TREE_REFINEMENT_ITERATIONS

public static final int DEFAULT_NO_OF_HUFFMAN_TREE_REFINEMENT_ITERATIONS
The default number of Huffman tree refinement iterations. By having more tree refinement iterations the compression gets better, but as the number is increased the returns are diminishing.

See Also:
Constant Field Values

DEFAULT_NO_OF_ENCODER_THREADS

public static final int DEFAULT_NO_OF_ENCODER_THREADS
The default number of encoder threads.

See Also:
Constant Field Values
Constructor Detail

BZip2OutputStreamSettings

public BZip2OutputStreamSettings()
Method Detail

setBlockSize

public BZip2OutputStreamSettings setBlockSize(int bs)
                                       throws IllegalArgumentException
Set the size of compressed data blocks. A high block size gives good but slow compression. A low block size gives worse but faster compression.

The default block size is 9 (the highest permitted value).

Parameters:
bs - The block size in hundreds of kilobytes. This should be between 1 and 9 (inclusive).
Returns:
this
Throws:
IllegalArgumentException - If the block size is not in the permitted range.

getBlockSize

public int getBlockSize()
Get the block size for a compressed data block.

Returns:
The block size for a compressed data block.

setNumberOfHuffmanTreeRefinementIterations

public BZip2OutputStreamSettings setNumberOfHuffmanTreeRefinementIterations(int no)
                                                                     throws IllegalArgumentException
Set the number of tree refinement iterations that are run when creating Huffman trees for each compressed data block.

A higher value for this parameter should give better but slower compression. As the value increases the returns are diminishing.

The default value is five refinement iterations.

Parameters:
no - The number of Huffman tree refinement iterations. This should be a positive integer larger than zero.
Returns:
this
Throws:
IllegalArgumentException - If the number is not a positive integer larger than zero.

getNumberOfHuffmanTreeRefinementIterations

public int getNumberOfHuffmanTreeRefinementIterations()
Get the number of Huffman tree refinement iterations.

Returns:
The number of Huffman tree refinement iterations.

setLogAdapter

public BZip2OutputStreamSettings setLogAdapter(LogAdapter la)
Set a LogAdapter for logging diagnostic output to. Output is logged to the debug and trace levels.

By default no log adapter is used and hence no diagnostic output is logged.

Parameters:
la - A log adapter.
Returns:
this

getLogAdapter

public LogAdapter getLogAdapter()
Get the log adapter used for logging diagnostic output to.

Returns:
The log adapter or null if no log adapter is set.

setNumberOfEncoderThreads

public BZip2OutputStreamSettings setNumberOfEncoderThreads(int no)
                                                    throws IllegalArgumentException
Set the number of encoder threads used for bzip2 compressing data. bzip2 encoding is CPU intensive and giving the encoder more threads to work with can drastically shorten the encoding time. The drawback is that the memory consumption grows since each encoder thread must keep its data in memory.

The default number of encoder threads is zero, which means that the thread that is writing the data to the BZip2OutputStream will be used for the encoding.

For the shortest encoding time, use as many threads as there are available CPU:s in the system.

Parameters:
no - The number of encoder threads to use. If this is set to 0, the encoding will be done in the thread writing to the stream.
Returns:
this
Throws:
IllegalArgumentException - If no is negative.
See Also:
setExecutorService(BZip2EncoderExecutorService)

getNumberOfEncoderThreads

public int getNumberOfEncoderThreads()

setExecutorService

public BZip2OutputStreamSettings setExecutorService(BZip2EncoderExecutorService executorService)
Set an executor service that the BZip2OutputStream will use to spread the encoding over several threads. This executor can be shared among several BZip2OutputStream objects.

If an executor service is set using this method, all threads that are available to the executor is used for the encoding and any value set using setNumberOfEncoderThreads(int) is ignored.

An executor service is created using the BZip2OutputStream.createExecutorService() or the BZip2OutputStream.createExecutorService(int) method.

Parameters:
executorService - The executor service.
Returns:
this
See Also:
setNumberOfEncoderThreads(int)

getExecutorService

public BZip2EncoderExecutorService getExecutorService()

clone

public BZip2OutputStreamSettings clone()
Make a copy of this object.

Overrides:
clone in class Object