You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2017/06/18 12:59:15 UTC
svn commit: r1799081 - in
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser:
InputStreamSource.java PDFStreamParser.java RandomAccessSource.java
SequentialSource.java
Author: lehmi
Date: Sun Jun 18 12:59:15 2017
New Revision: 1799081
URL: http://svn.apache.org/viewvc?rev=1799081&view=rev
Log:
PDFBOX-3536: provide another unread method for byte arrays to avoid array copies
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/RandomAccessSource.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/SequentialSource.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java?rev=1799081&r1=1799080&r2=1799081&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/InputStreamSource.java Sun Jun 18 12:59:15 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/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java?rev=1799081&r1=1799080&r2=1799081&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java Sun Jun 18 12:59:15 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/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/RandomAccessSource.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/RandomAccessSource.java?rev=1799081&r1=1799080&r2=1799081&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/RandomAccessSource.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/RandomAccessSource.java Sun Jun 18 12:59:15 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/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/SequentialSource.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/SequentialSource.java?rev=1799081&r1=1799080&r2=1799081&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/SequentialSource.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/SequentialSource.java Sun Jun 18 12:59:15 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