Class LZWFilter

java.lang.Object
org.apache.pdfbox.filter.Filter
org.apache.pdfbox.filter.LZWFilter

public class LZWFilter extends Filter
This is the filter used for the LZWDecode filter.
  • Field Details

    • LOG

      private static final org.apache.commons.logging.Log LOG
      Log instance.
    • CLEAR_TABLE

      public static final long CLEAR_TABLE
      The LZW clear table code.
      See Also:
    • EOD

      public static final long EOD
      The LZW end of data code.
      See Also:
  • Constructor Details

    • LZWFilter

      public LZWFilter()
  • Method Details

    • decode

      public DecodeResult decode(InputStream encoded, OutputStream decoded, COSDictionary parameters, int index) throws IOException
      Decodes data, producing the original non-encoded data.
      Specified by:
      decode in class Filter
      Parameters:
      encoded - the encoded byte stream
      decoded - the stream where decoded data will be written
      parameters - the parameters used for decoding
      index - the index to the filter being decoded
      Returns:
      repaired parameters dictionary, or the original parameters dictionary
      Throws:
      IOException - if the stream cannot be decoded
    • doLZWDecode

      private void doLZWDecode(InputStream encoded, OutputStream decoded, int earlyChange) throws IOException
      Throws:
      IOException
    • checkIndexBounds

      private void checkIndexBounds(List<byte[]> codeTable, long index, MemoryCacheImageInputStream in) throws IOException
      Throws:
      IOException
    • encode

      protected void encode(InputStream rawData, OutputStream encoded, COSDictionary parameters) throws IOException
      Specified by:
      encode in class Filter
      Throws:
      IOException
    • findPatternCode

      private int findPatternCode(List<byte[]> codeTable, byte[] pattern)
      Find the longest matching pattern in the code table.
      Parameters:
      codeTable - The LZW code table.
      pattern - The pattern to be searched for.
      Returns:
      The index of the longest matching pattern or -1 if nothing is found.
    • createCodeTable

      private List<byte[]> createCodeTable()
      Init the code table with 1 byte entries and the EOD and CLEAR_TABLE markers.
    • calculateChunk

      private int calculateChunk(int tabSize, int earlyChange)
      Calculate the appropriate chunk size
      Parameters:
      tabSize - the size of the code table
      earlyChange - 0 or 1 for early chunk increase
      Returns:
      a value between 9 and 12