pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1809053 - in /pdfbox/branches/2.0/pdfbox/src/test: java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java resources/org/apache/pdfbox/pdfparser/embedded_zip.pdf
Date Wed, 20 Sep 2017 17:02:31 GMT
Author: tilman
Date: Wed Sep 20 17:02:31 2017
New Revision: 1809053

URL: http://svn.apache.org/viewvc?rev=1809053&view=rev
Log:
PDFBOX-3938: add testcase from issue 2079 by Tim Allison

Added:
    pdfbox/branches/2.0/pdfbox/src/test/resources/org/apache/pdfbox/pdfparser/embedded_zip.pdf
  (with props)
Modified:
    pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java

Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java?rev=1809053&r1=1809052&r2=1809053&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/EndstreamOutputStreamTest.java
Wed Sep 20 17:02:31 2017
@@ -17,16 +17,29 @@
 package org.apache.pdfbox.pdfparser;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
-import junit.framework.TestCase;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Map;
+import org.apache.pdfbox.io.IOUtils;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
+import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
+import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
+import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
+import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
 import org.junit.Assert;
+import org.junit.Test;
 
 /**
  *
  * @author Tilman Hausherr
  */
-public class EndstreamOutputStreamTest extends TestCase
+public class EndstreamOutputStreamTest
 {
+    @Test
     public void testEndstreamOutputStream() throws IOException
     {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -93,5 +106,32 @@ public class EndstreamOutputStreamTest e
         byte[] expectedResult5 = { 1, 2, 3, 4, '\r', '\n', 5, 6, 7, '\r', 8, 9, '\n', '\r'};
         Assert.assertArrayEquals(expectedResult5, baos.toByteArray());
     }
-    
+
+    @Test
+    public void testPDFBox2079EmbeddedFile() throws IOException
+    {
+        // there should be 17660 bytes in the zip file.
+        // in PDFBox 1.8.5, windows newline is appended to the byte stream
+        // yielding 17662 bytes, which causes a problem for ZipFile in Java 1.6
+
+        // Modification of embedded_zip.pdf for 2.0:
+        // /Length entry removed to force usage of EndstreamOutputStream
+        PDDocument doc = PDDocument.load(
+                new File("src/test/resources/org/apache/pdfbox/pdfparser", "embedded_zip.pdf"));
+        PDDocumentCatalog catalog = doc.getDocumentCatalog();
+        PDDocumentNameDictionary names = catalog.getNames();
+        PDEmbeddedFilesNameTreeNode node = names.getEmbeddedFiles();
+        Map<String, PDComplexFileSpecification> map = node.getNames();
+        Assert.assertEquals(1, map.size());
+        PDComplexFileSpecification spec = map.get("My first attachment");
+        PDEmbeddedFile file = spec.getEmbeddedFile();
+        InputStream input = file.createInputStream();
+        File f = new File("target/test-output", spec.getFile());
+        System.out.println(f.getAbsolutePath());
+        OutputStream os = new FileOutputStream(f);
+        IOUtils.copy(input, os);
+        os.close();
+        Assert.assertEquals(17660, f.length());
+        doc.close();
+    }
 }

Added: pdfbox/branches/2.0/pdfbox/src/test/resources/org/apache/pdfbox/pdfparser/embedded_zip.pdf
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/resources/org/apache/pdfbox/pdfparser/embedded_zip.pdf?rev=1809053&view=auto
==============================================================================
Binary file - no diff available.

Propchange: pdfbox/branches/2.0/pdfbox/src/test/resources/org/apache/pdfbox/pdfparser/embedded_zip.pdf
------------------------------------------------------------------------------
    svn:mime-type = application/pdf



Mime
View raw message