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

public final Class Predictor

extends Object
Class Inheritance
Imports
java.io.FilterOutputStream, .IOException, .OutputStream, java.util.Arrays, org.apache.pdfbox.cos.COSDictionary, .COSName

Helper class to contain predictor decoding used by Flate and LZW filter. To see the history, look at the FlateFilter class.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Predictor.PredictorOutputStream

Output stream that implements predictor decoding.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static int
calcSetBitSeq(int by, int startBit, int bitSize, int val)

pack-priv static int
calculateRowLength(int colors, int bitsPerComponent, int columns)

pack-priv static void
decodePredictorRow(int
Predictor value for the current line
predictor
,
int
Number of color components, from decode parameters.
colors
,
int
Number of bits per components, from decode parameters.
bitsPerComponent
,
int
Number samples in a row, from decode parameters.
columns
,
byte[]
Current (active) line to decode. Data will be decoded in-place, i.e. - the contents of this buffer will be modified.
actline
,
byte[]
The previous decoded line. When decoding the first line, this parameter should be an empty byte array of the same length as actline.
lastline
)

Decodes a single line of data in-place.

pack-priv static int
getBitSeq(int by, int startBit, int bitSize)

pack-priv static OutputStream

Returns:

An OutputStream is returned, which will write decoded data into the given stream. If no predictor is specified, the original stream is returned.
wrapPredictor
(OutputStream
The stream to which decoded data should be written
out
,
COSDictionary
Decode parameters for the stream
decodeParams
)

Wraps and OutputStream in a predictor decoding stream as necessary.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Predictorback to summary
private Predictor()

Method Detail

calcSetBitSeqback to summary
pack-priv static int calcSetBitSeq(int by, int startBit, int bitSize, int val)
calculateRowLengthback to summary
pack-priv static int calculateRowLength(int colors, int bitsPerComponent, int columns)
decodePredictorRowback to summary
pack-priv static void decodePredictorRow(int predictor, int colors, int bitsPerComponent, int columns, byte[] actline, byte[] lastline)

Decodes a single line of data in-place.

Parameters
predictor:int

Predictor value for the current line

colors:int

Number of color components, from decode parameters.

bitsPerComponent:int

Number of bits per components, from decode parameters.

columns:int

Number samples in a row, from decode parameters.

actline:byte[]

Current (active) line to decode. Data will be decoded in-place, i.e. - the contents of this buffer will be modified.

lastline:byte[]

The previous decoded line. When decoding the first line, this parameter should be an empty byte array of the same length as actline.

getBitSeqback to summary
pack-priv static int getBitSeq(int by, int startBit, int bitSize)
wrapPredictorback to summary
pack-priv static OutputStream wrapPredictor(OutputStream out, COSDictionary decodeParams)

Wraps and OutputStream in a predictor decoding stream as necessary. If no predictor is specified by the parameters, the original stream is returned as is.

Parameters
out:OutputStream

The stream to which decoded data should be written

decodeParams:COSDictionary

Decode parameters for the stream

Returns:OutputStream

An OutputStream is returned, which will write decoded data into the given stream. If no predictor is specified, the original stream is returned.

org.apache.pdfbox.filter back to summary

private final Class Predictor.PredictorOutputStream

extends FilterOutputStream
Class Inheritance

Output stream that implements predictor decoding. Data is buffered until a complete row is available, which is then decoded and written to the underlying stream. The previous row is retained for decoding the next row.

Field Summary

Modifier and TypeField and Description
private final int
private final int
private final int
private byte[]
private int
private byte[]
private int
private final boolean
private boolean
private final int
Inherited from java.io.FilterOutputStream:
out

Constructor Summary

AccessConstructor and Description
pack-priv
PredictorOutputStream(OutputStream out, int predictor, int colors, int bitsPerComponent, int columns)

Method Summary

Modifier and TypeMethod and Description
private void
private void
flipRows()

Flips the row buffers (to avoid copying), and resets the current-row index and predictorRead flag

public void
flush()

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out to the stream.

public void
write(byte[]
the data to be written.
bytes
)

Overrides java.io.FilterOutputStream.write.

Writes b.length bytes to this output stream.

public void
write(byte[]
the data.
bytes
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.FilterOutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

public void
write(int
the byte.
i
)

Overrides java.io.FilterOutputStream.write.

Writes the specified byte to this output stream.

Inherited from java.io.FilterOutputStream:
close

Field Detail

bitsPerComponentback to summary
private final int bitsPerComponent
colorsback to summary
private final int colors
columnsback to summary
private final int columns
currentRowback to summary
private byte[] currentRow
currentRowDataback to summary
private int currentRowData
lastRowback to summary
private byte[] lastRow
predictorback to summary
private int predictor
predictorPerRowback to summary
private final boolean predictorPerRow
predictorReadback to summary
private boolean predictorRead
rowLengthback to summary
private final int rowLength

Constructor Detail

PredictorOutputStreamback to summary
pack-priv PredictorOutputStream(OutputStream out, int predictor, int colors, int bitsPerComponent, int columns)

Method Detail

decodeAndWriteRowback to summary
private void decodeAndWriteRow() throws IOException
flipRowsback to summary
private void flipRows()

Flips the row buffers (to avoid copying), and resets the current-row index and predictorRead flag

flushback to summary
public void flush() throws IOException

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.FilterOutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out to the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(byte[] bytes) throws IOException

Overrides java.io.FilterOutputStream.write.

Doc from java.io.FilterOutputStream.write.

Writes b.length bytes to this output stream.

Parameters
bytes:byte[]

the data to be written.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(byte[] bytes, int off, int len) throws IOException

Overrides java.io.FilterOutputStream.write.

Doc from java.io.FilterOutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Parameters
bytes:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(int i) throws IOException

Overrides java.io.FilterOutputStream.write.

Doc from java.io.FilterOutputStream.write.

Writes the specified byte to this output stream.

The write method of FilterOutputStream calls the write method of its underlying output stream, that is, it performs out.write(b).

Implements the abstract write method of OutputStream.

Parameters
i:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.