* @throws PDFException         if error occurs
     * @throws PDFSecurityException security error
     * @throws IOException          io error during stream handling
     */
    private void setInputStream(final SeekableInput in)
            throws PDFException, PDFSecurityException, IOException {
        try {
            documentSeekableInput = in;

            // create library to hold all document objects
            library = new Library();

            // if interactive show visual progress bar
            //ProgressMonitorInputStream monitor = null;

            boolean loaded = false;
            try {
                loadDocumentViaXRefs(in);
                loaded = true;
            }
            catch (PDFException e) {
                throw e;
            }
            catch (PDFSecurityException e) {
                throw e;
            }
            catch (Exception e) {
                if (logger.isLoggable(Level.WARNING)) {
                    logger.warning("Cross reference deferred loading failed, will fall back to linear reading.");
                }
            }

            if (!loaded) {
                // Cleanup any bits left behind by the failed xref loading
                if (catalog != null) {
                    catalog.dispose(false);
                    catalog = null;
                }
                if (library != null) {
                    library.dispose();
                    library = null;
                }
                library = new Library();
                pTrailer = null;

                in.seekAbsolute(0L);
                loadDocumentViaLinearTraversal(in.getInputStream());
            }

            // initiate the catalog, build the outline for the document
            catalog.init();

            // create new instance of state manager and add it to the library
            stateManager = new StateManager(pTrailer);
            library.setStateManager(stateManager);
        }
        catch (PDFException e) {
            logger.log(Level.FINE, "Error loading PDF file during linear parse.", e);
            dispose();
            throw e;
        }
        catch (PDFSecurityException e) {
            dispose();
            throw e;
        }
        catch (IOException e) {
            dispose();
            throw e;
        }
        catch (Exception e) {
            dispose();
            logger.log(Level.SEVERE, "Error loading PDF Document.", e);
            throw new IOException(e.getMessage());
        }
    }