pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tboe...@apache.org
Subject svn commit: r1705688 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: cos/COSDocument.java io/ScratchFile.java pdfparser/FDFParser.java
Date Mon, 28 Sep 2015 13:23:52 GMT
Author: tboehme
Date: Mon Sep 28 13:23:52 2015
New Revision: 1705688

URL: http://svn.apache.org/viewvc?rev=1705688&view=rev
Log:
PDFBOX-2883: remove COSDocument constructors using boolean 'useScratchFiles' parameter and
ensure to have an equivalent constructor using MemoryUsageSetting object; default is using
main memory only (as before)

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=1705688&r1=1705687&r2=1705688&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Mon Sep 28 13:23:52
2015
@@ -17,12 +17,12 @@
 package org.apache.pdfbox.cos;
 
 import java.io.Closeable;
-import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.io.ScratchFile;
@@ -79,46 +79,18 @@ public class COSDocument extends COSBase
     private ScratchFile scratchFile;
 
     /**
-     * Constructor.
-     *
-     * @param useScratchFiles enables the usage of a scratch file if set to true
-     *                     
-     */
-    public COSDocument(boolean useScratchFiles)
-    {
-        this((File)null, useScratchFiles);
-    }
-
-    /**
-     * Constructor that will use a temporary file in the given directory
-     * for storage of the PDF streams. The temporary file is automatically
-     * removed when this document gets closed.
-     *
-     * @param scratchDir directory for the temporary file,
-     *                   or <code>null</code> to use the system default
-     * @param useScratchFiles enables the usage of a scratch file if set to true
-     * 
+     * Constructor. Uses main memory to buffer PDF streams.
      */
-    public COSDocument(File scratchDir, boolean useScratchFiles)
+    public COSDocument()
     {
-        if (useScratchFiles)
-        {
-            try 
-            {
-                scratchFile = new ScratchFile(scratchDir);
-            }
-            catch (IOException e)
-            {
-                LOG.error("Can't create temp file, using memory buffer instead", e);
-            }
-        }
+        this(ScratchFile.getMainMemoryOnlyInstance());
     }
 
     /**
      * Constructor that will use the provide memory handler for storage of the
      * PDF streams.
      *
-     * @param scratchFile memory handler for storage of PDF streams
+     * @param scratchFile memory handler for buffering of PDF streams
      * 
      */
     public COSDocument(ScratchFile scratchFile)
@@ -127,14 +99,6 @@ public class COSDocument extends COSBase
     }
 
     /**
-     * Constructor. Uses memory to store stream.
-     */
-    public COSDocument()
-    {
-        this(false);
-    }
-
-    /**
      * Creates a new COSStream using the current configuration for scratch files.
      * 
      * @return the new COSStream
@@ -169,7 +133,7 @@ public class COSDocument extends COSBase
      * @return This will return an object with the specified type.
      * @throws IOException If there is an error getting the object
      */
-    public COSObject getObjectByType( COSName type ) throws IOException
+    public COSObject getObjectByType(COSName type) throws IOException
     {
         for( COSObject object : objectPool.values() )
         {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java?rev=1705688&r1=1705687&r2=1705688&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/ScratchFile.java Mon Sep 28 13:23:52
2015
@@ -135,12 +135,19 @@ public class ScratchFile implements Clos
      * (same as <code>new ScratchFile(MemoryUsageSetting.setupMainMemoryOnly())</code>).
      * 
      * @return instance configured to only use main memory with no size restriction
-     * 
-     * @throws IOException
      */
-    public static ScratchFile getMainMemoryOnlyInstance() throws IOException
+    public static ScratchFile getMainMemoryOnlyInstance()
     {
-        return new ScratchFile(MemoryUsageSetting.setupMainMemoryOnly());
+        try
+        {
+            return new ScratchFile(MemoryUsageSetting.setupMainMemoryOnly());
+        }
+        catch (IOException ioe)
+        {
+            // cannot happen for main memory setup
+            LOG.error("Unexpected exception occurred creating main memory scratch file instance:
" + ioe.getMessage() );
+            return null;
+        }
     }
     
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java?rev=1705688&r1=1705687&r2=1705688&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java Mon Sep 28
13:23:52 2015
@@ -89,7 +89,7 @@ public class FDFParser extends COSParser
                         + " does not contain an integer value, but: '" + eofLookupRangeStr
+ "'");
             }
         }
-        document = new COSDocument(false);
+        document = new COSDocument();
     }
 
     /**



Mime
View raw message