org.apache.poi.util

## Class LZWDecompresser

- java.lang.Object
- - org.apache.poi.util.LZWDecompresser

- Direct Known Subclasses:
    CompressedRTF, HDGFLZW

      public abstract class LZWDecompresser
      extends java.lang.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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DICT_MASK` the mask for calculating / wrapping dictionary offsets
    `static int` | `DICT_SIZE` the size of our dictionary

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `LZWDecompresser(boolean maskMeansCompressed, int codeLengthIncrease, boolean positionIsBigEndian)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract int` | `adjustDictionaryOffset(int offset)` Adjusts the position offset if needed when looking something up in the dictionary.
    `byte[]` | `decompress(java.io.InputStream src)` Decompresses the given input stream, returning the array of bytes of the decompressed input.
    `void` | `decompress(java.io.InputStream src, java.io.OutputStream res)` Perform a streaming decompression of the input.
    `protected abstract int` | `populateDictionary(byte[] dict)` Populates the dictionary, and returns where in it to begin writing new codes.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DICT_SIZE

          public static final int DICT_SIZE

      the size of our dictionary
      See Also:
        Constant Field Values

    - #### DICT_MASK

          public static final int DICT_MASK

      the mask for calculating / wrapping dictionary offsets
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### LZWDecompresser

          protected LZWDecompresser(boolean maskMeansCompressed,
                                    int codeLengthIncrease,
                                    boolean positionIsBigEndian)

  - ### Method Detail

    - #### populateDictionary

          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.

    - #### adjustDictionaryOffset

          protected abstract int adjustDictionaryOffset(int offset)

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

    - #### decompress

          public byte[] decompress(java.io.InputStream src)
                            throws java.io.IOException

      Decompresses the given input stream, returning the array of bytes of the decompressed input.
      Throws:
        `java.io.IOException`

    - #### decompress

          public void decompress(java.io.InputStream src,
                                 java.io.OutputStream res)
                          throws java.io.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:
        `java.io.IOException`

Copyright 2020 The Apache Software Foundation or its licensors, as applicable.