java.lang.Object
org.sejda.sambox.input.SourceReader
org.sejda.sambox.input.BaseCOSParser
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
ContentStreamCOSParser,COSParser
Base parser for COS objects providing methods to get parsed objects from the given
SeekableSource-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringprivate static final org.slf4j.Loggerstatic final StringFields inherited from class org.sejda.sambox.input.SourceReader
OBJ -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanConsumes an invalid dictionary keyprivate longdoFindStreamLength(long start) private longdoStreamLengthFrom(COSBase lengthBaseObj) private longReads from the current position until it finds the "endstream" meaning we're at the end of this stream object.nextName()nextNull()abstract COSBasenextStream(COSDictionary streamDictionary) This will read a COSStream from the input stream using length attribute within dictionary.private longstreamLength(COSDictionary streamDictionary) Retrieves the stream length.private longstreamLengthFrom(COSDictionary streamDictionary) Methods inherited from class org.sejda.sambox.input.SourceReader
close, isNextToken, length, offset, position, position, readGenerationNumber, readHexString, readInt, readIntegerNumber, readLine, readLiteralString, readLong, readName, readNumber, readObjectNumber, readToken, skipExpected, skipExpected, skipExpectedIndirectObjectDefinition, skipIndirectObjectDefinition, skipSpaces, skipTokenIfValue, source, unreadIfValid, unreadSpaces, unreadUntilSpaces
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
ENDOBJ
- See Also:
-
STREAM
- See Also:
-
ENDSTREAM
- See Also:
-
-
Constructor Details
-
BaseCOSParser
BaseCOSParser(org.sejda.io.SeekableSource source)
-
-
Method Details
-
nextParsedToken
- Returns:
- The next parsed basic type object from the stream or null if the next token is not a COSBase. Basic types are defined in Chap 7.3 of PDF 32000-1:2008
- Throws:
IOException- If there is an error during parsing.
-
nextDictionary
- Returns:
- The next parsed dictionary object from the stream. Dictionary objects are defined in Chap 7.3.7 of PDF 32000-1:2008
- Throws:
IOException- If there is an error during parsing.
-
consumeInvalidDictionaryKey
Consumes an invalid dictionary key- Returns:
- true if the dictionary has been recovered and parsing can go on
- Throws:
IOException
-
nextArray
- Returns:
- The next parsed array object from the stream. Array objects are defined in Chap 7.3.6 of PDF 32000-1:2008
- Throws:
IOException- If there is an error during parsing.
-
nextBoolean
- Returns:
- The next parsed boolean object from the stream. Boolean objects are defined in Chap 7.3.2 of PDF 32000-1:2008
- Throws:
IOException- If there is an error during parsing.
-
nextNumber
- Returns:
- The next parsed numeric object from the stream. Numeric objects are defined in Chap 7.3.3 of PDF 32000-1:2008
- Throws:
IOException- If there is an error during parsing.
-
nextNull
- Returns:
- The next parsed null object from the stream. Null object is defined in Chap 7.3.9 of PDF 32000-1:2008
- Throws:
IOException- If there is an error during parsing.
-
nextName
- Returns:
- The next parsed name object from the stream. Name objects are defined in Chap 7.3.5 of PDF 32000-1:2008
- Throws:
IOException- If there is an error during parsing.
-
nextLiteralString
- Returns:
- The next parsed literal string object from the stream. Literal string objects are defined in Chap 7.3.4.2 of PDF 32000-1:2008
- Throws:
IOException- If there is an error during parsing.
-
nextHexadecimalString
- Returns:
- The next parsed hexadecimal string object from the stream. Hexadecimal string objects is defined in Chap 7.3.4.3 of PDF 32000-1:2008
- Throws:
IOException- If there is an error during parsing.
-
nextString
- Returns:
- The next parsed string object from the stream. String objects is defined in Chap 7.3.4 of PDF 32000-1:2008
- Throws:
IOException- If there is an error during parsing.
-
nextStream
This will read a COSStream from the input stream using length attribute within dictionary. If length attribute is a indirect reference it is first resolved to get the stream length. This means we copy stream data without testing for 'endstream' or 'endobj' and thus it is no problem if these keywords occur within stream. We require 'endstream' to be found after stream data is read.- Parameters:
streamDictionary- dictionary that goes with this stream.- Returns:
- parsed pdf stream.
- Throws:
IOException- if an error occurred reading the stream, like problems with reading length attribute, stream does not end with 'endstream' after data read, stream too short etc.
-
streamLength
Retrieves the stream length. It gets it from the dictionary, if not present there it applies fallback strategy searching for endstream or endobj keywords.- Parameters:
streamDictionary-- Returns:
- the length
- Throws:
IOException
-
streamLengthFrom
- Parameters:
streamDictionary-- Returns:
- the stream length if found in the dictionary. -1 if nothing is found or if the length is incorrect.
- Throws:
IOException
-
doStreamLengthFrom
- Throws:
IOException
-
findStreamLength
Reads from the current position until it finds the "endstream" meaning we're at the end of this stream object. Some pdf files, however, forget to write some endstream tags and just close off objects with an "endobj" tag so we have to handle this case as well.- Returns:
- the length from the current position to the position where "endstream" or "endobj" was found
- Throws:
IOException
-
doFindStreamLength
- Throws:
IOException
-