org.at4j.comp.lzma
Class LzmaOutputStreamSettings

java.lang.Object
  extended by org.at4j.comp.lzma.LzmaOutputStreamSettings

public class LzmaOutputStreamSettings
extends Object

This configuration object contains settings for the LzmaOutputStream. When new:ed, this object contains the default settings. Use setter methods to modify its properties.

The properties are documented by their setter methods. For more in-depth documentation, refer to the LZMA SDK documentation.

Since:
1.0
Author:
Karl Gustafsson
See Also:
LzmaOutputStream

Field Summary
static int DEFAULT_DICTIONARY_SIZE_EXPONENT
          The default dictionary size exponent.
static MatchFinderAlgorithm DEFAULT_MATCH_FINDER_ALGORITHM
          The default match finder algorithm.
static int DEFAULT_MAX_DATA_QUEUE_SIZE
          The default maximum number of entries in the data queue used to feed data to the encoder.
static int DEFAULT_NUMBER_OF_LITERAL_CONTEXT_BITS
          The default number of literal context bits.
static int DEFAULT_NUMBER_OF_LITERAL_POS_BITS
          The default number of literal pos bits.
static int DEFAULT_NUMBER_OF_POS_BITS
          The default number of pos bits.
static boolean DEFAULT_WRITE_STREAM_PROPERTIES
          By default the stream properties are written at the head of the stream.
static boolean DEFAULT_WRITE_UNCOMPRESSED_DATA_SIZE
          By default the size of uncompressed data is written after the stream properties at the head of the stream.
 
Constructor Summary
LzmaOutputStreamSettings()
           
 
Method Summary
 int getBufferSize()
          Get the buffer size to use for the buffered output stream that the LZMA stream is opened on.
 int getDictionarySizeExponent()
          Get the dictionary size exponent.
 MatchFinderAlgorithm getMatchFinderAlgorithm()
          Get the match finder algorithm for the encoder.
 int getMaxDataQueueSize()
          Get the maximum size for the data queue used to feed data to the encoder.
 int getNumberOfLiteralContextBits()
          Get the number of literal context bits.
 int getNumberOfLiteralPosBits()
          Get the number of literal pos bits.
 int getNumberOfPosBits()
          Get the number of pos bits.
 byte[] getProperties()
          This method can be used to get the output stream properties in the format that they are encoded in the stream.
 ThreadFactory getThreadFactory()
          Get the thread factory that will be used for creating the LZMA compression thread.
 boolean isWriteStreamProperties()
          Should the encoder properties be written at the head of the stream?
 boolean isWriteUncompressedDataSize()
          Should the uncompressed data size (even if unknown) be written after the encoder properties at the head of the stream?
 LzmaOutputStreamSettings setBufferSize(int sz)
          Set the buffer size to use for the buffered output stream that the LZMA stream is opened on.
 LzmaOutputStreamSettings setCompressionLevel(CompressionLevel level)
          Set a compression level.
 LzmaOutputStreamSettings setDictionarySizeExponent(int size)
          Set the dictionary size exponent.
 LzmaOutputStreamSettings setMatchFinderAlgorithm(MatchFinderAlgorithm mfa)
          Set the match finder algorithm for the encoder.
 LzmaOutputStreamSettings setMaxDataQueueSize(int max)
          Set the maximum queue depth for the data queue used to feed data to the encoder.
 LzmaOutputStreamSettings setNumberOfLiteralContextBits(int no)
          Set the number of literal context bits.
 LzmaOutputStreamSettings setNumberOfLiteralPosBits(int no)
          Set the number of literal pos bits.
 LzmaOutputStreamSettings setNumberOfPosBits(int no)
          Set the number of pos bits.
 LzmaOutputStreamSettings setThreadFactory(ThreadFactory tf)
          Set the thread factory to use for creating the thread that will run the LZMA compression.
 LzmaOutputStreamSettings setWriteStreamProperties(boolean b)
          Should the encoding properties be written at the head of the stream? The properties are five bytes that document the settings of the encoder when encoding the stream.
 LzmaOutputStreamSettings setWriteUncompressedDataSize(boolean b)
          Should the uncompressed data size be written at the head of the stream, after the encoder properties (or first, if they are not present)? The uncompressed data size is a eight byte signed little endian value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DICTIONARY_SIZE_EXPONENT

public static final int DEFAULT_DICTIONARY_SIZE_EXPONENT
The default dictionary size exponent. See setDictionarySizeExponent(int).

See Also:
Constant Field Values

DEFAULT_NUMBER_OF_LITERAL_CONTEXT_BITS

public static final int DEFAULT_NUMBER_OF_LITERAL_CONTEXT_BITS
The default number of literal context bits. See setNumberOfLiteralContextBits(int).

See Also:
Constant Field Values

DEFAULT_NUMBER_OF_LITERAL_POS_BITS

public static final int DEFAULT_NUMBER_OF_LITERAL_POS_BITS
The default number of literal pos bits. See setNumberOfLiteralPosBits(int).

See Also:
Constant Field Values

DEFAULT_NUMBER_OF_POS_BITS

public static final int DEFAULT_NUMBER_OF_POS_BITS
The default number of pos bits. See setNumberOfPosBits(int).

See Also:
Constant Field Values

DEFAULT_MATCH_FINDER_ALGORITHM

public static final MatchFinderAlgorithm DEFAULT_MATCH_FINDER_ALGORITHM
The default match finder algorithm. See setMatchFinderAlgorithm(MatchFinderAlgorithm).


DEFAULT_MAX_DATA_QUEUE_SIZE

public static final int DEFAULT_MAX_DATA_QUEUE_SIZE
The default maximum number of entries in the data queue used to feed data to the encoder. See setMaxDataQueueSize(int).

See Also:
Constant Field Values

DEFAULT_WRITE_STREAM_PROPERTIES

public static final boolean DEFAULT_WRITE_STREAM_PROPERTIES
By default the stream properties are written at the head of the stream. See setWriteStreamProperties(boolean).

See Also:
Constant Field Values

DEFAULT_WRITE_UNCOMPRESSED_DATA_SIZE

public static final boolean DEFAULT_WRITE_UNCOMPRESSED_DATA_SIZE
By default the size of uncompressed data is written after the stream properties at the head of the stream. See setWriteUncompressedDataSize(boolean).

See Also:
Constant Field Values
Constructor Detail

LzmaOutputStreamSettings

public LzmaOutputStreamSettings()
Method Detail

setDictionarySizeExponent

public LzmaOutputStreamSettings setDictionarySizeExponent(int size)
                                                   throws IllegalArgumentException
Set the dictionary size exponent. The dictionary used will have the size 2^size bytes. The maximum exponent is 30. The default is 2^23 = 8.4 MB.

Parameters:
size - The dictionary size exponent.
Returns:
this
Throws:
IllegalArgumentException - If the supplied size is negative or larger than 30.

getDictionarySizeExponent

public int getDictionarySizeExponent()
Get the dictionary size exponent.

Returns:
The dictionary size exponent.
See Also:
setDictionarySizeExponent(int)

setNumberOfLiteralContextBits

public LzmaOutputStreamSettings setNumberOfLiteralContextBits(int no)
                                                       throws IllegalArgumentException
Set the number of literal context bits. See the LZMA SDK documentation for an explanation of this property.

This value must be between 0 and 8 (inclusive). The default value is 3. According to the LZMA documentation, 4 may give a better compress ratio for big files.

Parameters:
no - The number of literal context bits.
Returns:
this
Throws:
IllegalArgumentException - If the number is negative or greater than 8.

getNumberOfLiteralContextBits

public int getNumberOfLiteralContextBits()
Get the number of literal context bits.

Returns:
The number of literal context bits.
See Also:
setNumberOfLiteralContextBits(int)

setNumberOfLiteralPosBits

public LzmaOutputStreamSettings setNumberOfLiteralPosBits(int no)
                                                   throws IllegalArgumentException
Set the number of literal pos bits. This is used for periodical data when the period is equal to 2^no bytes. For example, for 32-bit (4 bytes) periodical data, no can be set to 2.

If this property is modified from its default value of 0, it often makes sense to set the number of literal context bits to 0. See setNumberOfLiteralContextBits(int).

This property must be in the range between 0 and 4 (inclusive).

Parameters:
no - The number of literal pos bits.
Returns:
this.
Throws:
IllegalArgumentException - If the number is negative or greater than 4.

getNumberOfLiteralPosBits

public int getNumberOfLiteralPosBits()
Get the number of literal pos bits.

Returns:
The number of literal pos bits.
See Also:
setNumberOfLiteralPosBits(int)

setNumberOfPosBits

public LzmaOutputStreamSettings setNumberOfPosBits(int no)
                                            throws IllegalArgumentException
Set the number of pos bits. This is intended for periodical data when the period is equal to 2^no.

This value must be between 0 and 4 (inclusive). The default value is 2.

Parameters:
no - The number of pos bits.
Returns:
this
Throws:
IllegalArgumentException - If the number is negative or greater than 4.

getNumberOfPosBits

public int getNumberOfPosBits()
Get the number of pos bits.

Returns:
The number of pos bits.
See Also:
setNumberOfPosBits(int)

setMatchFinderAlgorithm

public LzmaOutputStreamSettings setMatchFinderAlgorithm(MatchFinderAlgorithm mfa)
                                                 throws NullPointerException
Set the match finder algorithm for the encoder.

Parameters:
mfa - The match finder algorithm.
Returns:
this
Throws:
NullPointerException - If the match finder algorithm is null.

getMatchFinderAlgorithm

public MatchFinderAlgorithm getMatchFinderAlgorithm()
Get the match finder algorithm for the encoder.

Returns:
The match finder algorithm for the encoder.
See Also:
setMatchFinderAlgorithm(MatchFinderAlgorithm)

setMaxDataQueueSize

public LzmaOutputStreamSettings setMaxDataQueueSize(int max)
                                             throws IllegalArgumentException
Set the maximum queue depth for the data queue used to feed data to the encoder. By default the maximum queue depth is unlimited (represented by a value of 0). By setting this to some value, the total memory requirement for the compression operation is capped. The drawback is that the writing thread may be blocked waiting for the permission to put data on the queue if the queue is full.

The queue depth is measured in the number of data records in the queue. Every time the writing thread writes to the LZMA output stream, a data entry is put on the queue. This may be a single byte or a large byte array.

Parameters:
max - The maximum queue depth measured in the number of data entries. 0 means that the queue has unlimited size.
Returns:
this
Throws:
IllegalArgumentException - If the maximum queue depth is negative.

getMaxDataQueueSize

public int getMaxDataQueueSize()
Get the maximum size for the data queue used to feed data to the encoder.

Returns:
The maximum size for the data queue used to feed data to the encoder.
See Also:
setMaxDataQueueSize(int)

setWriteStreamProperties

public LzmaOutputStreamSettings setWriteStreamProperties(boolean b)
Should the encoding properties be written at the head of the stream? The properties are five bytes that document the settings of the encoder when encoding the stream. They are used by the decoder to be able to decode the stream.

If the properties are set somewhere else, this may be set to false.

The default behavior is to write the encoder properties.

Parameters:
b - Should the encoding properties be written at the head of the stream?
Returns:
this
See Also:
setWriteUncompressedDataSize(boolean)

isWriteStreamProperties

public boolean isWriteStreamProperties()
Should the encoder properties be written at the head of the stream?

Returns:
true if the encoder properties should be written at the head of the stream.
See Also:
setWriteStreamProperties(boolean)

setWriteUncompressedDataSize

public LzmaOutputStreamSettings setWriteUncompressedDataSize(boolean b)
Should the uncompressed data size be written at the head of the stream, after the encoder properties (or first, if they are not present)? The uncompressed data size is a eight byte signed little endian value.

The default behavior is to write the uncompressed data size, or to write -1 if that is unknown.

Parameters:
b - Should the uncompressed data size be written at the head of the stream?
Returns:
this

isWriteUncompressedDataSize

public boolean isWriteUncompressedDataSize()
Should the uncompressed data size (even if unknown) be written after the encoder properties at the head of the stream?

Returns:
true if the uncompressed data size should be written at the head of the stream.
See Also:
setWriteUncompressedDataSize(boolean)

setBufferSize

public LzmaOutputStreamSettings setBufferSize(int sz)
                                       throws IllegalArgumentException
Set the buffer size to use for the buffered output stream that the LZMA stream is opened on.

Parameters:
sz - The buffer size.
Returns:
this
Throws:
IllegalArgumentException - If the buffer size is < 1.

getBufferSize

public int getBufferSize()
Get the buffer size to use for the buffered output stream that the LZMA stream is opened on.

Returns:
The buffer size.
See Also:
setBufferSize(int)

setCompressionLevel

public LzmaOutputStreamSettings setCompressionLevel(CompressionLevel level)
Set a compression level. Setting a compression level affects some of the properties of this object.

The following values are set for the different compression levels:

Property BEST DEFAULT FASTEST
Dictionary size exponent 30 bytes 23 bytes 20 bytes
Number of literal context bits 4 3 3

Parameters:
level - The compression level.
Returns:
this
Since:
1.0.2

setThreadFactory

public LzmaOutputStreamSettings setThreadFactory(ThreadFactory tf)
Set the thread factory to use for creating the thread that will run the LZMA compression.

If this is not set, the LzmaOutputStream will just create a thread with new Thread.

By default, this property is null.

Parameters:
tf - The thread factory, or null if the LzmaOutputStream should use new Thread to create the compression thread.
Returns:
this

getThreadFactory

public ThreadFactory getThreadFactory()
Get the thread factory that will be used for creating the LZMA compression thread.

Returns:
The thread factory, or null if not set.

getProperties

public byte[] getProperties()
This method can be used to get the output stream properties in the format that they are encoded in the stream.

The properties can be used with a LzmaInputStreamSettings object.

Returns:
The encoded properties.