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 and Description
`BruteForceParser(org.apache.pdfbox.io.RandomAccessRead source, COSDocument document)` Constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `bfSearchForObjStreams(XrefTrailerResolver trailerResolver, SecurityHandler<? extends ProtectionPolicy> securityHandler)` Brute force search for all objects streams of a pdf.
`protected long` `bfSearchForXRef(long xrefOffset)` Search for the offset of the given xref table/stream among those found by a brute force search.
`boolean` `bfSearchTriggered()` Indicates whether the brute force search for objects was triggered.
`protected Map<COSObjectKey,Long>` `getBFCOSObjectOffsets()` Returns all found objects of a brute force search.
`protected COSDictionary` `rebuildTrailer(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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### BruteForceParser

    public BruteForceParser(org.apache.pdfbox.io.RandomAccessRead source,
                            COSDocument document)
                     throws IOException

Constructor. Triggers a brute force search for all objects of the document.

Parameters:
  `source` - input representing the pdf.
  `document` - the corresponding COS document
Throws:
  `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 Map<COSObjectKey,Long> getBFCOSObjectOffsets()
                                                    throws IOException

Returns all found objects of a brute force search.

Returns:
  map containing all found objects of a brute force search
Throws:
  `IOException` - if something went wrong

#### bfSearchForXRef

    protected long bfSearchForXRef(long xrefOffset)
                            throws IOException

Search 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:
  `IOException` - if something went wrong

#### bfSearchForObjStreams

    protected void bfSearchForObjStreams(XrefTrailerResolver trailerResolver,
                                         SecurityHandler<? extends ProtectionPolicy> securityHandler)
                                  throws IOException

Brute force search for all objects streams of a pdf.

Parameters:
  `trailerResolver` - the trailer resolver of the document
  `securityHandler` - security handler to be used to decrypt encrypted documents
Throws:
  `IOException` - if something went wrong

#### rebuildTrailer

    protected COSDictionary rebuildTrailer(XrefTrailerResolver trailerResolver,
                                           SecurityHandler<? extends ProtectionPolicy> securityHandler)
                                    throws IOException

Rebuild the trailer dictionary if startxref can't be found.

Parameters:
  `trailerResolver` - the trailer resolver of the document
  `securityHandler` - security handler to be used to decrypt encrypted documents
Returns:
  the rebuild trailer dictionary
Throws:
  `IOException` - if something went wrong