org.at4j.comp.bzip2
Class BZip2WritableFileSettings

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

public class BZip2WritableFileSettings
extends Object
implements Cloneable

This object contains settings used when creating a BZip2WritableFile.

Since:
1.1
Author:
Karl Gustafsson

Constructor Summary
BZip2WritableFileSettings()
           
 
Method Summary
 BZip2WritableFileSettings clone()
          Make a copy of this object.
 int getBlockSize()
           
 int getBufferSize()
           
 BZip2EncoderExecutorService getExcutorService()
           
 LogAdapter getLogAdapter()
           
 int getNumberOfEncoderThreads()
           
 int getNumberOfHuffmanTreeRefinementIterations()
          Get the number of Huffman tree refinement iterations.
 BZip2OutputStreamSettings getOutputStreamSettings()
          Get the settings for a BZip2OutputStream based on the configuration of this object.
 boolean isUseCommonsCompress()
           
 BZip2WritableFileSettings setBlockSize(int blockSize)
          Set the block size for the compression.
 BZip2WritableFileSettings setBufferSize(int bufferSize)
          Set the buffer size used for the input buffer that may be used before compressing written data.
 BZip2WritableFileSettings setExecutorService(BZip2EncoderExecutorService executorService)
          Set an executor service that will be used for spreading the work of encoding bzip2 blocks over several threads.
 BZip2WritableFileSettings setLogAdapter(LogAdapter la)
          Set a LogAdapter to use for logging error and diagnostic output.
 BZip2WritableFileSettings setNumberOfEncoderThreads(int no)
          Set the number of encoder threads to use for encoding bzip2 blocks.
 BZip2WritableFileSettings setNumberOfHuffmanTreeRefinementIterations(int no)
          Set the number of tree refinement iterations that is run when creating Huffman trees for each compressed data block.
 BZip2WritableFileSettings setUseCommonsCompress(boolean b)
          Should the bzip2 implementation from Apache Commons Compress be used instead of At4J's?
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BZip2WritableFileSettings

public BZip2WritableFileSettings()
Method Detail

setBlockSize

public BZip2WritableFileSettings setBlockSize(int blockSize)
                                       throws IllegalArgumentException
Set the block size for the compression.

Parameters:
blockSize - The size of bzip2 dictionary in 100k units. This must be a value between 1 and 9 (inclusive). A higher value gives a higher compression, but it will also make the compression and future decompressions use more memory.
Returns:
this
Throws:
IllegalArgumentException - If the block size is not in the permitted range.

getBlockSize

public int getBlockSize()

setBufferSize

public BZip2WritableFileSettings setBufferSize(int bufferSize)
                                        throws IllegalArgumentException
Set the buffer size used for the input buffer that may be used before compressing written data.

By default, no buffer is used.

Parameters:
bufferSize - The size of the memory buffer used for buffering the written output before it is compressed. Set this to 0 to disable the buffer.
Returns:
this
Throws:
IllegalArgumentException

getBufferSize

public int getBufferSize()

setUseCommonsCompress

public BZip2WritableFileSettings setUseCommonsCompress(boolean b)
Should the bzip2 implementation from Apache Commons Compress be used instead of At4J's?

Parameters:
b - Set this to true to use the bzip2 implementation from Commons Compress.
Returns:
this

isUseCommonsCompress

public boolean isUseCommonsCompress()

setLogAdapter

public BZip2WritableFileSettings setLogAdapter(LogAdapter la)
Set a LogAdapter to use for logging error and diagnostic output. This is only used for logging error output if several encoder threads are used.

Parameters:
la - The log adapter.
Returns:
this

getLogAdapter

public LogAdapter getLogAdapter()

setNumberOfEncoderThreads

public BZip2WritableFileSettings setNumberOfEncoderThreads(int no)
                                                    throws IllegalArgumentException
Set the number of encoder threads to use for encoding bzip2 blocks.

By default, bzip2 blocks are encoded in the thread that writes data to the writable file.

If an executor is set with the setExecutorService(BZip2EncoderExecutorService) method, this property is ignored.

Parameters:
no - Number of encoder threads. Set this to 0 to encode bzip2 blocks in the thread writing to the writable file.
Returns:
this
Throws:
IllegalArgumentException - If the number is negative.

getNumberOfEncoderThreads

public int getNumberOfEncoderThreads()

setExecutorService

public BZip2WritableFileSettings setExecutorService(BZip2EncoderExecutorService executorService)
Set an executor service that will be used for spreading the work of encoding bzip2 blocks over several threads. The executor may be shared between several BZip2WritableFile:s and/or BZip2OutputStream:s.

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

Parameters:
executorService - The executor service.
Returns:
this

getExcutorService

public BZip2EncoderExecutorService getExcutorService()

setNumberOfHuffmanTreeRefinementIterations

public BZip2WritableFileSettings setNumberOfHuffmanTreeRefinementIterations(int no)
                                                                     throws IllegalArgumentException
Set the number of tree refinement iterations that is 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.

getOutputStreamSettings

public BZip2OutputStreamSettings getOutputStreamSettings()
Get the settings for a BZip2OutputStream based on the configuration of this object.

Returns:
Stream settings.

clone

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

Overrides:
clone in class Object