You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Pe...@ibi.com on 2009/01/20 12:07:44 UTC

Could possibly be missing the case where the output was open, but the writer was not

// could possibly be missing the case where the output was open, but the
writer was not

// be sure to close output of it is not possible to close the writer.

 

 

 

    public void save( OutputStream output ) throws IOException,
COSVisitorException

    {

        //update the count in case any pages have been added behind the
scenes.

        getDocumentCatalog().getPages().updateCount();

        COSWriter writer = null;

        try

        {

            writer = new COSWriter( output );

            writer.write( this );

            writer.close();

        }

        finally

        {

            if( writer != null )

            {

                writer.close();

            }

            else if (output != null) {

                output.close();  // This may happen of you don't have
disk space or write access to the file.

            }

        }

    }