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

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

### Field Summary

Fields
`protected PreflightContext` `ctx`
`protected DataSource` `dataSource`
`static Charset` `encoding` Define a one byte encoding that hasn't specific encoding in UTF-8 charset.
`protected PreflightDocument` `preflightDocument`
`protected ValidationResult` `validationResult`

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

`EOF_MARKER, fileLen, initialParseDone, OBJ_MARKER, securityHandler, source, SYSPROP_EOFLOOKUPRANGE, SYSPROP_PARSEMINIMAL, TMP_FILE_PREFIX, 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, STREAM_STRING, T`

### Constructor Summary

Constructors
Constructor and Description
`PreflightParser(DataSource dataSource)` Constructor.
`PreflightParser(DataSource dataSource, org.apache.pdfbox.io.ScratchFile scratch)` Constructor.
`PreflightParser(File file)` Constructor.
`PreflightParser(File file, org.apache.pdfbox.io.ScratchFile scratch)` Constructor.
`PreflightParser(String filename)` Constructor.
`PreflightParser(String filename, org.apache.pdfbox.io.ScratchFile scratch)` Constructor.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`protected void` `addValidationError(ValidationResult.ValidationError error)` Add the error to the ValidationResult.
`protected void` `addValidationErrors(List<ValidationResult.ValidationError> errors)`
`protected void` `checkEndstreamKeyWord()` 'endstream' must be preceded by an EOL
`protected void` `checkPdfHeader()` Check that the PDF header match rules of the PDF/A specification.
`protected void` `checkStreamKeyWord()` 'stream' must be followed by <CR><LF> or only <LF>
`protected void` `createContext()` Create a validation context.
`protected void` `createPdfADocument(Format format, PreflightConfiguration config)`
`protected static ValidationResult` `createUnknownErrorResult()` Create an instance of ValidationResult with a ValidationError(UNKNOWN_ERROR)
`org.apache.pdfbox.pdmodel.PDDocument` `getPDDocument()`
`PreflightDocument` `getPreflightDocument()`
`protected void` `initialParse()`
`protected int` `lastIndexOf(char[] pattern, byte[] buf, int endOff)`
`void` `parse()`
`void` `parse(Format format)` Parse the given file and check if it is a confirming file according to the given format.
`void` `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(long objNr, int objGenNr, 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

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

`checkPages, getAccessPermission, getDocument, getEncryption, getStartxrefOffset, isCatalog, isLenient, parseDictObjects, parseFDFHeader, parseObjectDynamically, parsePDFHeader, parseTrailerValuesDynamically, parseXref, rebuildTrailer, retrieveTrailer, setEOFLookupRange, setLenient`

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

`isClosing, isClosing, isDigit, isDigit, isEndOfName, isEOL, isEOL, isSpace, isSpace, isWhitespace, isWhitespace, parseBoolean, parseCOSDictionary, readExpectedChar, readExpectedString, 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`

### Field Detail

#### encoding

    public static final Charset encoding

Define a one byte encoding that hasn't specific encoding in UTF-8 charset. Avoid unexpected error when the encoding is Cp5816

#### dataSource

    protected DataSource dataSource

#### validationResult

    protected ValidationResult validationResult

#### preflightDocument

    protected PreflightDocument preflightDocument

#### ctx

    protected PreflightContext ctx

### Constructor Detail

#### PreflightParser

    public PreflightParser(File file)
                    throws IOException

Constructor.

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

#### PreflightParser

    public PreflightParser(File file,
                           org.apache.pdfbox.io.ScratchFile scratch)
                    throws IOException

Constructor.

Parameters:
  `file` -
  `scratch` -
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.

#### PreflightParser

    public PreflightParser(String filename,
                           org.apache.pdfbox.io.ScratchFile scratch)
                    throws IOException

Constructor.

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

#### PreflightParser

    public PreflightParser(DataSource dataSource)
                    throws IOException

Constructor. This one is slower than the file and the filename constructors, because a temporary file will be created.

Parameters:
  `dataSource` - the datasource
Throws:
  `IOException` - if there is a reading error.

#### PreflightParser

    public PreflightParser(DataSource dataSource,
                           org.apache.pdfbox.io.ScratchFile scratch)
                    throws IOException

Constructor. This one is slower than the file and the filename constructors, because a temporary file will be created.

Parameters:
  `dataSource` - the datasource
  `scratch` -
Throws:
  `IOException` - if there is a reading error.

### Method Detail

#### createUnknownErrorResult

    protected static ValidationResult createUnknownErrorResult()

Create an instance of ValidationResult with a ValidationError(UNKNOWN_ERROR)

Returns:
  the ValidationError instance.

#### addValidationError

    protected void addValidationError(ValidationResult.ValidationError error)

Add the error to the ValidationResult. If the validationResult is null, an instance is created using the isWarning boolean of the ValidationError to know if the ValidationResult must be flagged as Valid.

Parameters:
  `error` -

#### addValidationErrors

    protected void addValidationErrors(List<ValidationResult.ValidationError> errors)

#### parse

    public void parse()
               throws IOException

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

#### parse

    public void 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`)
Throws:
  `IOException`

#### parse

    public void 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.
Throws:
  `IOException`

#### createPdfADocument

    protected void createPdfADocument(Format format,
                                      PreflightConfiguration config)
                               throws IOException

Throws:
  `IOException`

#### createContext

    protected void createContext()

Create a validation context. This context is set to the PreflightDocument.

#### getPDDocument

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

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

#### getPreflightDocument

    public PreflightDocument getPreflightDocument()
                                           throws IOException

Throws:
  `IOException`

#### initialParse

    protected void initialParse()
                         throws IOException

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

#### checkPdfHeader

    protected void checkPdfHeader()

Check that the PDF header match rules of the PDF/A specification. First line (offset 0) must be a comment with the PDF version (version 1.0 isn't conform to the PDF/A specification) Second line is a comment with at least 4 bytes greater than 0x80

#### 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()`

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.

#### checkStreamKeyWord

    protected void checkStreamKeyWord()
                               throws IOException

'stream' must be followed by <CR><LF> or only <LF>

Throws:
  `IOException`

#### checkEndstreamKeyWord

    protected void checkEndstreamKeyWord()
                                  throws IOException

'endstream' must be preceded by an EOL

Throws:
  `IOException`

#### 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(long objNr,
                                                                   int objGenNr,
                                                                   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`