java.lang.Object
org.sejda.sambox.input.ContentStreamParser
- All Implemented Interfaces:
Closeable,AutoCloseable
Component responsible for parsing a content stream to extract operands and such.
- Author:
- Andrea Vacondio
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionContentStreamParser(org.sejda.io.SeekableSource source) ContentStreamParser(PDContentStream stream) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes theSeekableSourcethis reader was created from.booleanisNextToken(String... values) longlength()voidoffset(long offset) adds an offset to the sourcelongposition()voidposition(long offset) seeks to the given offsetintreads an integer and throws anIOExceptionif the integer value has more than the maximum object revision (i.e.final StringReads a token conforming with PDF Hexadecimal Strings chap 7.3.4.3 PDF 32000-1:2008.intreadInt()final StringReads a token conforming with a PDF Integer object defined in Numeric Objects chap 7.3.3 PDF 32000-1:2008.readLine()Reads bytes until the first end of line marker occurs.Reads a token conforming with PDF Literal Strings chap 7.3.4.2 PDF 32000-1:2008.longreadLong()readName()Reads a token conforming with PDF Name Objects chap 7.3.5 PDF 32000-1:2008.final StringReads a token conforming with PDF Numeric Objects chap 7.3.3 PDF 32000-1:2008.longReads a long and throws anIOExceptionif the long value is negative or has more than 10 digits (i.e.voidskipExpected(char ec) Skips one char and throws an exception if it is not the expected value.final voidskipExpected(String expected) Skips the expected given StringvoidSkips an indirect object definition open tag (Ex.voidSkips an indirect object definition open tag (Ex.voidSkips all spaces and comments that are present.booleanskipTokenIfValue(String... values) Skips the next token if it's value is one of the given onesorg.sejda.io.SeekableSourcesource()tokens()voidunreadIfValid(int c) Unreads the given character if it's not -1voidUnreads white spacesvoidUnreads characters until it finds a white space
-
Field Details
-
OBJ
- See Also:
-
-
Constructor Details
-
ContentStreamParser
- Throws:
IOException
-
ContentStreamParser
public ContentStreamParser(org.sejda.io.SeekableSource source)
-
-
Method Details
-
tokens
- Returns:
- a list of tokens retrieved parsing the source this parser was created from.
- Throws:
IOException
-
nextParsedToken
- Returns:
- the next token parsed from the content stream
- Throws:
IOException
-
close
Closes theSeekableSourcethis reader was created from.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
source
public org.sejda.io.SeekableSource source()- Returns:
- the source for this reader
-
position
- Returns:
- the current position
- Throws:
IOException
-
offset
adds an offset to the source- Parameters:
offset-- Throws:
IOException
-
position
seeks to the given offset- Parameters:
offset- the new offset- Throws:
IOException
-
length
public long length()- Returns:
- the source length
-
skipExpected
Skips the expected given String- Parameters:
expected- the String value that is expected.- Throws:
IOException- if the String char is not the expected value or if an I/O error occurs.
-
skipExpected
Skips one char and throws 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.
-
skipTokenIfValue
Skips the next token if it's value is one of the given ones- Parameters:
values- the values to skip- Returns:
- true if the token is found and skipped, false otherwise.
- Throws:
IOException- if there is an error reading from the stream
-
skipIndirectObjectDefinition
Skips an indirect object definition open tag (Ex. "12 0 obj") as defined in the chap 7.3.10 PDF 32000-1:2008.- Throws:
IOException- if we are reading a not valid indirect object definition open tag
-
skipExpectedIndirectObjectDefinition
Skips an indirect object definition open tag (Ex. "12 0 obj") as defined in the chap 7.3.10 PDF 32000-1:2008.- Parameters:
expected- object we are expecting to find- Throws:
IOException- if we are reading a not valid indirect object definition open tag or the object number or generation number don't match the expected object
-
readToken
- Returns:
- The next token that was read from the stream.
- Throws:
IOException- If there is an error reading from the stream.- See Also:
-
unreadSpaces
Unreads white spaces- Throws:
IOException
-
unreadUntilSpaces
Unreads characters until it finds a white space- Throws:
IOException
-
isNextToken
- Parameters:
values- values for the next token.- Returns:
- true if the next token is one of the given values. false otherwise.
- Throws:
IOException- if there is an error reading from the stream
-
readLine
Reads 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.
-
readObjectNumber
Reads a long and throws anIOExceptionif 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
reads an integer and throws anIOExceptionif 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
-
readName
Reads a token conforming with PDF Name Objects chap 7.3.5 PDF 32000-1:2008.- Returns:
- the generation number being read.
- Throws:
IOException- if an I/O error occurs
-
readInt
- Returns:
- The integer that was read from the stream.
- Throws:
IOException- If there is an error reading from the stream.
-
readLong
- Returns:
- The long that was read from the stream.
- Throws:
IOException- If there is an error reading from the stream.
-
readIntegerNumber
Reads a token conforming with a PDF Integer object defined in Numeric Objects chap 7.3.3 PDF 32000-1:2008.- Returns:
- the token to parse as
IntegerorLong. - Throws:
IOException- If there is an error reading from the stream.
-
readNumber
Reads a token conforming with PDF Numeric Objects chap 7.3.3 PDF 32000-1:2008.- Returns:
- the token to parse as integer or real number.
- Throws:
IOException- If there is an error reading from the stream.
-
readHexString
Reads a token conforming with PDF Hexadecimal Strings chap 7.3.4.3 PDF 32000-1:2008. Any non hexadecimal char found while parsing the token is replace with the default '0' hex char.- Returns:
- the token to parse as an hexadecimal string
- Throws:
IOException- If there is an error reading from the stream.
-
readLiteralString
Reads a token conforming with PDF Literal Strings chap 7.3.4.2 PDF 32000-1:2008.- Returns:
- the token to parse as a literal string
- Throws:
IOException- If there is an error during parsing.
-
skipSpaces
Skips all spaces and comments that are present.- Throws:
IOException- If there is an error reading from the stream.
-
unreadIfValid
Unreads the given character if it's not -1- Parameters:
c-- Throws:
IOException
-