pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1693469 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
Date Thu, 30 Jul 2015 18:44:44 GMT
Author: lehmi
Date: Thu Jul 30 18:44:44 2015
New Revision: 1693469

URL: http://svn.apache.org/r1693469
Log:
PDFBOX-2911: close all FileInputStreams created when calling addSource with a filename or
a file

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java?rev=1693469&r1=1693468&r2=1693469&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
Thu Jul 30 18:44:44 2015
@@ -75,6 +75,7 @@ public class PDFMergerUtility
     private static final String STRUCTURETYPE_DOCUMENT = "Document";
 
     private final List<InputStream> sources;
+    private final List<FileInputStream> fileInputStreams;
     private String destinationFileName;
     private OutputStream destinationStream;
     private boolean ignoreAcroFormErrors = false;
@@ -85,6 +86,7 @@ public class PDFMergerUtility
     public PDFMergerUtility()
     {
         sources = new ArrayList<InputStream>();
+        fileInputStreams = new ArrayList<FileInputStream>();
     }
 
     /**
@@ -104,7 +106,7 @@ public class PDFMergerUtility
      */
     public void setDestinationFileName(String destination)
     {
-        this.destinationFileName = destination;
+        destinationFileName = destination;
     }
 
     /**
@@ -134,14 +136,7 @@ public class PDFMergerUtility
      */
     public void addSource(String source)
     {
-        try
-        {
-            sources.add(new FileInputStream(new File(source)));
-        }
-        catch (Exception e)
-        {
-            throw new RuntimeException(e);
-        }
+        addSource(new File(source));
     }
 
     /**
@@ -153,7 +148,9 @@ public class PDFMergerUtility
     {
         try
         {
-            sources.add(new FileInputStream(source));
+            FileInputStream stream = new FileInputStream(source); 
+            sources.add(stream);
+            fileInputStreams.add(stream);
         }
         catch (Exception e)
         {
@@ -260,6 +257,10 @@ public class PDFMergerUtility
                 {
                     doc.close();
                 }
+                for (FileInputStream stream : fileInputStreams)
+                {
+                    stream.close();
+                }
             }
         }
     }



Mime
View raw message