Package org.apache.pdfbox.filter
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 Summary
Fields Modifier and Type Field Description static longCLEAR_TABLEThe LZW clear table code.static longEODThe LZW end of data code.private static java.util.List<byte[]>INITIAL_CODE_TABLEprivate static org.apache.commons.logging.LogLOGLog instance.-
Fields inherited from class org.apache.pdfbox.filter.Filter
SYSPROP_DEFLATELEVEL
-
-
Constructor Summary
Constructors Constructor Description LZWFilter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static intcalculateChunk(int tabSize, boolean earlyChange)Calculate the appropriate chunk sizeprivate static java.util.List<byte[]>createCodeTable()Init the code table with 1 byte entries and the EOD and CLEAR_TABLE markers.private static java.util.List<byte[]>createInitialCodeTable()DecodeResultdecode(java.io.InputStream encoded, java.io.OutputStream decoded, COSDictionary parameters, int index)Decodes data, producing the original non-encoded data.private static voiddoLZWDecode(java.io.InputStream encoded, java.io.OutputStream decoded, boolean earlyChange)protected voidencode(java.io.InputStream rawData, java.io.OutputStream encoded, COSDictionary parameters)private static intfindPatternCode(java.util.List<byte[]> codeTable, byte[] pattern)Find a matching pattern in the code table.-
Methods inherited from class org.apache.pdfbox.filter.Filter
decode, decode, encode, findImageReader, findRasterReader, getCompressionLevel, getDecodeParams
-
-
-
-
Field Detail
-
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:
- Constant Field Values
-
EOD
public static final long EOD
The LZW end of data code.- See Also:
- Constant Field Values
-
INITIAL_CODE_TABLE
private static final java.util.List<byte[]> INITIAL_CODE_TABLE
-
-
Method Detail
-
decode
public DecodeResult decode(java.io.InputStream encoded, java.io.OutputStream decoded, COSDictionary parameters, int index) throws java.io.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:
java.io.IOException- if the stream cannot be decoded
-
doLZWDecode
private static void doLZWDecode(java.io.InputStream encoded, java.io.OutputStream decoded, boolean earlyChange) throws java.io.IOException- Throws:
java.io.IOException
-
encode
protected void encode(java.io.InputStream rawData, java.io.OutputStream encoded, COSDictionary parameters) throws java.io.IOException
-
findPatternCode
private static int findPatternCode(java.util.List<byte[]> codeTable, byte[] pattern)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
private static java.util.List<byte[]> createCodeTable()
Init the code table with 1 byte entries and the EOD and CLEAR_TABLE markers.
-
createInitialCodeTable
private static java.util.List<byte[]> 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
-
-