pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1847126 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
Date Wed, 21 Nov 2018 17:46:54 GMT
Author: tilman
Date: Wed Nov 21 17:46:54 2018
New Revision: 1847126

URL: http://svn.apache.org/viewvc?rev=1847126&view=rev
Log:
PDFBOX-4383: don't store file as FileInputStream, add "previously failing" test

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java?rev=1847126&r1=1847125&r2=1847126&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java Wed
Nov 21 17:46:54 2018
@@ -263,8 +263,7 @@ public class PDFMergerUtility
      */
     public void addSource(File source) throws FileNotFoundException
     {
-        FileInputStream stream = new FileInputStream(source);
-        sources.add(stream);
+        sources.add(source);
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java?rev=1847126&r1=1847125&r2=1847126&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/multipdf/PDFMergerUtilityTest.java
Wed Nov 21 17:46:54 2018
@@ -17,7 +17,10 @@ package org.apache.pdfbox.multipdf;
 
 import java.awt.image.BufferedImage;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -238,6 +241,46 @@ public class PDFMergerUtilityTest extend
         doc.close();
     }
 
+    /**
+     * PDFBOX-4383: Test that file can be deleted after merge.
+     *
+     * @throws IOException 
+     */
+    public void testFileDeletion() throws IOException
+    {
+        File outFile = new File(TARGETTESTDIR, "PDFBOX-4383-result.pdf");
+
+        File inFile1 = new File(TARGETTESTDIR, "PDFBOX-4383-src1.pdf");
+        File inFile2 = new File(TARGETTESTDIR, "PDFBOX-4383-src2.pdf");
+
+        createSimpleFile(inFile1);
+        createSimpleFile(inFile2);
+
+        try (OutputStream out = new FileOutputStream(outFile))
+        {
+            PDFMergerUtility merger = new PDFMergerUtility();
+            merger.setDestinationStream(out);
+
+            merger.addSource(inFile1);
+            merger.addSource(inFile2);
+
+            merger.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
+        }
+
+        Files.delete(inFile1.toPath());
+        Files.delete(inFile2.toPath());
+        Files.delete(outFile.toPath());
+    }
+
+    private void createSimpleFile(File file) throws IOException
+    {
+        try (PDDocument doc = new PDDocument())
+        {
+            doc.addPage(new PDPage());
+            doc.save(file);
+        }
+    }
+
     private class ElementCounter
     {
         int cnt = 0;



Mime
View raw message