pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1799083 - in /pdfbox/trunk: ./ pdfbox/src/main/java/org/apache/pdfbox/pdfparser/
Date Sun, 18 Jun 2017 13:03:47 GMT
Author: lehmi
Date: Sun Jun 18 13:03:47 2017
New Revision: 1799083

URL: http://svn.apache.org/viewvc?rev=1799083&view=rev
Log:
PDFBOX-3536: provide another unread method for byte arrays to avoid array copies

Modified:
    pdfbox/trunk/   (props changed)
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/RandomAccessSource.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/SequentialSource.java

Propchange: pdfbox/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Jun 18 13:03:47 2017
@@ -1,3 +1,3 @@
-/pdfbox/branches/2.0:1760418,1761484,1762133,1763609,1779822,1780783,1780789,1782684,1784450,1792784,1795704,1795712
+/pdfbox/branches/2.0:1760418,1761484,1762133,1763609,1779822,1780783,1780789,1782684,1784450,1792784,1795704,1795712,1799081
 /pdfbox/branches/no-awt:1618517-1621410
 /pdfbox/no-awt:1618514-1618516

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java?rev=1799083&r1=1799082&r2=1799083&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java Sun
Jun 18 13:03:47 2017
@@ -96,6 +96,13 @@ final class InputStreamSource implements
     }
 
     @Override
+    public void unread(byte[] bytes, int start, int len) throws IOException
+    {
+        input.unread(bytes, start, len);
+        position -= len - start;
+    }
+
+    @Override
     public byte[] readFully(int length) throws IOException
     {
         byte[] bytes = new byte[length];

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=1799083&r1=1799082&r2=1799083&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 Sun
Jun 18 13:03:47 2017
@@ -20,7 +20,6 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -424,7 +423,7 @@ public class PDFStreamParser extends Bas
                     noBinData = false;
                 }
             }
-            pdfSource.unread(Arrays.copyOfRange(binCharTestArr, 0, readBytes));
+            pdfSource.unread(binCharTestArr, 0, readBytes);
         }
         if (!noBinData)
         {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/RandomAccessSource.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/RandomAccessSource.java?rev=1799083&r1=1799082&r2=1799083&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/RandomAccessSource.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/RandomAccessSource.java
Sun Jun 18 13:03:47 2017
@@ -80,6 +80,12 @@ final class RandomAccessSource implement
     }
 
     @Override
+    public void unread(byte[] bytes, int start, int len) throws IOException
+    {
+        reader.rewind(len - start);
+    }
+
+    @Override
     public byte[] readFully(int length) throws IOException
     {
         return reader.readFully(length);

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/SequentialSource.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/SequentialSource.java?rev=1799083&r1=1799082&r2=1799083&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/SequentialSource.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/SequentialSource.java Sun
Jun 18 13:03:47 2017
@@ -74,19 +74,29 @@ interface SequentialSource extends Close
      * Unreads a single byte.
      *
      * @param b byte array to push back
-     * @throws IOException If there is an error while seeking
+     * @throws IOException if there is an error while unreading
      */
     void unread(int b) throws IOException;
 
     /**
      * Unreads an array of bytes.
      *
-     * @param bytes byte array to push back
-     * @throws IOException If there is an error while seeking
+     * @param bytes byte array to be unread
+     * @throws IOException if there is an error while unreading
      */
     void unread(byte[] bytes) throws IOException;
 
     /**
+     * Unreads a portion of an array of bytes.
+     *
+     * @param bytes byte array to be unread
+     * @param start start index
+     * @param len number of bytes to be unread
+     * @throws IOException if there is an error while unreading
+     */
+    void unread(byte[] bytes, int start, int len) throws IOException;
+
+    /**
      * Reads a given number of bytes in its entirety.
      *
      * @param length the number of bytes to be read



Mime
View raw message