pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gbaill...@apache.org
Subject svn commit: r1558570 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: cos/COSStream.java io/RandomAccessBuffer.java
Date Wed, 15 Jan 2014 21:34:22 GMT
Author: gbailleul
Date: Wed Jan 15 21:34:22 2014
New Revision: 1558570

URL: http://svn.apache.org/r1558570
Log:
PDFBOX-1625:
* implement a clone method on RandomAccessBuffer
* clone RandomAccessBuffer in COSStream when necessary

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java?rev=1558570&r1=1558569&r2=1558570&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java Wed Jan 15 21:34:22
2014
@@ -28,13 +28,10 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.filter.Filter;
 import org.apache.pdfbox.filter.FilterManager;
+import org.apache.pdfbox.io.*;
 import org.apache.pdfbox.pdfparser.PDFStreamParser;
 import org.apache.pdfbox.exceptions.COSVisitorException;
 import org.apache.pdfbox.io.IOUtils;
-import org.apache.pdfbox.io.RandomAccess;
-import org.apache.pdfbox.io.RandomAccessFileInputStream;
-import org.apache.pdfbox.io.RandomAccessFileOutputStream;
-
 /**
  * This class represents a stream object in a PDF document.
  *
@@ -61,6 +58,16 @@ public class COSStream extends COSDictio
      */
     private RandomAccessFileOutputStream unFilteredStream;
 
+    private RandomAccess clone (RandomAccess file) {
+        if (file == null) {
+            return null;
+        } else if (file instanceof RandomAccessFile) {
+            return file;
+        } else {
+            return ((RandomAccessBuffer)file).clone();
+        }
+    }
+
     /**
      * Constructor.  Creates a new stream with an empty dictionary.
      *
@@ -69,7 +76,7 @@ public class COSStream extends COSDictio
     public COSStream( RandomAccess storage )
     {
         super();
-        file = storage;
+        file = clone(storage);
     }
 
     /**
@@ -81,7 +88,7 @@ public class COSStream extends COSDictio
     public COSStream( COSDictionary dictionary, RandomAccess storage )
     {
         super( dictionary );
-        file = storage;
+        file = clone(storage);
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java?rev=1558570&r1=1558569&r2=1558570&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessBuffer.java Wed Jan
15 21:34:22 2014
@@ -59,6 +59,30 @@ public class RandomAccessBuffer implemen
         bufferListMaxIndex = 0;
     }
 
+    @Override
+    public RandomAccessBuffer clone() {
+        RandomAccessBuffer copy = new RandomAccessBuffer();
+
+        copy.bufferList = new ArrayList<byte[]>(bufferList.size());
+        for (byte [] buffer : bufferList) {
+            byte [] newBuffer = new byte [buffer.length];
+            System.arraycopy(buffer,0,newBuffer,0,buffer.length);
+            copy.bufferList.add(newBuffer);
+        }
+        if (currentBuffer!=null) {
+            copy.currentBuffer = copy.bufferList.get(copy.bufferList.size()-1);
+        } else {
+            copy.currentBuffer = null;
+        }
+        copy.pointer = pointer;
+        copy.currentBufferPointer = currentBufferPointer;
+        copy.size = size;
+        copy.bufferListIndex = bufferListIndex;
+        copy.bufferListMaxIndex = bufferListMaxIndex;
+
+        return copy;
+    }
+
     /**
      * {@inheritDoc}
      */



Mime
View raw message