pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1692027 - in /pdfbox/trunk: examples/src/main/java/org/apache/pdfbox/examples/util/ pdfbox/src/main/java/org/apache/pdfbox/contentstream/ pdfbox/src/main/java/org/apache/pdfbox/io/ pdfbox/src/main/java/org/apache/pdfbox/multipdf/ pdfbox/sr...
Date Mon, 20 Jul 2015 21:47:42 GMT
Author: jahewson
Date: Mon Jul 20 21:47:41 2015
New Revision: 1692027

URL: http://svn.apache.org/r1692027
Log:
PDFBOX-2894: Remove COSStreamArray / SequenceRandomAccessRead

Removed:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/SequenceRandomAccessRead.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSStreamArray.java
Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/RemoveAllText.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDContentStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/LayerUtility.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFCloneUtility.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3CharProc.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/form/PDFormXObject.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/pattern/PDTilingPattern.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripperByArea.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/ICCProfileWrapper.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/RemoveAllText.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/RemoveAllText.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/RemoveAllText.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/RemoveAllText.java Mon Jul 20 21:47:41 2015
@@ -70,7 +70,7 @@ public class RemoveAllText
                 }
                 for( PDPage page : document.getPages() )
                 {
-                    PDFStreamParser parser = new PDFStreamParser(page.getStream());
+                    PDFStreamParser parser = new PDFStreamParser(page);
                     parser.parse();
                     List<Object> tokens = parser.getTokens();
                     List<Object> newTokens = new ArrayList<Object>();

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDContentStream.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDContentStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDContentStream.java Mon Jul 20 21:47:41 2015
@@ -17,7 +17,8 @@
 
 package org.apache.pdfbox.contentstream;
 
-import org.apache.pdfbox.cos.COSStream;
+import java.io.IOException;
+import java.io.InputStream;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.util.Matrix;
@@ -30,9 +31,12 @@ import org.apache.pdfbox.util.Matrix;
 public interface PDContentStream
 {
     /**
-     * Returns the underlying COS stream.
+     * Returns this stream's content, if any.
+     * 
+     * @return An InputStream or null.
+     * @throws IOException If the stream could not be read
      */
-    COSStream getContentStream();
+    InputStream getContents() throws IOException;
 
     /**
      * Returns this stream's resources, if any.

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java Mon Jul 20 21:47:41 2015
@@ -142,7 +142,7 @@ public abstract class PDFStreamEngine
     public void processPage(PDPage page) throws IOException
     {
         initPage(page);
-        if (page.getStream() != null)
+        if (page.hasContents())
         {
             isProcessingPage = true;
             processStream(page);
@@ -447,7 +447,7 @@ public abstract class PDFStreamEngine
     private void processStreamOperators(PDContentStream contentStream) throws IOException
     {
         List<COSBase> arguments = new ArrayList<COSBase>();
-        PDFStreamParser parser = new PDFStreamParser(contentStream.getContentStream());
+        PDFStreamParser parser = new PDFStreamParser(contentStream);
         Object token = parser.parseNextToken();
         while (token != null)
         {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/LayerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/LayerUtility.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/LayerUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/LayerUtility.java Mon Jul 20 21:47:41 2015
@@ -147,9 +147,7 @@ public class LayerUtility
      */
     public PDFormXObject importPageAsForm(PDDocument sourceDoc, PDPage page) throws IOException
     {
-        COSStream pageStream = (COSStream)page.getStream().getCOSObject();
-        PDStream newStream = new PDStream(targetDoc,
-                pageStream.getUnfilteredStream(), false);
+        PDStream newStream = new PDStream(targetDoc, page.getContents(), false);
         PDFormXObject form = new PDFormXObject(newStream);
 
         //Copy resources

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFCloneUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFCloneUtility.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFCloneUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFCloneUtility.java Mon Jul 20 21:47:41 2015
@@ -20,7 +20,6 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
@@ -29,7 +28,6 @@ import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
-import org.apache.pdfbox.pdmodel.common.COSStreamArray;
 import org.apache.pdfbox.pdmodel.common.PDStream;
 
 /**
@@ -110,26 +108,6 @@ class PDFCloneUtility
               retval = newArray;
               clonedVersion.put( base, retval );
           }
-          else if (base instanceof COSStreamArray)
-          {
-              // PDFBOX-2052
-              COSStreamArray originalStream = (COSStreamArray) base;
-
-              if (originalStream.size() > 0)
-              {
-                  throw new IllegalStateException("Cannot close stream array with items next to the streams.");
-              }
-
-              COSArray array = new COSArray();
-              for (int i = 0; i < originalStream.getStreamCount(); i++)
-              {
-                  COSBase base2 = originalStream.get(i);
-                  COSBase cloneForNewDocument = cloneForNewDocument(base2);
-                  array.add(cloneForNewDocument);
-              }
-              retval = new COSStreamArray(array);
-              clonedVersion.put(base, retval);
-          }
           else if( base instanceof COSStream )
           {
               COSStream originalStream = (COSStream)base;

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java Mon Jul 20 21:47:41 2015
@@ -20,9 +20,9 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.contentstream.PDContentStream;
 import org.apache.pdfbox.contentstream.operator.Operator;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSBoolean;
@@ -32,6 +32,7 @@ import org.apache.pdfbox.cos.COSNull;
 import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSStream;
+import org.apache.pdfbox.io.RandomAccessBuffer;
 import org.apache.pdfbox.io.RandomAccessRead;
 import org.apache.pdfbox.pdmodel.common.PDStream;
 
@@ -55,8 +56,18 @@ public class PDFStreamParser extends Bas
     /**
      * Constructor.
      *
-     * @param stream The stream to parse.
+     * @param contentStream The content stream to parse.
+     * @throws IOException If there is an error initializing the stream.
+     */
+    public PDFStreamParser(PDContentStream contentStream) throws IOException
+    {
+        this(new RandomAccessBuffer(contentStream.getContents()));
+    }
+    
+    /**
+     * Constructor.
      *
+     * @param stream The stream to parse.
      * @throws IOException If there is an error initializing the stream.
      */
     public PDFStreamParser( PDStream stream ) throws IOException
@@ -68,7 +79,6 @@ public class PDFStreamParser extends Bas
      * Constructor.
      *
      * @param stream The stream to parse.
-     *
      * @throws IOException If there is an error initializing the stream.
      */
     public PDFStreamParser( COSStream stream ) throws IOException
@@ -80,7 +90,6 @@ public class PDFStreamParser extends Bas
      * Constructor.
      *
      * @param input The random access read to parse.
-     *
      * @throws IOException If there is an error initializing the stream.
      */
     public PDFStreamParser( RandomAccessRead input ) throws IOException

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Mon Jul 20 21:47:41 2015
@@ -556,33 +556,23 @@ public class PDDocument implements Close
     public PDPage importPage(PDPage page) throws IOException
     {
         PDPage importedPage = new PDPage(new COSDictionary(page.getCOSObject()), resourceCache);
-        InputStream is = null;
-        OutputStream os = null;
+        InputStream in = null;
         try
         {
-            PDStream src = page.getStream();
-            if (src != null)
+            in = page.getContents();
+            if (in != null)
             {
-                PDStream dest = new PDStream(document.createCOSStream());
+                PDStream dest = new PDStream(document, page.getContents());
                 dest.addCompression();
                 importedPage.setContents(dest);
-                is = src.createInputStream();
-                os = dest.createOutputStream();
-                IOUtils.copy(is, os);
             }
             addPage(importedPage);
         }
-        finally
+        catch (IOException e)
         {
-            if (is != null)
-            {
-                is.close();
-            }
-            if (os != null)
-            {
-                os.close();
-            }
+            IOUtils.closeQuietly(in);
         }
+
         return importedPage;
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java Mon Jul 20 21:47:41 2015
@@ -16,12 +16,16 @@
  */
 package org.apache.pdfbox.pdmodel;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.SequenceInputStream;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.apache.pdfbox.contentstream.PDContentStream;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
@@ -32,7 +36,6 @@ import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.common.COSArrayList;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
-import org.apache.pdfbox.pdmodel.common.COSStreamArray;
 import org.apache.pdfbox.pdmodel.common.PDMetadata;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.common.PDStream;
@@ -111,22 +114,73 @@ public class PDPage implements COSObject
         return page;
     }
 
+    /**
+     * Returns the content streams which make up this page.
+     * 
+     * @return content stream iterator
+     */
+    public Iterator<PDStream> getContentStreams()
+    {
+        List<PDStream> streams = new ArrayList<PDStream>();
+        COSBase base = page.getDictionaryObject(COSName.CONTENTS);
+        if (base instanceof COSStream)
+        {
+            streams.add(new PDStream((COSStream) base));
+        }
+        else if (base instanceof COSArray && ((COSArray) base).size() > 0)
+        {
+            COSArray array = (COSArray)base;
+            for (int i = 0; i < streams.size(); i++)
+            {
+                COSStream stream = (COSStream) array.getObject(i);
+                streams.add(new PDStream(stream));
+            }
+        }
+        return streams.iterator();
+    }
+    
     @Override
-    public COSStream getContentStream()
+    public InputStream getContents() throws IOException
     {
         COSBase base = page.getDictionaryObject(COSName.CONTENTS);
         if (base instanceof COSStream)
         {
-            return (COSStream)base;
+            return ((COSStream)base).getUnfilteredStream();
         }
         else if (base instanceof COSArray && ((COSArray) base).size() > 0)
         {
-            return new COSStreamArray((COSArray) base);
+            COSArray streams = (COSArray)base;
+            byte[] delimiter = new byte[] { '\n' };
+            List<InputStream> inputStreams = new ArrayList<InputStream>();
+            for (int i = 0; i < streams.size(); i++)
+            {
+                COSStream stream = (COSStream)streams.getObject(i);
+                inputStreams.add(stream.getUnfilteredStream());
+                inputStreams.add(new ByteArrayInputStream(delimiter));
+            }
+            return new SequenceInputStream(Collections.enumeration(inputStreams));
         }
         return null;
     }
 
     /**
+     * Returns true if this page has contents.
+     */
+    public boolean hasContents()
+    {
+        COSBase contents = page.getDictionaryObject(COSName.CONTENTS);
+        if (contents instanceof COSStream)
+        {
+            return ((COSStream) contents).size() > 0;
+        }
+        else if (contents instanceof COSArray)
+        {
+            return ((COSArray) contents).size() > 0;
+        }
+        return false;
+    }
+
+    /**
      * A dictionary containing any resources required by the page.
      */
     @Override
@@ -435,25 +489,28 @@ public class PDPage implements COSObject
     }
 
     /**
-     * This will get the contents of the PDF Page, in the case that the contents of the page is an
-     * array then then the entire array of streams will be be wrapped and appear as a single stream.
+     * This will set the contents of this page.
      * 
-     * @return The page content stream.
-     * @throws IOException If there is an error obtaining the stream.
+     * @param contents The new contents of the page.
      */
-    public PDStream getStream() throws IOException
+    public void setContents(PDStream contents)
     {
-        return PDStream.createFromCOS(page.getDictionaryObject(COSName.CONTENTS));
+        page.setItem(COSName.CONTENTS, contents);
     }
 
     /**
      * This will set the contents of this page.
-     * 
-     * @param contents The new contents of the page.
+     *
+     * @param contents Array of new contents of the page.
      */
-    public void setContents(PDStream contents)
+    public void setContents(List<PDStream> contents)
     {
-        page.setItem(COSName.CONTENTS, contents);
+        COSArray array = new COSArray();
+        for (PDStream stream : contents)
+        {
+            array.add(stream);
+        }
+        page.setItem(COSName.CONTENTS, array);
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java Mon Jul 20 21:47:41 2015
@@ -23,8 +23,6 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.text.NumberFormat;
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Locale;
 import java.util.Stack;
 import org.apache.commons.logging.Log;
@@ -34,7 +32,6 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.pdfwriter.COSWriter;
-import org.apache.pdfbox.pdmodel.common.COSStreamArray;
 import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDPropertyList;
 import org.apache.pdfbox.pdmodel.font.PDFont;
@@ -96,12 +93,13 @@ public final class PDPageContentStream i
      *
      * @param document The document the page is part of.
      * @param sourcePage The page to write the contents to.
-     * @param appendContent Indicates whether content will be overwritten. If false all previous content is deleted.
+     * @param appendContent Indicates whether content will be overwritten. If false all previous
+     *                      content is deleted.
      * @param compress Tell if the content stream should compress the page contents.
      * @throws IOException If there is an error writing to the page contents.
      */
-    public PDPageContentStream(PDDocument document, PDPage sourcePage, boolean appendContent, boolean compress)
-            throws IOException
+    public PDPageContentStream(PDDocument document, PDPage sourcePage, boolean appendContent,
+                               boolean compress) throws IOException
     {
         this(document, sourcePage, appendContent, compress, false);
     }
@@ -111,104 +109,102 @@ public final class PDPageContentStream i
      *
      * @param document The document the page is part of.
      * @param sourcePage The page to write the contents to.
-     * @param appendContent Indicates whether content will be overwritten. If false all previous content is deleted.
+     * @param appendContent Indicates whether content will be overwritten. If false all previous
+     *                      content is deleted.
      * @param compress Tell if the content stream should compress the page contents.
      * @param resetContext Tell if the graphic context should be reseted.
      * @throws IOException If there is an error writing to the page contents.
      */
-    public PDPageContentStream(PDDocument document, PDPage sourcePage, boolean appendContent, boolean compress,
-            boolean resetContext) throws IOException
+    public PDPageContentStream(PDDocument document, PDPage sourcePage, boolean appendContent,
+                               boolean compress, boolean resetContext) throws IOException
     {
         this.document = document;
         
-        // Get the pdstream from the source page instead of creating a new one
-        PDStream contents = sourcePage.getStream();
-        boolean hasContent = contents != null;
-
         // If request specifies the need to append to the document
-        if (appendContent && hasContent)
+        if (appendContent && sourcePage.hasContents())
         {
-
-            // Create a pdstream to append new content
+            // Create a stream to append new content
             PDStream contentsToAppend = new PDStream(document);
-
-            // This will be the resulting COSStreamArray after existing and new streams are merged
-            COSStreamArray compoundStream;
-
-            // If contents is already an array, a new stream is simply appended to it
-            if (contents.getStream() instanceof COSStreamArray)
-            {
-                compoundStream = (COSStreamArray) contents.getStream();
-                compoundStream.appendStream(contentsToAppend.getStream());
+            
+            // Add new stream to contents array
+            COSBase contents = sourcePage.getCOSObject().getDictionaryObject(COSName.CONTENTS);
+            COSArray array;
+            if (contents instanceof COSArray)
+            {
+                // If contents is already an array, a new stream is simply appended to it
+                array = (COSArray)contents;
+                array.add(contentsToAppend);
             }
             else
             {
-                // Creates the COSStreamArray and adds the current stream plus a new one to it
-                COSArray newArray = new COSArray();
-                newArray.add(contents.getCOSObject());
-                newArray.add(contentsToAppend.getCOSObject());
-                compoundStream = new COSStreamArray(newArray);
+                // Creates a new array and adds the current stream plus a new one to it
+                array = new COSArray();
+                array.add(contents);
+                array.add(contentsToAppend);
             }
 
             if (compress)
             {
-                List<COSName> filters = new ArrayList<COSName>();
-                filters.add(COSName.FLATE_DECODE);
-                contentsToAppend.setFilters(filters);
+                contentsToAppend.addCompression();
             }
 
+            // save the initial/unmodified graphics context
             if (resetContext)
             {
                 // create a new stream to encapsulate the existing stream
                 PDStream saveGraphics = new PDStream(document);
                 output = saveGraphics.createOutputStream();
+                
                 // save the initial/unmodified graphics context
                 saveGraphicsState();
                 close();
+                
                 if (compress)
                 {
-                    List<COSName> filters = new ArrayList<COSName>();
-                    filters.add(COSName.FLATE_DECODE);
-                    saveGraphics.setFilters(filters);
+                    saveGraphics.addCompression();
                 }
+                
                 // insert the new stream at the beginning
-                compoundStream.insertCOSStream(saveGraphics);
+                array.add(0, saveGraphics.getStream());
             }
 
             // Sets the compoundStream as page contents
-            sourcePage.setContents(new PDStream(compoundStream));
+            sourcePage.getCOSObject().setItem(COSName.CONTENTS, array);
             output = contentsToAppend.createOutputStream();
+
+            // restore the initial/unmodified graphics context
             if (resetContext)
             {
-                // restore the initial/unmodified graphics context
                 restoreGraphicsState();
             }
         }
         else
         {
-            if (hasContent)
+            if (sourcePage.hasContents())
             {
                 LOG.warn("You are overwriting an existing content, you should use the append mode");
             }
-            contents = new PDStream(document);
+            PDStream contents = new PDStream(document);
             if (compress)
             {
-                List<COSName> filters = new ArrayList<COSName>();
-                filters.add(COSName.FLATE_DECODE);
-                contents.setFilters(filters);
+                contents.addCompression();
             }
             sourcePage.setContents(contents);
             output = contents.createOutputStream();
         }
-        formatDecimal.setMaximumFractionDigits(10);
-        formatDecimal.setGroupingUsed(false);
-        // this has to be done here, as the resources will be set to null when reseting the content stream
+        
+        // this has to be done here, as the resources will be set to null when resetting the content
+        // stream
         resources = sourcePage.getResources();
         if (resources == null)
         {
             resources = new PDResources();
             sourcePage.setResources(resources);
         }
+
+        // configure NumberFormat
+        formatDecimal.setMaximumFractionDigits(10);
+        formatDecimal.setGroupingUsed(false);
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java Mon Jul 20 21:47:41 2015
@@ -29,6 +29,7 @@ import java.util.Map;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNull;
 import org.apache.pdfbox.cos.COSStream;
@@ -71,6 +72,17 @@ public class PDStream implements COSObje
     }
 
     /**
+     * This will create a new PDStream object.
+     *
+     * @param document
+     *            The document that the stream will be part of.
+     */
+    public PDStream(COSDocument document)
+    {
+        stream = document.createCOSStream();
+    }
+
+    /**
      * Constructor.
      * 
      * @param str
@@ -87,14 +99,48 @@ public class PDStream implements COSObje
      * 
      * @param doc
      *            The document that will hold the stream.
-     * @param str
+     * @param input
+     *            The stream parameter.
+     * @throws IOException
+     *             If there is an error creating the stream in the document.
+     */
+    public PDStream(PDDocument doc, InputStream input) throws IOException
+    {
+        this(doc, input, false);
+    }
+
+    /**
+     * Constructor. Reads all data from the input stream and embeds it into the
+     * document, this will close the InputStream.
+     *
+     * @param doc
+     *            The document that will hold the stream.
+     * @param input
+     *            The stream parameter.
+     * @throws IOException
+     *             If there is an error creating the stream in the document.
+     */
+    public PDStream(COSDocument doc, InputStream input) throws IOException
+    {
+        this(doc, input, false);
+    }
+
+    /**
+     * Constructor. Reads all data from the input stream and embeds it into the
+     * document, this will close the InputStream.
+     *
+     * @param doc
+     *            The document that will hold the stream.
+     * @param input
      *            The stream parameter.
+     * @param filtered
+     *            True if the stream already has a filter applied.
      * @throws IOException
      *             If there is an error creating the stream in the document.
      */
-    public PDStream(PDDocument doc, InputStream str) throws IOException
+    public PDStream(PDDocument doc, InputStream input, boolean filtered) throws IOException
     {
-        this(doc, str, false);
+        this(doc.getDocument(), input, filtered);
     }
 
     /**
@@ -103,20 +149,19 @@ public class PDStream implements COSObje
      * 
      * @param doc
      *            The document that will hold the stream.
-     * @param str
+     * @param input
      *            The stream parameter.
      * @param filtered
      *            True if the stream already has a filter applied.
      * @throws IOException
      *             If there is an error creating the stream in the document.
      */
-    public PDStream(PDDocument doc, InputStream str, boolean filtered)
-            throws IOException
+    public PDStream(COSDocument doc, InputStream input, boolean filtered) throws IOException
     {
         OutputStream output = null;
         try
         {
-            stream = doc.getDocument().createCOSStream();
+            stream = doc.createCOSStream();
             if (filtered)
             {
                 output = stream.createFilteredStream();
@@ -125,12 +170,7 @@ public class PDStream implements COSObje
             {
                 output = stream.createUnfilteredStream();
             }
-            byte[] buffer = new byte[1024];
-            int amountRead;
-            while ((amountRead = str.read(buffer)) != -1)
-            {
-                output.write(buffer, 0, amountRead);
-            }
+            IOUtils.copy(input, output);
         } 
         finally
         {
@@ -138,9 +178,9 @@ public class PDStream implements COSObje
             {
                 output.close();
             }
-            if (str != null)
+            if (input != null)
             {
-                str.close();
+                input.close();
             }
         }
     }
@@ -161,41 +201,6 @@ public class PDStream implements COSObje
     }
 
     /**
-     * Create a pd stream from either a regular COSStream on a COSArray of cos
-     * streams.
-     * 
-     * @param base
-     *            Either a COSStream or COSArray.
-     * @return A PDStream or null if base is null.
-     * @throws IOException
-     *             If there is an error creating the PDStream.
-     */
-    public static PDStream createFromCOS(COSBase base) throws IOException
-    {
-        PDStream retval = null;
-        if (base instanceof COSStream)
-        {
-            retval = new PDStream((COSStream) base);
-        } 
-        else if (base instanceof COSArray)
-        {
-            if (((COSArray) base).size() > 0)
-            {
-                retval = new PDStream(new COSStreamArray((COSArray) base));
-            }
-        } 
-        else
-        {
-            if (base != null)
-            {
-                throw new IOException("Contents are unknown type:"
-                        + base.getClass().getName());
-            }
-        }
-        return retval;
-    }
-
-    /**
      * Convert this standard java object to a COS object.
      * 
      * @return The cos object that matches this Java object.
@@ -271,7 +276,7 @@ public class PDStream implements COSObje
 
     /**
      * Get the cos stream associated with this object.
-     * 
+     *
      * @return The cos object that matches this Java object.
      */
     public COSStream getStream()
@@ -607,5 +612,4 @@ public class PDStream implements COSObje
     {
         this.stream.setInt(COSName.DL, decodedStreamLength);
     }
-
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3CharProc.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3CharProc.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3CharProc.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType3CharProc.java Mon Jul 20 21:47:41 2015
@@ -17,11 +17,14 @@
 
 package org.apache.pdfbox.pdmodel.font;
 
+import java.io.IOException;
+import java.io.InputStream;
 import org.apache.pdfbox.contentstream.PDContentStream;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.util.Matrix;
 
 /**
@@ -50,11 +53,16 @@ public final class PDType3CharProc imple
     {
         return font;
     }
+    
+    public PDStream getContentStream()
+    {
+        return new PDStream(charStream);
+    }
 
     @Override
-    public COSStream getContentStream()
+    public InputStream getContents() throws IOException
     {
-        return charStream;
+        return charStream.getUnfilteredStream();
     }
 
     @Override

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/form/PDFormXObject.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/form/PDFormXObject.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/form/PDFormXObject.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/form/PDFormXObject.java Mon Jul 20 21:47:41 2015
@@ -17,13 +17,13 @@
 package org.apache.pdfbox.pdmodel.graphics.form;
 
 import java.awt.geom.AffineTransform;
-
+import java.io.IOException;
+import java.io.InputStream;
 import org.apache.pdfbox.contentstream.PDContentStream;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSFloat;
 import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.ResourceCache;
@@ -121,11 +121,16 @@ public class PDFormXObject extends PDXOb
         }
         return group;
     }
+    
+    public PDStream getContentStream()
+    {
+        return new PDStream(getCOSStream());
+    }
 
     @Override
-    public COSStream getContentStream()
+    public InputStream getContents() throws IOException
     {
-        return getCOSStream();
+        return getCOSStream().getUnfilteredStream();
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/pattern/PDTilingPattern.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/pattern/PDTilingPattern.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/pattern/PDTilingPattern.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/pattern/PDTilingPattern.java Mon Jul 20 21:47:41 2015
@@ -16,6 +16,8 @@
  */
 package org.apache.pdfbox.pdmodel.graphics.pattern;
 
+import java.io.IOException;
+import java.io.InputStream;
 import org.apache.pdfbox.contentstream.PDContentStream;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSDictionary;
@@ -23,6 +25,7 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.common.PDStream;
 
 /**
  * A tiling pattern dictionary.
@@ -165,11 +168,16 @@ public class PDTilingPattern extends PDA
         float yStep = getCOSObject().getFloat( COSName.Y_STEP, 0 );
         return yStep == Short.MAX_VALUE ? 0 : yStep;
     }
+    
+    public PDStream getContentStream()
+    {
+        return new PDStream((COSStream)getCOSObject());
+    }
 
     @Override
-    public COSStream getContentStream()
+    public InputStream getContents() throws IOException
     {
-        return (COSStream)getCOSObject();
+        return ((COSStream)getCOSObject()).getUnfilteredStream();
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java Mon Jul 20 21:47:41 2015
@@ -298,9 +298,8 @@ public class PDFTextStripper extends PDF
 
         for (PDPage page : pages)
         {
-            PDStream contentStream = page.getStream();
             currentPageNo++;
-            if (contentStream != null)
+            if (page.hasContents())
             {
                 processPage(page);
             }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripperByArea.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripperByArea.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripperByArea.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripperByArea.java Mon Jul 20 21:47:41 2015
@@ -25,9 +25,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Vector;
-
 import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.common.PDStream;
 
 /**
  * This will extract text from a specified region in the PDF.
@@ -118,9 +116,8 @@ public class PDFTextStripperByArea exten
             regionCharacterList.put( regionName, regionCharactersByArticle );
             regionText.put( regionName, new StringWriter() );
         }
-
-        PDStream contentStream = page.getStream();
-        if( contentStream != null )
+        
+        if( page.hasContents() )
         {
             processPage( page );
         }

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestSymmetricKeyEncryption.java Mon Jul 20 21:47:41 2015
@@ -31,7 +31,6 @@ import javax.crypto.Cipher;
 import junit.framework.TestCase;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
@@ -241,16 +240,14 @@ public class TestSymmetricKeyEncryption
         int numSrcPages = document.getNumberOfPages();
         PDFRenderer pdfRenderer = new PDFRenderer(document);
         List<BufferedImage> srcImgTab = new ArrayList<BufferedImage>();
-        List<ByteArrayOutputStream> srcContentStreamTab = new ArrayList<ByteArrayOutputStream>();
+        List<byte[]> srcContentStreamTab = new ArrayList<byte[]>();
         for (int i = 0; i < numSrcPages; ++i)
         {
             srcImgTab.add(pdfRenderer.renderImage(i));
-            COSStream contentStream = document.getPage(i).getContentStream();
-            InputStream unfilteredStream = contentStream.getUnfilteredStream();
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            IOUtils.copy(unfilteredStream, baos);
+            InputStream unfilteredStream = document.getPage(i).getContents();
+            byte[] bytes = IOUtils.toByteArray(unfilteredStream);
             unfilteredStream.close();
-            srcContentStreamTab.add(baos);
+            srcContentStreamTab.add(bytes);
         }
 
         PDDocument encryptedDoc = encrypt(keyLength, sizePriorToEncr, document,
@@ -265,14 +262,12 @@ public class TestSymmetricKeyEncryption
             ValidateXImage.checkIdent(bim, srcImgTab.get(i));
 
             // compare content streams
-            COSStream contentStreamDecr = encryptedDoc.getPage(i).getContentStream();
-            InputStream unfilteredStream = contentStreamDecr.getUnfilteredStream();
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            IOUtils.copy(unfilteredStream, baos);
+            InputStream unfilteredStream = encryptedDoc.getPage(i).getContents();
+            byte[] bytes = IOUtils.toByteArray(unfilteredStream);
             unfilteredStream.close();
             Assert.assertArrayEquals("content stream of page " + i + " not identical",
-                    srcContentStreamTab.get(i).toByteArray(),
-                    baos.toByteArray());
+                    srcContentStreamTab.get(i),
+                    bytes);
         }
 
         File pdfFile = new File(testResultsDir, prefix + keyLength + "-bit-decrypted.pdf");

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/io/TestRandomAccessBuffer.java Mon Jul 20 21:47:41 2015
@@ -285,76 +285,6 @@ public class TestRandomAccessBuffer exte
         buffer.close();
     }
     
-    public void testSequenceRandomAccessRead() throws IOException
-    {
-        RandomAccessBuffer buffer1 = new RandomAccessBuffer();
-        buffer1.write(new byte[] {0,1,2,3});
-        RandomAccessBuffer buffer2 = new RandomAccessBuffer();
-        buffer2.write(new byte[] {4});
-        RandomAccessBuffer buffer3 = new RandomAccessBuffer();
-        buffer3.write(new byte[] {5,6,7});
-        RandomAccessBuffer buffer4 = new RandomAccessBuffer();
-        buffer4.write(new byte[] {8,9,10,11,12});
-        RandomAccessBuffer bufferEmpty = new RandomAccessBuffer();
-        Vector<RandomAccessRead> buffers = new Vector<RandomAccessRead>();
-        buffers.add(buffer1);
-        buffers.add(bufferEmpty);
-        buffers.add(buffer2);
-        buffers.add(buffer3);
-        buffers.add(buffer4);
-        // read the whole buffer
-        SequenceRandomAccessRead sequenceBuffer = new SequenceRandomAccessRead(buffers);
-        int byteRead = -1;
-        int sum = 0;
-        while((byteRead = sequenceBuffer.read()) > -1)
-        {
-            sum += byteRead;
-        }
-        assertEquals(78, sum);
-        sequenceBuffer.close();
-        buffers = new Vector<RandomAccessRead>();
-        buffers.add(buffer1);
-        buffers.add(bufferEmpty);
-        buffers.add(buffer2);
-        buffers.add(buffer3);
-        buffers.add(buffer4);
-        // read parts of the buffer
-        sequenceBuffer = new SequenceRandomAccessRead(buffers);
-        sequenceBuffer.seek(2);
-        byte[] bytesRead = new byte[4];
-        assertEquals(4,sequenceBuffer.read(bytesRead));
-        sum = 0;
-        for (byte element : bytesRead)
-        {
-            sum += element;
-        }
-        assertEquals(14, sum);
-        // seek beyond EOF
-        sequenceBuffer.seek(sequenceBuffer.length()+1);
-        // check isEOF
-        assertTrue(sequenceBuffer.isEOF());
-        // check read
-        assertEquals(-1, sequenceBuffer.read());
-
-        // test some read/rewind stuff
-        sequenceBuffer.seek(3);
-        assertEquals(3, sequenceBuffer.read());
-        assertEquals(4, sequenceBuffer.read());
-        sequenceBuffer.rewind(1);
-        assertEquals(4, sequenceBuffer.read());
-        assertEquals(5, sequenceBuffer.read());
-        sequenceBuffer.rewind(1);
-        assertEquals(5, sequenceBuffer.read());
-        
-        // close
-        sequenceBuffer.close();
-        buffer1.close();
-        buffer2.close();
-        buffer3.close();
-        buffer4.close();
-        bufferEmpty.close();
-    }
-    
     public void testPDFBOX1490() throws Exception
     {
         // create a buffer filled with 1024 * "0" 

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestPDPageContentStream.java Mon Jul 20 21:47:41 2015
@@ -20,7 +20,6 @@ import java.io.IOException;
 import junit.framework.TestCase;
 import org.apache.pdfbox.contentstream.operator.Operator;
 import org.apache.pdfbox.cos.COSFloat;
-import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdfparser.PDFStreamParser;
 
 /**
@@ -41,8 +40,7 @@ public class TestPDPageContentStream ext
         contentStream.close();
 
         // now read the PDF stream and verify that the CMYK values are correct
-        COSStream stream = page.getStream().getStream();
-        PDFStreamParser parser = new PDFStreamParser(stream);
+        PDFStreamParser parser = new PDFStreamParser(page);
         parser.parse();
         java.util.List<Object>  pageTokens = parser.getTokens();
         // expected five tokens :
@@ -67,8 +65,7 @@ public class TestPDPageContentStream ext
         contentStream.close();
 
         // now read the PDF stream and verify that the CMYK values are correct
-        stream = page.getStream().getStream();
-        parser = new PDFStreamParser(stream);
+        parser = new PDFStreamParser(page);
         parser.parse();
         pageTokens = parser.getTokens();
         // expected five tokens  :

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java Mon Jul 20 21:47:41 2015
@@ -32,7 +32,6 @@ import org.apache.pdfbox.cos.COSFloat;
 import org.apache.pdfbox.cos.COSInteger;
 import org.apache.pdfbox.cos.COSString;
 import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
 import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPattern;
@@ -66,8 +65,7 @@ public class PreflightContentStream exte
     {
         try
         {
-            PDStream pstream = this.processeedPage.getStream();
-            if (pstream != null)
+            if (this.processeedPage.hasContents())
             {
                 processPage(this.processeedPage);
             }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/ICCProfileWrapper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/ICCProfileWrapper.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/ICCProfileWrapper.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/graphic/ICCProfileWrapper.java Mon Jul 20 21:47:41 2015
@@ -24,22 +24,23 @@ package org.apache.pdfbox.preflight.grap
 import java.awt.color.ICC_ColorSpace;
 import java.awt.color.ICC_Profile;
 import java.io.IOException;
-
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
-import org.apache.pdfbox.pdmodel.common.PDStream;
-import static org.apache.pdfbox.preflight.PreflightConstants.DOCUMENT_DICTIONARY_KEY_OUTPUT_INTENTS;
-import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_INVALID;
-import static org.apache.pdfbox.preflight.PreflightConstants.OUTPUT_INTENT_DICTIONARY_KEY_DEST_OUTPUT_PROFILE;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightDocument;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.utils.COSUtils;
 
+
+import static org.apache.pdfbox.preflight.PreflightConstants.DOCUMENT_DICTIONARY_KEY_OUTPUT_INTENTS;
+import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_INVALID;
+import static org.apache.pdfbox.preflight.PreflightConstants.OUTPUT_INTENT_DICTIONARY_KEY_DEST_OUTPUT_PROFILE;
+
 /**
  * This class embeds an instance of java.awt.color.ICC_Profile which represent the ICCProfile defined by the
  * DestOutputItents key of the OutputIntents of the PDF.
@@ -134,11 +135,10 @@ public class ICCProfileWrapper
             {
                 try
                 {
-                    PDStream stream = PDStream.createFromCOS(COSUtils.getAsStream(destOutputProfile,
-                            document.getDocument()));
+                    COSStream stream = COSUtils.getAsStream(destOutputProfile, document.getDocument());
                     if (stream != null)
                     {
-                        ICC_Profile iccp = ICC_Profile.getInstance(stream.createInputStream());
+                        ICC_Profile iccp = ICC_Profile.getInstance(stream.getUnfilteredStream());
                         return new ICCProfileWrapper(iccp);
                     }
                 }

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java Mon Jul 20 21:47:41 2015
@@ -21,84 +21,12 @@
 
 package org.apache.pdfbox.preflight.process;
 
-import static org.apache.pdfbox.preflight.PreflightConfiguration.ACTIONS_PROCESS;
-import static org.apache.pdfbox.preflight.PreflightConstants.DICTIONARY_KEY_ADDITIONAL_ACTION;
-import static org.apache.pdfbox.preflight.PreflightConstants.DOCUMENT_DICTIONARY_KEY_OUTPUT_INTENTS;
-import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_ACTION_FORBIDDEN_ADDITIONAL_ACTION;
-import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_ACTION_FORBIDDEN_ACTIONS_NAMED;
-import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_INVALID;
-import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_MULTIPLE;
-import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_TOO_RECENT;
-import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY;
-import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_OUTPUT_INTENT_S_VALUE_INVALID;
-import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_LANG_NOT_RFC1766;
-import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_NOCATALOG;
-import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_TRAILER_CATALOG_EMBEDDEDFILES;
-import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_TRAILER_CATALOG_OCPROPERTIES;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_Adobe;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR001;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR002;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR003;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR005;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR006;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_001;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_002;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_003;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_005;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_CGATS_TR_006;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_ERIMM;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_EUROSB104;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_EUROSB204;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA27;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA28;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA29;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA30;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA31;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA32;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA33;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA34;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA35;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA36;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA37;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA38;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA39;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA40;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA41;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA42;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA43;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA44;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA45;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA46;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_FOGRA47;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_IFRA26;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_JC200103;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_JC200104;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_JCN2002;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_JCW2003;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_RIMM;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_ROMM;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_bg_sRGB;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_eciRGB;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_opRGB;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_sRGB;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_sRGB_IEC;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_sYCC;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_scRGB;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_scRGB_nl;
-import static org.apache.pdfbox.preflight.PreflightConstants.ICC_CHARACTERIZATION_DATA_REGISTRY_scYCC_nl;
-import static org.apache.pdfbox.preflight.PreflightConstants.OUTPUT_INTENT_DICTIONARY_KEY_DEST_OUTPUT_PROFILE;
-import static org.apache.pdfbox.preflight.PreflightConstants.OUTPUT_INTENT_DICTIONARY_KEY_INFO;
-import static org.apache.pdfbox.preflight.PreflightConstants.OUTPUT_INTENT_DICTIONARY_KEY_OUTPUT_CONDITION_IDENTIFIER;
-import static org.apache.pdfbox.preflight.PreflightConstants.OUTPUT_INTENT_DICTIONARY_KEY_S;
-import static org.apache.pdfbox.preflight.PreflightConstants.OUTPUT_INTENT_DICTIONARY_VALUE_GTS_PDFA1;
-
 import java.awt.color.ICC_Profile;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
@@ -106,12 +34,12 @@ import org.apache.pdfbox.cos.COSDocument
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSObject;
+import org.apache.pdfbox.cos.COSObjectKey;
+import org.apache.pdfbox.cos.COSStream;
 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.PDStream;
-import org.apache.pdfbox.cos.COSObjectKey;
 import org.apache.pdfbox.preflight.PreflightConfiguration;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -120,6 +48,10 @@ import org.apache.pdfbox.preflight.graph
 import org.apache.pdfbox.preflight.utils.COSUtils;
 import org.apache.pdfbox.preflight.utils.ContextHelper;
 
+
+import static org.apache.pdfbox.preflight.PreflightConfiguration.ACTIONS_PROCESS;
+import static org.apache.pdfbox.preflight.PreflightConstants.*;
+
 /**
  * This ValidationProcess check if the Catalog entries are confirming with the PDF/A-1b specification.
  */
@@ -417,7 +349,7 @@ public class CatalogValidationProcess ex
             // keep reference to avoid multiple profile definition
             mapDestOutputProfile.put(new COSObjectKey((COSObject) destOutputProfile), true);
             COSDocument cosDocument = ctx.getDocument().getDocument();
-            PDStream stream = PDStream.createFromCOS(COSUtils.getAsStream(destOutputProfile, cosDocument));
+            COSStream stream = COSUtils.getAsStream(destOutputProfile, cosDocument);
             if (stream == null)
             {
                 addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY,
@@ -425,7 +357,7 @@ public class CatalogValidationProcess ex
                 return;
             }
 
-            ICC_Profile iccp = ICC_Profile.getInstance(stream.createInputStream());
+            ICC_Profile iccp = ICC_Profile.getInstance(stream.getUnfilteredStream());
             
             if (!validateICCProfileNEntry(stream, ctx, iccp))
             {
@@ -487,7 +419,7 @@ public class CatalogValidationProcess ex
         return true;
     }
 
-    private boolean validateICCProfileNEntry(PDStream stream, PreflightContext ctx, ICC_Profile iccp)
+    private boolean validateICCProfileNEntry(COSStream stream, PreflightContext ctx, ICC_Profile iccp)
     {
         COSDictionary streamDict = (COSDictionary) stream.getCOSObject();
         if (!streamDict.containsKey(COSName.N))

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java?rev=1692027&r1=1692026&r2=1692027&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/MetadataValidationProcess.java Mon Jul 20 21:47:41 2015
@@ -30,15 +30,14 @@ import java.util.ArrayList;
 import java.util.List;
 import javax.imageio.ImageIO;
 import javax.xml.bind.DatatypeConverter;
-
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSObject;
+import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
@@ -276,9 +275,9 @@ public class MetadataValidationProcess e
             throw new XpacketParsingException("Failed while retrieving xpacket", error);
         }
 
-        PDStream stream = PDStream.createFromCOS(metadataDictionnary);
+        COSStream stream = (COSStream)metadataDictionnary;
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        InputStream is = stream.createInputStream();
+        InputStream is = stream.getUnfilteredStream();
         IOUtils.copy(is, bos);
         is.close();
         bos.close();



Mime
View raw message