pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1718454 - /pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpegTest.java
Date Mon, 07 Dec 2015 20:33:49 GMT
Author: tilman
Date: Mon Dec  7 20:33:48 2015
New Revision: 1718454

URL: http://svn.apache.org/viewvc?rev=1718454&view=rev
Log:
PDFBOX-3153: add test

Modified:
    pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpegTest.java

Modified: pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpegTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpegTest.java?rev=1718454&r1=1718453&r2=1718454&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpegTest.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/xobject/PDJpegTest.java
Mon Dec  7 20:33:48 2015
@@ -18,11 +18,18 @@ package org.apache.pdfbox.pdmodel.graphi
 
 import java.awt.Graphics;
 import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
 import javax.imageio.ImageIO;
 import junit.framework.TestCase;
+import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.exceptions.COSVisitorException;
+import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
@@ -32,6 +39,7 @@ import static org.apache.pdfbox.pdmodel.
 import static org.apache.pdfbox.pdmodel.graphics.xobject.PDUtils.colorCount;
 import static org.apache.pdfbox.pdmodel.graphics.xobject.PDUtils.createInterestingImage;
 import org.apache.pdfbox.util.ImageIOUtil;
+import static org.junit.Assert.assertArrayEquals;
 
 /**
  *
@@ -104,6 +112,7 @@ public class PDJpegTest extends TestCase
         document.save(pdfFile);
         document.close();
         document = PDDocument.loadNonSeq(pdfFile, null);
+        checkJpegStream(document, this.getClass().getResourceAsStream("jpeg.jpg"));
         document.close();
     }
 
@@ -139,6 +148,7 @@ public class PDJpegTest extends TestCase
         document.save(pdfFile);
         document.close();
         document = PDDocument.loadNonSeq(pdfFile, null);
+        checkJpegStream(document, this.getClass().getResourceAsStream("jpeg256.jpg"));
         document.close();
     }
 
@@ -340,4 +350,21 @@ public class PDJpegTest extends TestCase
         assertTrue(writeOk);
     }
 
+    // check whether it is possible to extract the jpeg stream exactly 
+    // as it was passed to createFromStream
+    private void checkJpegStream(PDDocument doc, InputStream resourceStream)
+            throws IOException
+    {
+        Map<String, PDXObject> xObjectMap = 
+                ((List<PDPage>) doc.getDocumentCatalog().getAllPages()).get(0).getResources().getXObjects();
+        PDXObjectImage ximage = (PDXObjectImage) xObjectMap.get("Im0");
+        InputStream dctStream = ximage.getPDStream().getPartiallyFilteredStream(Arrays.asList(COSName.DCT_DECODE.getName()));
+        ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
+        ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
+        IOUtils.copy(resourceStream, baos1);
+        IOUtils.copy(dctStream, baos2);
+        resourceStream.close();
+        dctStream.close();
+        assertArrayEquals(baos1.toByteArray(), baos2.toByteArray());
+    }
 }



Mime
View raw message