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 11:08:19 UTC

Optional logger calls could be added to COSDocument & PDJpeg when an error occurs.

The return code of the delete was ignored.

We really should log an error like this if it happened.

 

 

COSBase extends LoggingObject

org.apache.pdfbox.cos.COSDocument extends COSBase

 

In COSDocument you could add calls to the logger to report any problems
deleting a file.

 

    public void close() throws IOException

    {

        if( scratchFile != null )

        {

            scratchFile.close();

            scratchFile = null;

        }

        if( tmpFile != null )

        {

            boolean deleted=false;

            try {

                  deleted=tmpFile.delete();

                  if (!deleted)

                        logger().severe("File was not deleted:
"+tmpFile.getName());

            }

            catch (IOException e) {

                  if (!deleted)

                        logger().severe("File was not deleted
IOException: "+tmpFile.getName());

                  throw e;

            }

            catch (SecurityException se) { 

                        // If a security manager exists and its 

                        // java.lang.SecurityManager.checkDelete method
denies delete 

                        // access to the file.

                  if (!deleted)

                        logger().severe("File was not deleted security
exception: "+tmpFile.getName());

 

                  throw se;

            }

            tmpFile = null;

        }

    }

 

 

package org.apache.pdfbox.pdmodel.graphics.xobject;

 

public abstract class PDXObject implements COSObjectable

public abstract class PDXObjectImage extends PDXObject

public class PDJpeg extends PDXObjectImage

 

To make logging available to PDJpeg  you could extend the PDXObject
class.

 

public abstract class PDXObject extends LoggingObject implements
COSObjectable

 

Then in PDJpeg  the logging of errors could be added for the delete
method call, just like above.

 

           if (imgFile != null) {

                imgFile.delete();

            }