Package org.apache.pdfbox.pdfparser
Class BruteForceParser
- java.lang.Object
-
- org.apache.pdfbox.pdfparser.BaseParser
-
- org.apache.pdfbox.pdfparser.COSParser
-
- org.apache.pdfbox.pdfparser.BruteForceParser
-
- All Implemented Interfaces:
ICOSParser
public class BruteForceParser extends COSParser
Brute force parser to be used as last resort if a malformed pdf can't be read.
-
-
Field Summary
-
Fields inherited from class org.apache.pdfbox.pdfparser.COSParser
fileLen, initialParseDone, securityHandler, SYSPROP_EOFLOOKUPRANGE, xrefTrailerResolver
-
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, N, O, R, S, source, STREAM_STRING, T
-
-
Constructor Summary
Constructors Constructor Description BruteForceParser(org.apache.pdfbox.io.RandomAccessRead source, COSDocument document)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbfSearchForObjStreams(XrefTrailerResolver trailerResolver, SecurityHandler<? extends ProtectionPolicy> securityHandler)Brute force search for all objects streams of a pdf.protected longbfSearchForXRef(long xrefOffset)Search for the offset of the given xref table/stream among those found by a brute force search.booleanbfSearchTriggered()Indicates whether the brute force search for objects was triggered.protected java.util.Map<COSObjectKey,java.lang.Long>getBFCOSObjectOffsets()Returns all found objects of a brute force search.protected COSDictionaryrebuildTrailer(XrefTrailerResolver trailerResolver, SecurityHandler<? extends ProtectionPolicy> securityHandler)Rebuild the trailer dictionary if startxref can't be found.-
Methods inherited from class org.apache.pdfbox.pdfparser.COSParser
checkPages, createRandomAccessReadView, dereferenceCOSObject, getAccessPermission, getEncryption, isLenient, isString, lastIndexOf, parseCOSStream, parseFDFHeader, parseObjectDynamically, parseObjectStreamObject, parsePDFHeader, parseXrefTable, prepareDecryption, resetTrailerResolver, retrieveTrailer, setEOFLookupRange, setLenient
-
Methods inherited from class org.apache.pdfbox.pdfparser.BaseParser
getObjectKey, isClosing, isClosing, isDigit, isDigit, isEndOfName, isEOF, isEOL, isEOL, isSpace, isSpace, isWhitespace, isWhitespace, parseCOSArray, parseCOSDictionary, parseCOSName, parseCOSString, parseDirObject, readExpectedChar, readExpectedString, readGenerationNumber, readInt, readLine, readLong, readObjectNumber, readString, readString, readStringNumber, skipLinebreak, skipSpaces, skipWhiteSpaces
-
-
-
-
Constructor Detail
-
BruteForceParser
public BruteForceParser(org.apache.pdfbox.io.RandomAccessRead source, COSDocument document) throws java.io.IOExceptionConstructor. Triggers a brute force search for all objects of the document.- Parameters:
source- input representing the pdf.document- the corresponding COS document- Throws:
java.io.IOException- if the source data could not be read
-
-
Method Detail
-
bfSearchTriggered
public boolean bfSearchTriggered()
Indicates whether the brute force search for objects was triggered.- Returns:
- true if the search was triggered
-
getBFCOSObjectOffsets
protected java.util.Map<COSObjectKey,java.lang.Long> getBFCOSObjectOffsets() throws java.io.IOException
Returns all found objects of a brute force search.- Returns:
- map containing all found objects of a brute force search
- Throws:
java.io.IOException- if something went wrong
-
bfSearchForXRef
protected long bfSearchForXRef(long xrefOffset) throws java.io.IOExceptionSearch for the offset of the given xref table/stream among those found by a brute force search.- Parameters:
xrefOffset- the given offset to be searched for- Returns:
- the offset of the xref entry
- Throws:
java.io.IOException- if something went wrong
-
bfSearchForObjStreams
protected void bfSearchForObjStreams(XrefTrailerResolver trailerResolver, SecurityHandler<? extends ProtectionPolicy> securityHandler) throws java.io.IOException
Brute force search for all objects streams of a pdf.- Parameters:
trailerResolver- the trailer resolver of the documentsecurityHandler- security handler to be used to decrypt encrypted documents- Throws:
java.io.IOException- if something went wrong
-
rebuildTrailer
protected COSDictionary rebuildTrailer(XrefTrailerResolver trailerResolver, SecurityHandler<? extends ProtectionPolicy> securityHandler) throws java.io.IOException
Rebuild the trailer dictionary if startxref can't be found.- Parameters:
trailerResolver- the trailer resolver of the documentsecurityHandler- security handler to be used to decrypt encrypted documents- Returns:
- the rebuild trailer dictionary
- Throws:
java.io.IOException- if something went wrong
-
-