Package org.apache.pdfbox.pdfparser
Class PDFStreamParser
- java.lang.Object
-
- org.apache.pdfbox.pdfparser.BaseParser
-
- org.apache.pdfbox.pdfparser.PDFStreamParser
-
public class PDFStreamParser extends BaseParser
This will parse a PDF byte stream and extract operands and such.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]binCharTestArrprivate static org.apache.commons.logging.LogLOGLog instance.private static intMAX_BIN_CHAR_TEST_LENGTHprivate java.util.List<java.lang.Object>streamObjects-
Fields inherited from class org.apache.pdfbox.pdfparser.BaseParser
A, ASCII_CR, ASCII_LF, B, D, DEF, document, E, ENDOBJ_STRING, ENDSTREAM_STRING, J, M, MAX_LENGTH_LONG, N, O, R, S, seqSource, STREAM_STRING, T
-
-
Constructor Summary
Constructors Constructor Description PDFStreamParser(byte[] bytes)Constructor.PDFStreamParser(PDContentStream contentStream)Constructor.PDFStreamParser(COSStream stream)Deprecated.UsePDFStreamParser(PDContentStream)instead.PDFStreamParser(PDStream stream)Deprecated.UsePDFStreamParser(PDContentStream)instead.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<java.lang.Object>getTokens()This will get the tokens that were parsed from the stream by theparse()method.private booleanhasNextSpaceOrReturn()Checks if the next char is a space or a return.private booleanhasNoFollowingBinData(SequentialSource pdfSource)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 blanksprivate booleanisSpaceOrReturn(int c)voidparse()This will parse all the tokens in the stream.java.lang.ObjectparseNextToken()This will parse the next token in the stream.protected java.lang.StringreadOperator()This will read an operator from the stream.-
Methods inherited from class org.apache.pdfbox.pdfparser.BaseParser
isClosing, isClosing, isDigit, isDigit, isEndOfName, isEOL, isEOL, isSpace, isSpace, isWhitespace, isWhitespace, parseBoolean, parseCOSArray, parseCOSDictionary, parseCOSName, parseCOSString, parseDirObject, readExpectedChar, readExpectedString, readExpectedString, readGenerationNumber, readInt, readLine, readLong, readObjectNumber, readString, readString, readStringNumber, skipSpaces, skipWhiteSpaces
-
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
Log instance.
-
streamObjects
private final java.util.List<java.lang.Object> streamObjects
-
MAX_BIN_CHAR_TEST_LENGTH
private static final int MAX_BIN_CHAR_TEST_LENGTH
- See Also:
- Constant Field Values
-
binCharTestArr
private final byte[] binCharTestArr
-
-
Constructor Detail
-
PDFStreamParser
@Deprecated public PDFStreamParser(PDStream stream) throws java.io.IOException
Deprecated.UsePDFStreamParser(PDContentStream)instead.Constructor.- Parameters:
stream- The stream to parse.- Throws:
java.io.IOException- If there is an error initializing the stream.
-
PDFStreamParser
@Deprecated public PDFStreamParser(COSStream stream) throws java.io.IOException
Deprecated.UsePDFStreamParser(PDContentStream)instead.Constructor.- Parameters:
stream- The stream to parse.- Throws:
java.io.IOException- If there is an error initializing the stream.
-
PDFStreamParser
public PDFStreamParser(PDContentStream contentStream) throws java.io.IOException
Constructor.- Parameters:
contentStream- The content stream to parse.- Throws:
java.io.IOException- If there is an error initializing the stream.
-
PDFStreamParser
public PDFStreamParser(byte[] bytes) throws java.io.IOExceptionConstructor.- Parameters:
bytes- the bytes to parse.- Throws:
java.io.IOException- If there is an error initializing the stream.
-
-
Method Detail
-
parse
public void parse() throws java.io.IOExceptionThis will parse all the tokens in the stream. This will close the stream when it is finished parsing. You can then access these withgetTokens().- Throws:
java.io.IOException- If there is an error while parsing the stream.
-
getTokens
public java.util.List<java.lang.Object> getTokens()
This will get the tokens that were parsed from the stream by theparse()method.- Returns:
- All of the tokens in the stream.
-
parseNextToken
public java.lang.Object parseNextToken() throws java.io.IOExceptionThis will parse the next token in the stream.- Returns:
- The next token in the stream or null if there are no more tokens in the stream.
- Throws:
java.io.IOException- If an io error occurs while parsing the stream.
-
hasNoFollowingBinData
private boolean hasNoFollowingBinData(SequentialSource pdfSource) throws java.io.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:
trueif next bytes are probably printable ASCII characters starting with a PDF operator, otherwisefalse- Throws:
java.io.IOException
-
readOperator
protected java.lang.String readOperator() throws java.io.IOExceptionThis will read an operator from the stream.- Returns:
- The operator that was read from the stream.
- Throws:
java.io.IOException- If there is an error reading from the stream.
-
isSpaceOrReturn
private boolean isSpaceOrReturn(int c)
-
hasNextSpaceOrReturn
private boolean hasNextSpaceOrReturn() throws java.io.IOExceptionChecks if the next char is a space or a return.- Returns:
- true if the next char is a space or a return
- Throws:
java.io.IOException- if something went wrong
-
-