Class LZWDecompresser

java.lang.Object
org.apache.poi.util.LZWDecompresser
Direct Known Subclasses:
CompressedRTF, HDGFLZW

public abstract class LZWDecompresser extends Object
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 Details

    • DICT_SIZE

      public static final int DICT_SIZE
      the size of our dictionary
      See Also:
    • DICT_MASK

      public static final int DICT_MASK
      the mask for calculating / wrapping dictionary offsets
      See Also:
  • Method Details

    • setMaxRecordLength

      public static void setMaxRecordLength(int length)
      Parameters:
      length - the max record length allowed for LZWDecompresser
    • getMaxRecordLength

      public static int getMaxRecordLength()
      Returns:
      the max record length allowed for LZWDecompresser
    • decompress

      public byte[] decompress(InputStream src) throws IOException
      Decompresses the given input stream, returning the array of bytes of the decompressed input.
      Throws:
      IOException
    • decompress

      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
      Throws:
      IOException