Package org.apache.pdfbox.pdfparser
Class BaseParser
java.lang.Object
org.apache.pdfbox.pdfparser.BaseParser
- Direct Known Subclasses:
COSParser
,PDFObjectStreamParser
,PDFStreamParser
,PDFXrefStreamParser
This class is used to contain parsing logic that will be used by both the
PDFParser and the COSStreamParser.
- Author:
- Ben Litchfield
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
protected static final byte
ASCII code for carriage return.protected static final byte
ASCII code for line feed.protected static final int
protected static final int
static final String
This is a string constant that will be used for comparisons.protected COSDocument
This is the document that will be parsed.protected static final int
protected static final String
This is a string constant that will be used for comparisons.protected static final String
This is a string constant that will be used for comparisons.protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final String
This is a string constant that will be used for comparisons.protected static final int
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
This will tell if the next character is a closing brace( close of PDF array ).protected boolean
isClosing
(int c) This will tell if the next character is a closing brace( close of PDF array ).protected boolean
isDigit()
This will tell if the next byte is a digit or not.protected static boolean
isDigit
(int c) This will tell if the given value is a digit or not.protected boolean
isEndOfName
(int ch) Determine if a character terminates a PDF name.protected boolean
isEOL()
This will tell if the next byte to be read is an end of line byte.protected boolean
isEOL
(int c) This will tell if the next byte to be read is an end of line byte.protected boolean
isSpace()
This will tell if the next byte is a space or not.protected boolean
isSpace
(int c) This will tell if the given value is a space or not.protected boolean
This will tell if the next byte is whitespace or not.protected boolean
isWhitespace
(int c) This will tell if a character is whitespace or not.protected COSBoolean
This will parse a boolean object from the stream.protected COSArray
This will parse a PDF array object.protected COSDictionary
This will parse a PDF dictionary.protected COSName
This will parse a PDF name from the stream.protected COSString
This will parse a PDF string.protected COSBase
This will parse a directory object from the stream.protected void
readExpectedChar
(char ec) Read one char and throw an exception if it is not the expected value.protected final void
readExpectedString
(char[] expectedString, boolean skipSpaces) Reads given pattern fromseqSource
.protected void
readExpectedString
(String expectedString) Read one String and throw an exception if it is not the expected value.protected int
This will read a integer from the Stream and throw anIllegalArgumentException
if the integer value has more than the maximum object revision (i.e.protected int
readInt()
This will read an integer from the stream.protected String
readLine()
This will read bytes until the first end of line marker occurs.protected long
readLong()
This will read an long from the stream.protected long
This will read a long from the Stream and throw anIOException
if the long value is negative or has more than 10 digits (i.e.protected String
This will read the next string from the stream.protected String
readString
(int length) This will read the next string from the stream up to a certain length.protected final StringBuilder
This method is used to read a token by the readInt() and the readLong() method.protected void
This will skip all spaces and comments that are present.protected void
-
Field Details
-
E
protected static final int E- See Also:
-
N
protected static final int N- See Also:
-
D
protected static final int D- See Also:
-
S
protected static final int S- See Also:
-
T
protected static final int T- See Also:
-
R
protected static final int R- See Also:
-
A
protected static final int A- See Also:
-
M
protected static final int M- See Also:
-
O
protected static final int O- See Also:
-
B
protected static final int B- See Also:
-
J
protected static final int J- See Also:
-
DEF
This is a string constant that will be used for comparisons.- See Also:
-
ENDOBJ_STRING
This is a string constant that will be used for comparisons.- See Also:
-
ENDSTREAM_STRING
This is a string constant that will be used for comparisons.- See Also:
-
STREAM_STRING
This is a string constant that will be used for comparisons.- See Also:
-
ASCII_LF
protected static final byte ASCII_LFASCII code for line feed.- See Also:
-
ASCII_CR
protected static final byte ASCII_CRASCII code for carriage return.- See Also:
-
document
This is the document that will be parsed.
-
-
Method Details
-
parseCOSDictionary
This will parse a PDF dictionary.- Returns:
- The parsed dictionary, never null.
- Throws:
IOException
- If there is an error reading the stream.
-
skipWhiteSpaces
- Throws:
IOException
-
parseCOSString
This will parse a PDF string.- Returns:
- The parsed PDF string.
- Throws:
IOException
- If there is an error reading from the stream.
-
parseCOSArray
This will parse a PDF array object.- Returns:
- The parsed PDF array.
- Throws:
IOException
- If there is an error parsing the stream.
-
isEndOfName
protected boolean isEndOfName(int ch) Determine if a character terminates a PDF name.- Parameters:
ch
- The character- Returns:
- true if the character terminates a PDF name, otherwise false.
-
parseCOSName
This will parse a PDF name from the stream.- Returns:
- The parsed PDF name.
- Throws:
IOException
- If there is an error reading from the stream.
-
parseBoolean
This will parse a boolean object from the stream.- Returns:
- The parsed boolean object.
- Throws:
IOException
- If an IO error occurs during parsing.
-
parseDirObject
This will parse a directory object from the stream.- Returns:
- The parsed object.
- Throws:
IOException
- If there is an error during parsing.
-
readString
This will read the next string from the stream.- Returns:
- The string that was read from the stream, never null.
- Throws:
IOException
- If there is an error reading from the stream.
-
readExpectedString
Read one String and throw an exception if it is not the expected value.- Parameters:
expectedString
- the String value that is expected.- Throws:
IOException
- if the String char is not the expected value or if an I/O error occurs.
-
readExpectedString
protected final void readExpectedString(char[] expectedString, boolean skipSpaces) throws IOException Reads given pattern fromseqSource
. Skipping whitespace at start and end if wanted.- Parameters:
expectedString
- pattern to be skippedskipSpaces
- if set to true spaces before and after the string will be skipped- Throws:
IOException
- if pattern could not be read
-
readExpectedChar
Read one char and throw an exception if it is not the expected value.- Parameters:
ec
- the char value that is expected.- Throws:
IOException
- if the read char is not the expected value or if an I/O error occurs.
-
readString
This will read the next string from the stream up to a certain length.- Parameters:
length
- The length to stop reading at.- Returns:
- The string that was read from the stream of length 0 to length.
- Throws:
IOException
- If there is an error reading from the stream.
-
isClosing
This will tell if the next character is a closing brace( close of PDF array ).- Returns:
- true if the next byte is ']', false otherwise.
- Throws:
IOException
- If an IO error occurs.
-
isClosing
protected boolean isClosing(int c) This will tell if the next character is a closing brace( close of PDF array ).- Parameters:
c
- The character to check against end of line- Returns:
- true if the next byte is ']', false otherwise.
-
readLine
This will read bytes until the first end of line marker occurs. NOTE: The EOL marker may consists of 1 (CR or LF) or 2 (CR and CL) bytes which is an important detail if one wants to unread the line.- Returns:
- The characters between the current position and the end of the line.
- Throws:
IOException
- If there is an error reading from the stream.
-
isEOL
This will tell if the next byte to be read is an end of line byte.- Returns:
- true if the next byte is 0x0A or 0x0D.
- Throws:
IOException
- If there is an error reading from the stream.
-
isEOL
protected boolean isEOL(int c) This will tell if the next byte to be read is an end of line byte.- Parameters:
c
- The character to check against end of line- Returns:
- true if the next byte is 0x0A or 0x0D.
-
isWhitespace
This will tell if the next byte is whitespace or not.- Returns:
- true if the next byte in the stream is a whitespace character.
- Throws:
IOException
- If there is an error reading from the stream.
-
isWhitespace
protected boolean isWhitespace(int c) This will tell if a character is whitespace or not. These values are specified in table 1 (page 12) of ISO 32000-1:2008.- Parameters:
c
- The character to check against whitespace- Returns:
- true if the character is a whitespace character.
-
isSpace
This will tell if the next byte is a space or not.- Returns:
- true if the next byte in the stream is a space character.
- Throws:
IOException
- If there is an error reading from the stream.
-
isSpace
protected boolean isSpace(int c) This will tell if the given value is a space or not.- Parameters:
c
- The character to check against space- Returns:
- true if the next byte in the stream is a space character.
-
isDigit
This will tell if the next byte is a digit or not.- Returns:
- true if the next byte in the stream is a digit.
- Throws:
IOException
- If there is an error reading from the stream.
-
isDigit
protected static boolean isDigit(int c) This will tell if the given value is a digit or not.- Parameters:
c
- The character to be checked- Returns:
- true if the next byte in the stream is a digit.
-
skipSpaces
This will skip all spaces and comments that are present.- Throws:
IOException
- If there is an error reading from the stream.
-
readObjectNumber
This will read a long from the Stream and throw anIOException
if the long value is negative or has more than 10 digits (i.e. : bigger thanOBJECT_NUMBER_THRESHOLD
)- Returns:
- the object number being read.
- Throws:
IOException
- if an I/O error occurs
-
readGenerationNumber
This will read a integer from the Stream and throw anIllegalArgumentException
if the integer value has more than the maximum object revision (i.e. : bigger thanGENERATION_NUMBER_THRESHOLD
)- Returns:
- the generation number being read.
- Throws:
IOException
- if an I/O error occurs
-
readInt
This will read an integer from the stream.- Returns:
- The integer that was read from the stream.
- Throws:
IOException
- If there is an error reading from the stream.
-
readLong
This will read an long from the stream.- Returns:
- The long that was read from the stream.
- Throws:
IOException
- If there is an error reading from the stream.
-
readStringNumber
This method is used to read a token by the readInt() and the readLong() method. Valid delimiters are any non digit values.- Returns:
- the token to parse as integer or long by the calling method.
- Throws:
IOException
- throws by theseqSource
methods.
-