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

public Class PDFStreamParser

extends BaseParser
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .IOException, java.util.ArrayList, .List, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.contentstream.PDContentStream, org.apache.pdfbox.contentstream.operator.Operator, .OperatorName, org.apache.pdfbox.cos.COSBase, .COSBoolean, .COSDictionary, .COSName, .COSNull, .COSNumber, org.apache.pdfbox.io.RandomAccessReadBuffer

This will parse a PDF byte stream and extract operands and such.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private final byte[]
private static final Log
private static final int
Inherited from org.apache.pdfbox.pdfparser.BaseParser:
AASCII_CRASCII_LFBDDEFdocumentEENDOBJ_STRINGENDSTREAM_STRINGJMMAX_LENGTH_LONGNORSsourceSTREAM_STRINGT

Constructor Summary

AccessConstructor and Description
public
PDFStreamParser(PDContentStream
The content stream to parse.
pdContentstream
)

Constructor.

public
PDFStreamParser(byte[]
the bytes to parse.
bytes
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Close the underlying resource.

private boolean

Returns:

true if the next char is a space or a return
hasNextSpaceOrReturn
()

Checks if the next char is a space or a return.

private boolean

Returns:

true if next bytes are probably printable ASCII characters starting with a PDF operator, otherwise false
hasNoFollowingBinData
()

Looks up an amount of bytes if they contain only ASCII characters (no control sequences etc.), and that these ASCII characters begin with a sequence of 1-3 non-blank characters between blanks

private boolean
public List<Object>

Returns:

All of the tokens in the stream.
parse
()

This will parse all the tokens in the stream.

public Object

Returns:

The next token in the stream or null if there are no more tokens in the stream.
parseNextToken
()

This will parse the next token in the stream.

private String

Returns:

The operator that was read from the stream.
readOperator
()

This will read an operator from the stream.

Inherited from org.apache.pdfbox.pdfparser.BaseParser:
getObjectKeyisClosingisClosingisDigitisDigitisEndOfNameisEOFisEOLisEOLisSpaceisSpaceisWhitespaceisWhitespaceparseCOSArrayparseCOSDictionaryparseCOSNameparseCOSStringparseDirObjectreadExpectedCharreadExpectedStringreadGenerationNumberreadIntreadLinereadLongreadObjectNumberreadStringreadStringreadStringNumberskipSpacesskipWhiteSpaces

Field Detail

binCharTestArrback to summary
private final byte[] binCharTestArr
LOGback to summary
private static final Log LOG

Hides org.apache.pdfbox.pdfparser.BaseParser.LOG.

Log instance.

MAX_BIN_CHAR_TEST_LENGTHback to summary
private static final int MAX_BIN_CHAR_TEST_LENGTH

Constructor Detail

PDFStreamParserback to summary
public PDFStreamParser(PDContentStream pdContentstream) throws IOException

Constructor.

Parameters
pdContentstream:PDContentStream

The content stream to parse.

Exceptions
IOException:
If there is an error initializing the stream.
PDFStreamParserback to summary
public PDFStreamParser(byte[] bytes)

Constructor.

Parameters
bytes:byte[]

the bytes to parse.

Method Detail

closeback to summary
public void close() throws IOException

Close the underlying resource.

Exceptions
IOException:
if something went wrong
hasNextSpaceOrReturnback to summary
private boolean hasNextSpaceOrReturn() throws IOException

Checks if the next char is a space or a return.

Returns:boolean

true if the next char is a space or a return

Exceptions
IOException:
if something went wrong
hasNoFollowingBinDataback to summary
private boolean hasNoFollowingBinData() throws IOException

Looks up an amount of bytes if they contain only ASCII characters (no control sequences etc.), and that these ASCII characters begin with a sequence of 1-3 non-blank characters between blanks

Returns:boolean

true if next bytes are probably printable ASCII characters starting with a PDF operator, otherwise false

isSpaceOrReturnback to summary
private boolean isSpaceOrReturn(int c)
parseback to summary
public List<Object> parse() throws IOException

This will parse all the tokens in the stream. This will close the stream when it is finished parsing.

Returns:List<Object>

All of the tokens in the stream.

Exceptions
IOException:
If there is an error while parsing the stream.
parseNextTokenback to summary
public Object parseNextToken() throws IOException

This will parse the next token in the stream.

Returns:Object

The next token in the stream or null if there are no more tokens in the stream.

Exceptions
IOException:
If an io error occurs while parsing the stream.
readOperatorback to summary
private String readOperator() throws IOException

This will read an operator from the stream.

Returns:String

The operator that was read from the stream.

Exceptions
IOException:
If there is an error reading from the stream.