LZWInputStream
Date: 2017-02-08

org.apache.commons.compress.compressors.lzw

## Class LZWInputStream

- java.lang.Object
- - java.io.InputStream
  - - org.apache.commons.compress.compressors.CompressorInputStream
    - - org.apache.commons.compress.compressors.lzw.LZWInputStream

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
  Direct Known Subclasses:
    ZCompressorInputStream

      public abstract class LZWInputStream
      extends CompressorInputStream

  Generic LZW implementation. It is used internally for the Z decompressor and the Unshrinking Zip file compression method, but may be useful for third-party projects in implementing their own LZW variations.

  Since:
    1.10

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static int` | `DEFAULT_CODE_SIZE`
    `protected BitInputStream` | `in`
    `protected static int` | `UNUSED_PREFIX`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `LZWInputStream(java.io.InputStream inputStream, java.nio.ByteOrder byteOrder)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract int` | `addEntry(int previousCode, byte character)` Add a new entry to the dictionary.
    `protected int` | `addEntry(int previousCode, byte character, int maxTableSize)` Adds a new entry if the maximum table size hasn't been exceeded and returns the new index.
    `protected int` | `addRepeatOfPreviousCode()` Add entry for repeat of previousCode we haven't added, yet.
    `void` | `close()`
    `protected abstract int` | `decompressNextSymbol()` Read the next code and expand it.
    `protected int` | `expandCodeToOutputStack(int code, boolean addedUnfinishedEntry)` Expands the entry with index code to the output stack and may create a new entry
    `protected int` | `getClearCode()`
    `protected int` | `getCodeSize()`
    `protected int` | `getPrefix(int offset)`
    `protected int` | `getPrefixesLength()`
    `protected int` | `getTableSize()`
    `protected void` | `incrementCodeSize()`
    `protected void` | `initializeTables(int maxCodeSize)` Initializes the arrays based on the maximum code size.
    `int` | `read()`
    `int` | `read(byte[] b, int off, int len)`
    `protected int` | `readNextCode()` Reads the next code from the stream.
    `protected void` | `resetCodeSize()`
    `protected void` | `resetPreviousCode()`
    `protected void` | `setClearCode(int codeSize)` Sets the clear code based on the code size.
    `protected void` | `setCodeSize(int cs)`
    `protected void` | `setPrefix(int offset, int value)`
    `protected void` | `setTableSize(int newSize)`

    - ### Methods inherited from class org.apache.commons.compress.compressors.CompressorInputStream

      `count, count, getBytesRead, getCount, pushedBackBytes`

    - ### Methods inherited from class java.io.InputStream

      `available, mark, markSupported, read, reset, skip`

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

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

- - ### Field Detail

    - #### DEFAULT_CODE_SIZE

          protected static final int DEFAULT_CODE_SIZE

      See Also:
        Constant Field Values

    - #### UNUSED_PREFIX

          protected static final int UNUSED_PREFIX

      See Also:
        Constant Field Values

    - #### in

          protected final BitInputStream in

  - ### Constructor Detail

    - #### LZWInputStream

          protected LZWInputStream(java.io.InputStream inputStream,
                        java.nio.ByteOrder byteOrder)

  - ### Method Detail

    - #### close

          public void close()
                     throws java.io.IOException

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Overrides:
        `close` in class `java.io.InputStream`
      Throws:
        `java.io.IOException`

    - #### read

          public int read()
                   throws java.io.IOException

      Specified by:
        `read` in class `java.io.InputStream`
      Throws:
        `java.io.IOException`

    - #### read

          public int read(byte[] b,
                 int off,
                 int len)
                   throws java.io.IOException

      Overrides:
        `read` in class `java.io.InputStream`
      Throws:
        `java.io.IOException`

    - #### decompressNextSymbol

          protected abstract int decompressNextSymbol()
                                               throws java.io.IOException

      Read the next code and expand it.
      Returns:
        the expanded next code
      Throws:
        `java.io.IOException` - on error

    - #### addEntry

          protected abstract int addEntry(int previousCode,
                     byte character)
                                   throws java.io.IOException

      Add a new entry to the dictionary.
      Parameters:
        `previousCode` - the previous code
        `character` - the next character to append
      Returns:
        the new code
      Throws:
        `java.io.IOException` - on error

    - #### setClearCode

          protected void setClearCode(int codeSize)

      Sets the clear code based on the code size.
      Parameters:
        `codeSize` - code size

    - #### initializeTables

          protected void initializeTables(int maxCodeSize)

      Initializes the arrays based on the maximum code size.
      Parameters:
        `maxCodeSize` - maximum code size

    - #### readNextCode

          protected int readNextCode()
                              throws java.io.IOException

      Reads the next code from the stream.
      Returns:
        the next code
      Throws:
        `java.io.IOException` - on error

    - #### addEntry

          protected int addEntry(int previousCode,
                     byte character,
                     int maxTableSize)

      Adds a new entry if the maximum table size hasn't been exceeded and returns the new index.
      Parameters:
        `previousCode` - the previous code
        `character` - the character to append
        `maxTableSize` - the maximum table size
      Returns:
        the new code

    - #### addRepeatOfPreviousCode

          protected int addRepeatOfPreviousCode()
                                         throws java.io.IOException

      Add entry for repeat of previousCode we haven't added, yet.
      Returns:
        new code for a repeat of the previous code
      Throws:
        `java.io.IOException` - on error

    - #### expandCodeToOutputStack

          protected int expandCodeToOutputStack(int code,
                                    boolean addedUnfinishedEntry)
                                         throws java.io.IOException

      Expands the entry with index code to the output stack and may create a new entry
      Parameters:
        `code` - the code
        `addedUnfinishedEntry` - whether unfinished entries have been added
      Returns:
        the new location of the output stack
      Throws:
        `java.io.IOException` - on error

    - #### getCodeSize

          protected int getCodeSize()

    - #### resetCodeSize

          protected void resetCodeSize()

    - #### setCodeSize

          protected void setCodeSize(int cs)

    - #### incrementCodeSize

          protected void incrementCodeSize()

    - #### resetPreviousCode

          protected void resetPreviousCode()

    - #### getPrefix

          protected int getPrefix(int offset)

    - #### setPrefix

          protected void setPrefix(int offset,
                       int value)

    - #### getPrefixesLength

          protected int getPrefixesLength()

    - #### getClearCode

          protected int getClearCode()

    - #### getTableSize

          protected int getTableSize()

    - #### setTableSize

          protected void setTableSize(int newSize)