org.apache.pdfbox.preflight.parser

## Class PreflightParser

- java.lang.Object
- - org.apache.pdfbox.pdfparser.BaseParser
  - - org.apache.pdfbox.pdfparser.COSParser
    - - org.apache.pdfbox.pdfparser.PDFParser
      - - org.apache.pdfbox.preflight.parser.PreflightParser

All Implemented Interfaces:
  org.apache.pdfbox.cos.ICOSParser

    public class PreflightParser
    extends org.apache.pdfbox.pdfparser.PDFParser

### Field Summary

### Fields inherited from class org.apache.pdfbox.pdfparser.COSParser

`EOF_MARKER, fileLen, initialParseDone, OBJ_MARKER, 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
`PreflightParser(File file)` Constructor.
`PreflightParser(org.apache.pdfbox.io.RandomAccessRead rar)` Constructor.
`PreflightParser(String filename)` Constructor.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`protected org.apache.pdfbox.pdmodel.PDDocument` `createDocument()`
`protected void` `initialParse()`
`protected int` `lastIndexOf(char[] pattern, byte[] buf, int endOff)`
`org.apache.pdfbox.pdmodel.PDDocument` `parse()`
`org.apache.pdfbox.pdmodel.PDDocument` `parse(Format format)` Parse the given file and check if it is a confirming file according to the given format.
`org.apache.pdfbox.pdmodel.PDDocument` `parse(Format format, PreflightConfiguration config)` Parse the given file and check if it is a confirming file according to the given format.
`protected org.apache.pdfbox.cos.COSArray` `parseCOSArray()`
`protected org.apache.pdfbox.cos.COSName` `parseCOSName()`
`protected org.apache.pdfbox.cos.COSStream` `parseCOSStream(org.apache.pdfbox.cos.COSDictionary dic)` Wraps the `COSParser.parseCOSStream(org.apache.pdfbox.cos.COSDictionary)` to check rules on 'stream' and 'endstream' keywords.
`protected org.apache.pdfbox.cos.COSString` `parseCOSString()` Check that the hexa string contains only an even number of Hexadecimal characters.
`protected org.apache.pdfbox.cos.COSBase` `parseDirObject()` Call `BaseParser.parseDirObject()` check limit range for Float, Integer and number of Dictionary entries.
`protected org.apache.pdfbox.cos.COSBase` `parseObjectDynamically(org.apache.pdfbox.cos.COSObjectKey objKey, boolean requireExistingNotCompressedObj)`
`protected boolean` `parseXrefTable(long startByteOffset)` Same method than the COSParser.parseXrefTable(long) with additional controls : - EOL mandatory after the 'xref' keyword - Cross reference subsection header uses single white space as separator - and so on
`protected boolean` `resetTrailerResolver()`
`static ValidationResult` `validate(File file)` Load and validate the given file.

### Methods inherited from class org.apache.pdfbox.pdfparser.PDFParser

`load, load, parse`

### Methods inherited from class org.apache.pdfbox.pdfparser.COSParser

`checkPages, createRandomAccessReadView, dereferenceCOSObject, getAccessPermission, getEncryption, isLenient, isString, parseFDFHeader, parseObjectStreamObject, parsePDFHeader, prepareDecryption, 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, parseCOSDictionary, 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

#### PreflightParser

    public PreflightParser(File file)
                    throws IOException

Constructor.

Parameters:
  `file` -
Throws:
  `IOException` - if there is a reading error.

#### PreflightParser

    public PreflightParser(org.apache.pdfbox.io.RandomAccessRead rar)
                    throws IOException

Constructor.

Parameters:
  `rar` - input source
Throws:
  `IOException` - if there is a reading error.

#### PreflightParser

    public PreflightParser(String filename)
                    throws IOException

Constructor.

Parameters:
  `filename` -
Throws:
  `IOException` - if there is a reading error.

### Method Detail

#### parse

    public org.apache.pdfbox.pdmodel.PDDocument parse()
                                               throws IOException

Overrides:
  `parse` in class `org.apache.pdfbox.pdfparser.PDFParser`
Throws:
  `IOException`

#### parse

    public org.apache.pdfbox.pdmodel.PDDocument parse(Format format)
                                               throws IOException

Parse the given file and check if it is a confirming file according to the given format.

Parameters:
  `format` - format that the document should follow (default `Format.PDF_A1B`)
Returns:
  the parsed document.
Throws:
  `IOException`

#### parse

    public org.apache.pdfbox.pdmodel.PDDocument parse(Format format,
                                                      PreflightConfiguration config)
                                               throws IOException

Parse the given file and check if it is a confirming file according to the given format.

Parameters:
  `format` - format that the document should follow (default `Format.PDF_A1B`)
  `config` - Configuration bean that will be used by the PreflightDocument. If null the format is used to determine the default configuration.
Returns:
  the parsed document.
Throws:
  `IOException`

#### createDocument

    protected org.apache.pdfbox.pdmodel.PDDocument createDocument()
                                                           throws IOException

Overrides:
  `createDocument` in class `org.apache.pdfbox.pdfparser.PDFParser`
Throws:
  `IOException`

#### initialParse

    protected void initialParse()
                         throws IOException

Overrides:
  `initialParse` in class `org.apache.pdfbox.pdfparser.PDFParser`
Throws:
  `IOException`

#### resetTrailerResolver

    protected boolean resetTrailerResolver()

Overrides:
  `resetTrailerResolver` in class `org.apache.pdfbox.pdfparser.COSParser`

#### parseXrefTable

    protected boolean parseXrefTable(long startByteOffset)
                              throws IOException

Same method than the COSParser.parseXrefTable(long) with additional controls : - EOL mandatory after the 'xref' keyword - Cross reference subsection header uses single white space as separator - and so on

Overrides:
  `parseXrefTable` in class `org.apache.pdfbox.pdfparser.COSParser`
Parameters:
  `startByteOffset` - the offset to start at
Returns:
  false on parsing error
Throws:
  `IOException` - If an IO error occurs.

#### parseCOSStream

    protected org.apache.pdfbox.cos.COSStream parseCOSStream(org.apache.pdfbox.cos.COSDictionary dic)
                                                      throws IOException

Wraps the `COSParser.parseCOSStream(org.apache.pdfbox.cos.COSDictionary)` to check rules on 'stream' and 'endstream' keywords. `checkStreamKeyWord()` and `checkEndstreamKeyWord(org.apache.pdfbox.cos.COSDictionary, long)`

Overrides:
  `parseCOSStream` in class `org.apache.pdfbox.pdfparser.COSParser`
Parameters:
  `dic` - 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.

#### parseCOSArray

    protected org.apache.pdfbox.cos.COSArray parseCOSArray()
                                                    throws IOException

Overrides:
  `parseCOSArray` in class `org.apache.pdfbox.pdfparser.BaseParser`
Throws:
  `IOException`

#### parseCOSName

    protected org.apache.pdfbox.cos.COSName parseCOSName()
                                                  throws IOException

Overrides:
  `parseCOSName` in class `org.apache.pdfbox.pdfparser.BaseParser`
Throws:
  `IOException`

#### parseCOSString

    protected org.apache.pdfbox.cos.COSString parseCOSString()
                                                      throws IOException

Check that the hexa string contains only an even number of Hexadecimal characters. Once it is done, reset the offset at the beginning of the string and call `BaseParser.parseCOSString()`

Overrides:
  `parseCOSString` in class `org.apache.pdfbox.pdfparser.BaseParser`
Returns:
  The parsed PDF string.
Throws:
  `IOException` - If there is an error reading from the stream.

#### parseDirObject

    protected org.apache.pdfbox.cos.COSBase parseDirObject()
                                                    throws IOException

Call `BaseParser.parseDirObject()` check limit range for Float, Integer and number of Dictionary entries.

Overrides:
  `parseDirObject` in class `org.apache.pdfbox.pdfparser.BaseParser`
Returns:
  The parsed object.
Throws:
  `IOException` - if there is an error during parsing.

#### parseObjectDynamically

    protected org.apache.pdfbox.cos.COSBase parseObjectDynamically(org.apache.pdfbox.cos.COSObjectKey objKey,
                                                                   boolean requireExistingNotCompressedObj)
                                                            throws IOException

Overrides:
  `parseObjectDynamically` in class `org.apache.pdfbox.pdfparser.COSParser`
Throws:
  `IOException`

#### lastIndexOf

    protected int lastIndexOf(char[] pattern,
                              byte[] buf,
                              int endOff)

Overrides:
  `lastIndexOf` in class `org.apache.pdfbox.pdfparser.COSParser`

#### validate

    public static ValidationResult validate(File file)
                                     throws IOException

Load and validate the given file. Returns the validation result and closes the read pdf.

Parameters:
  `file` - thew file to be read and validated
Returns:
  the validation result
Throws:
  `IOException` - in case of a file reading or parsing error