Package org.apache.pdfbox.filter
Class LZWFilter
java.lang.Object
org.apache.pdfbox.filter.Filter
org.apache.pdfbox.filter.LZWFilter
This is the filter used for the LZWDecode filter.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe LZW clear table code.static final longThe LZW end of data code.private static final List<byte[]>private static final org.apache.commons.logging.LogLog instance.Fields inherited from class org.apache.pdfbox.filter.Filter
SYSPROP_DEFLATELEVEL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static intcalculateChunk(int tabSize, boolean earlyChange) Calculate the appropriate chunk sizeprivate voidcheckIndexBounds(List<byte[]> codeTable, long index, MemoryCacheImageInputStream in) private static List<byte[]>Init the code table with 1 byte entries and the EOD and CLEAR_TABLE markers.private static List<byte[]>decode(InputStream encoded, OutputStream decoded, COSDictionary parameters, int index) Decodes data, producing the original non-encoded data.private voiddoLZWDecode(InputStream encoded, OutputStream decoded, boolean earlyChange) protected voidencode(InputStream rawData, OutputStream encoded, COSDictionary parameters) private static intfindPatternCode(List<byte[]> codeTable, byte[] pattern) Find a matching pattern in the code table.Methods inherited from class org.apache.pdfbox.filter.Filter
decode, encode, findImageReader, getCompressionLevel, getDecodeParams
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOGLog instance. -
CLEAR_TABLE
public static final long CLEAR_TABLEThe LZW clear table code.- See Also:
-
EOD
public static final long EODThe LZW end of data code.- See Also:
-
INITIAL_CODE_TABLE
-
-
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:
decodein classFilter- Parameters:
encoded- the encoded byte streamdecoded- the stream where decoded data will be writtenparameters- the parameters used for decodingindex- 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, boolean 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:
encodein classFilter- Throws:
IOException
-
findPatternCode
Find a matching pattern in the code table.- Parameters:
codeTable- The LZW code table.pattern- The pattern to be searched for.- Returns:
- The index of the matching pattern or -1 if nothing is found.
-
createCodeTable
Init the code table with 1 byte entries and the EOD and CLEAR_TABLE markers. -
createInitialCodeTable
-
calculateChunk
private static int calculateChunk(int tabSize, boolean earlyChange) Calculate the appropriate chunk size- Parameters:
tabSize- the size of the code tableearlyChange- true for early chunk increase- Returns:
- a value between 9 and 12
-