You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2014/09/14 12:11:27 UTC

svn commit: r1624824 - in /pdfbox/trunk: pdfbox/src/main/java/org/apache/pdfbox/cos/ pdfbox/src/main/java/org/apache/pdfbox/pdfparser/ preflight/src/test/java/org/apache/pdfbox/preflight/utils/

Author: lehmi
Date: Sun Sep 14 10:11:27 2014
New Revision: 1624824

URL: http://svn.apache.org/r1624824
Log:
PDFBOX-2301: updated documentation, removed unused methods

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/utils/TestCOSUtils.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=1624824&r1=1624823&r2=1624824&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 Sun Sep 14 10:11:27 2014
@@ -28,7 +28,6 @@ import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.pdfbox.pdfparser.NonSequentialPDFParser;
 import org.apache.pdfbox.pdfparser.PDFObjectStreamParser;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface;
 import org.apache.pdfbox.persistence.util.COSObjectKey;
@@ -88,7 +87,7 @@ public class COSDocument extends COSBase
     
     private final File scratchDirectory;
     
-    private final boolean useScratchFiles;
+    private final boolean useScratchFile;
     
     /**
      * Flag to skip malformed or otherwise unparseable input where possible.
@@ -96,12 +95,8 @@ public class COSDocument extends COSBase
     private final boolean forceParsing;
 
     /**
-     * Constructor that will use the given random access file for storage
-     * of the PDF streams. The client of this method is responsible for
-     * deleting the storage if necessary that this file will write to. The
-     * close method will close the file though.
+     * Constructor.
      *
-     * @param scratchFileValue the random access file to use for storage
      * @param forceParsingValue flag to skip malformed or otherwise unparseable
      *                     document content where possible
      */
@@ -111,14 +106,12 @@ public class COSDocument extends COSBase
     }
 
     /**
-     * Constructor that will use the given random access file for storage
-     * of the PDF streams. The client of this method is responsible for
-     * deleting the storage if necessary that this file will write to. The
-     * close method will close the file though.
+     * Constructor.
      *
-     * @param scratchFileValue the random access file to use for storage
      * @param forceParsingValue flag to skip malformed or otherwise unparseable
      *                     document content where possible
+     * @param useScratchFiles enables the usage of a scratch file if set to true
+     *                     
      */
     public COSDocument(boolean forceParsingValue, boolean useScratchFiles) 
     {
@@ -134,31 +127,18 @@ public class COSDocument extends COSBase
      *                   or <code>null</code> to use the system default
      * @param forceParsingValue flag to skip malformed or otherwise unparseable
      *                     document content where possible
-     */
-    public COSDocument(File scratchDir, boolean forceParsingValue) 
-    {
-        this(scratchDir, forceParsingValue, false);
-    }
-
-    /**
-     * 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 forceParsingValue flag to skip malformed or otherwise unparseable
-     *                     document content where possible
+     * @param useScratchFiles enables the usage of a scratch file if set to true
+     * 
      */
     public COSDocument(File scratchDir, boolean forceParsingValue, boolean useScratchFiles) 
     {
         forceParsing = forceParsingValue;
         scratchDirectory = scratchDir;
-        this.useScratchFiles = useScratchFiles;
+        useScratchFile = useScratchFiles;
     }
 
     /**
-     * Constructor.  Uses memory to store stream.
+     * Constructor. Uses memory to store stream.
      */
     public COSDocument()
     {
@@ -166,30 +146,17 @@ public class COSDocument extends COSBase
     }
 
     /**
-     * Constructor that will create a create a scratch file in the
-     * following directory.
-     *
-     * @param scratchDir The directory to store a scratch file.
-     *
-     * @throws IOException If there is an error creating the tmp file.
-     */
-    public COSDocument(File scratchDir) throws IOException 
-    {
-        this(scratchDir, false, false);
-    }
-
-    /**
-     * Create a new COSStream using the underlying scratch file.
+     * Creates a new COSStream using the current configuration for scratch files.
      * 
      * @return the new COSStream
      */
     public COSStream createCOSStream()
     {
-        return new COSStream( useScratchFiles, scratchDirectory);
+        return new COSStream( useScratchFile, scratchDirectory);
     }
 
     /**
-     * Create a new COSStream using the underlying scratch file.
+     * Creates a new COSStream using the current configuration for scratch files.
      *
      * @param dictionary the corresponding dictionary
      * 
@@ -197,20 +164,7 @@ public class COSDocument extends COSBase
      */
     public COSStream createCOSStream(COSDictionary dictionary)
     {
-        return new COSStream( dictionary, useScratchFiles, scratchDirectory );
-    }
-
-    /**
-     * This will get the first dictionary object by type.
-     *
-     * @param type The type of the object.
-     *
-     * @return This will return an object with the specified type.
-     * @throws IOException If there is an error getting the object
-     */
-    public COSObject getObjectByType( String type ) throws IOException
-    {
-        return getObjectByType( COSName.getPDFName( type ) );
+        return new COSStream( dictionary, useScratchFile, scratchDirectory );
     }
 
     /**
@@ -566,8 +520,8 @@ public class COSDocument extends COSBase
         {
             if (trailer != null)
             {
-            	trailer.clear();
-            	trailer = null;
+                trailer.clear();
+                trailer = null;
             }
             // Clear object pool
             List<COSObject> list = getObjects();
@@ -579,15 +533,15 @@ public class COSDocument extends COSBase
                     // clear the resources of the pooled objects
                     if (cosObject instanceof COSStream)
                     {
-                    	((COSStream)cosObject).close();
+                        ((COSStream)cosObject).close();
                     }
                     else if (cosObject instanceof COSDictionary)
                     {
-                    	((COSDictionary)cosObject).clear();
+                        ((COSDictionary)cosObject).clear();
                     }
                     else if (cosObject instanceof COSArray)
                     {
-                    	((COSArray)cosObject).clear();
+                        ((COSArray)cosObject).clear();
                     }
                     // TODO are there other kind of COSObjects to be cleared?
                 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java?rev=1624824&r1=1624823&r2=1624824&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java Sun Sep 14 10:11:27 2014
@@ -53,6 +53,9 @@ public class COSStream extends COSDictio
 
     private static final int BUFFER_SIZE=16384;
 
+    /**
+     * internal buffer, either held in memory or within a scratch file.
+     */
     private RandomAccess buffer;
     /**
      * The stream with all of the filters applied.
@@ -87,14 +90,17 @@ public class COSStream extends COSDictio
 
     /**
      * Constructor.  Creates a new stream with an empty dictionary.
-     *
+     * 
+     * @param useScratchFiles enables the usage of a scratch file if set to true
+     * @param scratchDirectory directory to be used to create the scratch file. If null java.io.temp is used instead.
+     *     
      */
     public COSStream( boolean useScratchFiles, File scratchDirectory )
     {
         super();
         if (useScratchFiles)
         {
-            buffer = createScratchFile(scratchDirectory);
+            createScratchFile(scratchDirectory);
         }
         if (buffer == null)
         {
@@ -106,6 +112,8 @@ public class COSStream extends COSDictio
      * Constructor.
      *
      * @param dictionary The dictionary that is associated with this stream.
+     * @param useScratchFiles enables the usage of a scratch file if set to true
+     * @param scratchDirectory directory to be used to create the scratch file. If null java.io.temp is used instead.
      * 
      */
     public COSStream( COSDictionary dictionary, boolean useScratchFiles, File scratchDirectory  )
@@ -113,7 +121,7 @@ public class COSStream extends COSDictio
         super( dictionary );
         if (useScratchFiles)
         {
-            buffer = createScratchFile(scratchDirectory);
+            createScratchFile(scratchDirectory);
         }
         if (buffer == null)
         {
@@ -121,12 +129,18 @@ public class COSStream extends COSDictio
         }
     }
 
-    private RandomAccessFile createScratchFile(File scratchDirectory)
+    /**
+     * Create a scratch file to be used as buffer to decrease memory foot print.
+     * 
+     * @param scratchDirectory directory to be used to create the scratch file. If null java.io.temp is used instead.
+     * 
+     */
+    private void createScratchFile(File scratchDirectory)
     {
-        RandomAccessFile buffer = null;
         try 
         {
             File scratchFile = File.createTempFile("PDFBox", null, scratchDirectory);
+            // mark scratch file to deleted automatically after usage
             scratchFile.deleteOnExit();
             buffer = new RandomAccessFile(scratchFile, "rw");
         }
@@ -134,23 +148,6 @@ public class COSStream extends COSDictio
         {
             LOG.error("Can't create temp file, using memory buffer instead", exception);
         }
-        return buffer;
-    }
-
-    /**
-     * This will replace this object with the data from the new object.  This
-     * is used to easily maintain referential integrity when changing references
-     * to new objects.
-     *
-     * @param stream The stream that have the new values in it.
-     */
-    public void replaceWithStream( COSStream stream )
-    {
-        this.clear();
-        this.addAll( stream );
-        buffer = stream.buffer;
-        filteredStream = stream.filteredStream;
-        unFilteredStream = stream.unFilteredStream;
     }
 
     /**
@@ -170,7 +167,7 @@ public class COSStream extends COSDictio
     /**
      * This will get the stream with all of the filters applied.
      *
-     * @return the bytes of the physical (endoced) stream
+     * @return the bytes of the physical (encoded) stream
      *
      * @throws IOException when encoding/decoding causes an exception
      */
@@ -275,12 +272,6 @@ public class COSStream extends COSDictio
         }
     }
 
-    /**
-     * visitor pattern double dispatch method.
-     *
-     * @param visitor The object to notify when visiting this object.
-     * @return any object, depending on the visitor implementation, or null
-     */
     @Override
     public Object accept(ICOSVisitor visitor) throws IOException
     {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java?rev=1624824&r1=1624823&r2=1624824&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java Sun Sep 14 10:11:27 2014
@@ -141,7 +141,7 @@ public class PDFParser extends BaseParse
         {
             if( tempDirectory != null )
             {
-                document = new COSDocument( tempDirectory );
+                document = new COSDocument( tempDirectory, false, true );
             }
             else
             {

Modified: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/utils/TestCOSUtils.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/utils/TestCOSUtils.java?rev=1624824&r1=1624823&r2=1624824&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/utils/TestCOSUtils.java (original)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/utils/TestCOSUtils.java Sun Sep 14 10:11:27 2014
@@ -221,7 +221,7 @@ public class TestCOSUtils
 
         IOCOSDocument(File scratchDir) throws IOException
         {
-            super(scratchDir);
+            super(scratchDir, false, true);
         }
 
         @Override