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 2016/02/28 17:17:43 UTC

svn commit: r1732763 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java

Author: lehmi
Date: Sun Feb 28 16:17:43 2016
New Revision: 1732763

URL: http://svn.apache.org/viewvc?rev=1732763&view=rev
Log:
PDFBOX-3253: collect all COSStreams when creating a new pdf so that they can be closed when closing the COSDocument

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.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=1732763&r1=1732762&r2=1732763&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 Feb 28 16:17:43 2016
@@ -59,6 +59,11 @@ public class COSDocument extends COSBase
         new HashMap<COSObjectKey, Long>();
 
     /**
+     * List containing all streams which are created when creating a new pdf. 
+     */
+    private final List<COSStream> streams = new ArrayList<COSStream>();
+    
+    /**
      * Document trailer dictionary.
      */
     private COSDictionary trailer;
@@ -105,7 +110,12 @@ public class COSDocument extends COSBase
      */
     public COSStream createCOSStream()
     {
-        return new COSStream(scratchFile);
+        COSStream stream = new COSStream(scratchFile);
+        // collect all COSStreams so that they can be closed when closing the COSDocument.
+        // This is limited to newly created pdfs as all COSStreams of an existing pdf are
+        // collected within the map objectPool
+        streams.add(stream);
+        return stream;
     }
 
     /**
@@ -432,7 +442,13 @@ public class COSDocument extends COSBase
                     }
                 }
             }
-
+            if (streams != null)
+            {
+                for(COSStream stream : streams)
+                {
+                    stream.close();
+                }
+            }
             if (scratchFile != null)
             {
                 scratchFile.close();