Top Description Fields Constructors Methods
org.apache.poi.util

public abstract Class LZWDecompresser

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream, org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream

This class provides common functionality for the various LZW implementations in the different file formats. It's currently used by HDGF and HMEF.

Two good resources on LZW are: http://en.wikipedia.org/wiki/LZW http://marknelson.us/1989/10/01/lzw-data-compression/

Field Summary

Modifier and TypeField and Description
private final int
codeLengthIncrease

How much to append to the code length in the stream to get the real code length?

private static final int
public static final int
DICT_MASK

the mask for calculating / wrapping dictionary offsets

public static final int
DICT_SIZE

the size of our dictionary

private final boolean
maskMeansCompressed

Does the mask bit mean it's compressed or uncompressed?

private static int
private final boolean
positionIsBigEndian

Does the 12 bits of the position get stored in Little Endian or Big Endian form?

Constructor Summary

AccessConstructor and Description
protected
LZWDecompresser(boolean maskMeansCompressed, int codeLengthIncrease, boolean positionIsBigEndian)

Method Summary

Modifier and TypeMethod and Description
protected abstract int
adjustDictionaryOffset(int offset)

Adjusts the position offset if needed when looking something up in the dictionary.

public byte[]
decompress(InputStream src)

Decompresses the given input stream, returning the array of bytes of the decompressed input.

public void
decompress(InputStream src, OutputStream res)

Perform a streaming decompression of the input.

public static int

Returns:

the max record length allowed for LZWDecompresser
getMaxRecordLength
()

protected abstract int
populateDictionary(byte[] dict)

Populates the dictionary, and returns where in it to begin writing new codes.

public static void
setMaxRecordLength(int
the max record length allowed for LZWDecompresser
length
)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

codeLengthIncreaseback to summary
private final int codeLengthIncrease

How much to append to the code length in the stream to get the real code length? Normally 2 or 3

DEFAULT_MAX_RECORD_LENGTHback to summary
private static final int DEFAULT_MAX_RECORD_LENGTH
DICT_MASKback to summary
public static final int DICT_MASK

the mask for calculating / wrapping dictionary offsets

DICT_SIZEback to summary
public static final int DICT_SIZE

the size of our dictionary

maskMeansCompressedback to summary
private final boolean maskMeansCompressed

Does the mask bit mean it's compressed or uncompressed?

MAX_RECORD_LENGTHback to summary
private static int MAX_RECORD_LENGTH
positionIsBigEndianback to summary
private final boolean positionIsBigEndian

Does the 12 bits of the position get stored in Little Endian or Big Endian form? This controls whether a pos+length of 0x12 0x34 becomes a position of 0x123 or 0x312

Constructor Detail

LZWDecompresserback to summary
protected LZWDecompresser(boolean maskMeansCompressed, int codeLengthIncrease, boolean positionIsBigEndian)

Method Detail

adjustDictionaryOffsetback to summary
protected abstract int adjustDictionaryOffset(int offset)

Adjusts the position offset if needed when looking something up in the dictionary.

decompressback to summary
public byte[] decompress(InputStream src) throws IOException

Decompresses the given input stream, returning the array of bytes of the decompressed input.

decompressback to summary
public void decompress(InputStream src, OutputStream res) throws IOException

Perform a streaming decompression of the input. Works by: 1) Reading a flag byte, the 8 bits of which tell you if the following 8 codes are compressed our un-compressed 2) Consider the 8 bits in turn 3) If the bit is set, the next code is un-compressed, so add it to the dictionary and output it 4) If the bit isn't set, then read in the length and start position in the dictionary, and output the bytes there 5) Loop until we've done all 8 bits, then read in the next flag byte

getMaxRecordLengthback to summary
public static int getMaxRecordLength()
Returns:int

the max record length allowed for LZWDecompresser

populateDictionaryback to summary
protected abstract int populateDictionary(byte[] dict)

Populates the dictionary, and returns where in it to begin writing new codes. Generally, if the dictionary is pre-populated, then new codes should be placed at the end of that block. Equally, if the dictionary is left with all zeros, then usually the new codes can go in at the start.

setMaxRecordLengthback to summary
public static void setMaxRecordLength(int length)
Parameters
length:int

the max record length allowed for LZWDecompresser