class PDFParser extends COSParser
{
    private static final Logger LOG = LogManager.getLogger(PDFParser.class);

    /**
     * Constructor.
     * Unrestricted main memory will be used for buffering PDF streams.
     * 
     * @param source source representing the pdf.
     * @throws IOException If something went wrong.
     */
    public PDFParser(RandomAccessRead source) throws IOException
    {
        this(source, "");
    }

    /**
     * Constructor.
     * Unrestricted main memory will be used for buffering PDF streams.
     * 
     * @param source input representing the pdf.
     * @param decryptionPassword password to be used for decryption.
     * @throws IOException If something went wrong.
     */
    public PDFParser(RandomAccessRead source, String decryptionPassword) throws IOException
    {
        this(source, decryptionPassword, null, null);
    }

    /**
     * Constructor.
     * Unrestricted main memory will be used for buffering PDF streams.
     * 
     * @param source input representing the pdf.
     * @param decryptionPassword password to be used for decryption.
     * @param keyStore key store to be used for decryption when using public key security 
     * @param alias alias to be used for decryption when using public key security
     *
     * @throws IOException If something went wrong.
     */
    public PDFParser(RandomAccessRead source, String decryptionPassword, InputStream keyStore,
            String alias) throws IOException
    {
        this(source, decryptionPassword, keyStore, alias, null);
    }

    /**
     * Constructor.
     * 
     * @param source input representing the pdf.
     * @param decryptionPassword password to be used for decryption.
     * @param keyStore key store to be used for decryption when using public key security
     * @param alias alias to be used for decryption when using public key security
     * @param streamCacheCreateFunction a function to create an instance of the stream cache
     *
     * @throws IOException If something went wrong.
     */
    public PDFParser(RandomAccessRead source, String decryptionPassword, InputStream keyStore,
            String alias, StreamCacheCreateFunction streamCacheCreateFunction) throws IOException
    {
        super(source, decryptionPassword, keyStore, alias, streamCacheCreateFunction);
    }

    /**
     * The initial parse will first parse only the trailer, the xrefstart and all xref tables to have a pointer (offset)
     * to all the pdf's objects. It can handle linearized pdfs, which will have an xref at the end pointing to an xref
     * at the beginning of the file. Last the root object is parsed.
     * 
     * @throws InvalidPasswordException If the password is incorrect.
     * @throws IOException If something went wrong.
     */
    protected void initialParse() throws IOException
    {<FILL_FUNCTION_BODY>}

    /**
     * This will parse the stream and populate the PDDocument object. This will close the keystore stream when it is
     * done parsing. Lenient mode is active by default.
     *
     * @return the populated PDDocument
     *
     * @throws InvalidPasswordException If the password is incorrect.
     * @throws IOException If there is an error reading from the stream or corrupt data is found.
     */
    public PDDocument parse() throws IOException
    {
        return parse(true);
    }

    /**
     * This will parse the stream and populate the PDDocument object. This will close the keystore stream when it is
     * done parsing.
     *
     * @param lenient activate leniency if set to true
     * @return the populated PDDocument
     * 
     * @throws InvalidPasswordException If the password is incorrect.
     * @throws IOException If there is an error reading from the stream or corrupt data is found.
     */
    public PDDocument parse(boolean lenient) throws IOException
    {
        setLenient(lenient);
        // set to false if all is processed
        boolean exceptionOccurred = true;
        try
        {
            // PDFBOX-1922 read the version header and rewind
            if (!parsePDFHeader() && !parseFDFHeader())
            {
                if (lenient)
                {
                    LOG.warn("Error: Header doesn't contain versioninfo");
                }
                else
                {
                    throw new IOException("Error: Header doesn't contain versioninfo");
                }
            }
    
            if (!initialParseDone)
            {
                initialParse();
            }
            exceptionOccurred = false;
            PDDocument pdDocument = createDocument();
            pdDocument.setEncryptionDictionary(getEncryption());
            return pdDocument;
        }
        finally
        {
            if (exceptionOccurred && document != null)
            {
                IOUtils.closeQuietly(document);
                document = null;
            }
        }
    }

    /**
     * Create the resulting document. Maybe overwritten if the parser uses another class as document.
     * 
     * @return the resulting document
     * @throws IOException if the method is called before parsing the document
     */
    protected PDDocument createDocument() throws IOException
    {
        return new PDDocument(document, source, getAccessPermission());
    }

    /**
     * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams.
     * 
     * @param file file to be loaded
     * 
     * @return loaded document
     * 
     * @throws InvalidPasswordException If the file required a non-empty password.
     * @throws IOException in case of a file reading or parsing error
     * 
     * @deprecated use {@link Loader#loadPDF(File)} instead
     */
    @Deprecated
    public static PDDocument load(File file) throws IOException
    {
        return Loader.loadPDF(file);
    }

    /**
     * Parses a PDF. Unrestricted main memory will be used for buffering PDF streams.
     * 
     * @param file file to be loaded
     * @param password password to be used for decryption
     * 
     * @return loaded document
     * 
     * @throws InvalidPasswordException If the password is incorrect.
     * @throws IOException in case of a file reading or parsing error
     * 
     * @deprecated use {@link Loader#loadPDF(File, String)} instead
     */
    @Deprecated
    public static PDDocument load(File file, String password) throws IOException
    {
        return Loader.loadPDF(file, password);
    }

}

        COSDictionary trailer = retrieveTrailer();
    
        COSDictionary root = trailer.getCOSDictionary(COSName.ROOT);
        if (root == null)
        {
            throw new IOException("Missing root object specification in trailer.");
        }
        // in some pdfs the type value "Catalog" is missing in the root object
        if (isLenient() && !root.containsKey(COSName.TYPE))
        {
            root.setItem(COSName.TYPE, COSName.CATALOG);
        }
        // check pages dictionaries
        checkPages(root);
        document.setDecrypted();
        initialParseDone = true;
    
<methods>public void <init>(org.apache.pdfbox.io.RandomAccessRead) throws java.io.IOException,public void <init>(org.apache.pdfbox.io.RandomAccessRead, java.lang.String, java.io.InputStream, java.lang.String) throws java.io.IOException,public void <init>(org.apache.pdfbox.io.RandomAccessRead, java.lang.String, java.io.InputStream, java.lang.String, org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction) throws java.io.IOException,public org.apache.pdfbox.io.RandomAccessReadView createRandomAccessReadView(long, long) throws java.io.IOException,public org.apache.pdfbox.cos.COSBase dereferenceCOSObject(org.apache.pdfbox.cos.COSObject) throws java.io.IOException,public boolean isLenient() ,public void setEOFLookupRange(int) <variables>private static final int DEFAULT_TRAIL_BYTECOUNT,private static final byte[] ENDOBJ,private static final byte[] ENDSTREAM,private static final char[] EOF_MARKER,private static final java.lang.String FDF_DEFAULT_VERSION,private static final java.lang.String FDF_HEADER,private static final Logger LOG,protected static final long MINIMUM_SEARCH_OFFSET,private static final char[] OBJ_MARKER,private static final java.lang.String PDF_DEFAULT_VERSION,private static final java.lang.String PDF_HEADER,private static final char[] STARTXREF,private static final int STRMBUFLEN,public static final java.lang.String SYSPROP_EOFLOOKUPRANGE,private org.apache.pdfbox.pdmodel.encryption.AccessPermission accessPermission,private org.apache.pdfbox.pdfparser.BruteForceParser bruteForceParser,private final Map<java.lang.Long,Map<org.apache.pdfbox.cos.COSObjectKey,org.apache.pdfbox.cos.COSBase>> decompressedObjects,private org.apache.pdfbox.pdmodel.encryption.PDEncryption encryption,private final non-sealed long fileLen,protected boolean initialParseDone,private boolean isLenient,private java.lang.String keyAlias,private java.io.InputStream keyStoreInputStream,private java.lang.String password,private int readTrailBytes,private SecurityHandler<org.apache.pdfbox.pdmodel.encryption.ProtectionPolicy> securityHandler,private final byte[] strmBuf,private boolean trailerWasRebuild,private final Map<org.apache.pdfbox.cos.COSObjectKey,java.lang.Long> xrefTable