Top Description Fields Constructors Methods
org.apache.pdfbox.filter

public Class LZWFilter

extends Filter
Class Inheritance
Imports
java.io.EOFException, .IOException, .InputStream, .OutputStream, java.util.ArrayList, .Arrays, .List, javax.imageio.stream.MemoryCacheImageInputStream, .MemoryCacheImageOutputStream, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.cos.COSDictionary, .COSName

This is the filter used for the LZWDecode filter.
Authors
Ben Litchfield, Tilman Hausherr

Field Summary

Modifier and TypeField and Description
public static final long
CLEAR_TABLE

The LZW clear table code.

public static final long
EOD

The LZW end of data code.

private static final List<byte[]>
private static final Log
Inherited from org.apache.pdfbox.filter.Filter:
SYSPROP_DEFLATELEVEL

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static int

Returns:

a value between 9 and 12
calculateChunk
(int
the size of the code table
tabSize
,
boolean
true for early chunk increase
earlyChange
)

Calculate the appropriate chunk size

private static void
checkIndexBounds(List<byte[]> codeTable, long index, MemoryCacheImageInputStream in)

private static List<byte[]>
createCodeTable()

Init the code table with 1 byte entries and the EOD and CLEAR_TABLE markers.

private static List<byte[]>
public DecodeResult
decode(InputStream
the encoded byte stream
encoded
,
OutputStream
the stream where decoded data will be written
decoded
,
COSDictionary
the parameters used for decoding
parameters
,
int
the index to the filter being decoded
index
)

Implements abstract org.apache.pdfbox.filter.Filter.decode.

Decodes data, producing the original non-encoded data.

private static void
doLZWDecode(InputStream encoded, OutputStream decoded, boolean earlyChange)

protected void
encode(InputStream rawData, OutputStream encoded, COSDictionary parameters)

Implements abstract org.apache.pdfbox.filter.Filter.encode.

private static int

Returns:

The index of the matching pattern or -1 if nothing is found.
findPatternCode
(List<byte[]>
The LZW code table.
codeTable
,
byte[]
The pattern to be searched for.
pattern
)

Find a matching pattern in the code table.

Inherited from org.apache.pdfbox.filter.Filter:
decodedecodeencodefindImageReaderfindRasterReadergetCompressionLevelgetDecodeParams

Field Detail

CLEAR_TABLEback to summary
public static final long CLEAR_TABLE

The LZW clear table code.

EODback to summary
public static final long EOD

The LZW end of data code.

INITIAL_CODE_TABLEback to summary
private static final List<byte[]> INITIAL_CODE_TABLE
LOGback to summary
private static final Log LOG

Hides org.apache.pdfbox.filter.Filter.LOG.

Log instance.

Constructor Detail

LZWFilterback to summary
public LZWFilter()

Method Detail

calculateChunkback to summary
private static int calculateChunk(int tabSize, boolean earlyChange)

Calculate the appropriate chunk size

Parameters
tabSize:int

the size of the code table

earlyChange:boolean

true for early chunk increase

Returns:int

a value between 9 and 12

checkIndexBoundsback to summary
private static void checkIndexBounds(List<byte[]> codeTable, long index, MemoryCacheImageInputStream in) throws IOException
createCodeTableback to summary
private static List<byte[]> createCodeTable()

Init the code table with 1 byte entries and the EOD and CLEAR_TABLE markers.

createInitialCodeTableback to summary
private static List<byte[]> createInitialCodeTable()
decodeback to summary
public DecodeResult decode(InputStream encoded, OutputStream decoded, COSDictionary parameters, int index) throws IOException

Implements abstract org.apache.pdfbox.filter.Filter.decode.

Doc from org.apache.pdfbox.filter.Filter.decode.

Decodes data, producing the original non-encoded data.

Parameters
encoded:InputStream

the encoded byte stream

decoded:OutputStream

the stream where decoded data will be written

parameters:COSDictionary

the parameters used for decoding

index:int

the index to the filter being decoded

Returns:DecodeResult

repaired parameters dictionary, or the original parameters dictionary

Annotations
@Override
Exceptions
IOException:
if the stream cannot be decoded
doLZWDecodeback to summary
private static void doLZWDecode(InputStream encoded, OutputStream decoded, boolean earlyChange) throws IOException
encodeback to summary
protected void encode(InputStream rawData, OutputStream encoded, COSDictionary parameters) throws IOException

Implements abstract org.apache.pdfbox.filter.Filter.encode.

Annotations
@Override
findPatternCodeback to summary
private static int findPatternCode(List<byte[]> codeTable, byte[] pattern)

Find a matching pattern in the code table.

Parameters
codeTable:List<byte[]>

The LZW code table.

pattern:byte[]

The pattern to be searched for.

Returns:int

The index of the matching pattern or -1 if nothing is found.