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 2020/10/13 06:21:52 UTC
svn commit: r1882447 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java
Author: lehmi
Date: Tue Oct 13 06:21:52 2020
New Revision: 1882447
URL: http://svn.apache.org/viewvc?rev=1882447&view=rev
Log:
PDFBOX-4836: add support for ByteBuffer as source
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java?rev=1882447&r1=1882446&r2=1882447&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/RandomAccessReadBuffer.java Tue Oct 13 06:21:52 2020
@@ -74,10 +74,20 @@ public class RandomAccessReadBuffer impl
*/
public RandomAccessReadBuffer(byte[] input)
{
- // this is a special case. Wrap the given byte array to one ByteBuffer.
- chunkSize = input.length;
+ // this is a special case. Wrap the given byte array to a single ByteBuffer.
+ this(ByteBuffer.wrap(input));
+ }
+
+ /**
+ * Create a random access buffer using the given ByteBuffer.
+ *
+ * @param input the ByteBuffer to be read
+ */
+ public RandomAccessReadBuffer(ByteBuffer input)
+ {
+ chunkSize = input.capacity();
size = chunkSize;
- currentBuffer = ByteBuffer.wrap(input);
+ currentBuffer = input;
bufferList = new ArrayList<>(1);
bufferList.add(currentBuffer);
}
@@ -247,8 +257,8 @@ public class RandomAccessReadBuffer impl
if (maxLength >= remainingBytes)
{
// copy the remaining bytes from the current buffer
- System.arraycopy(currentBuffer.array(), currentBufferPointer, b, offset,
- remainingBytes);
+ currentBuffer.position(currentBufferPointer);
+ currentBuffer.get(b, offset, remainingBytes);
// end of file reached
currentBufferPointer += remainingBytes;
pointer += remainingBytes;
@@ -257,7 +267,8 @@ public class RandomAccessReadBuffer impl
else
{
// copy the remaining bytes from the whole buffer
- System.arraycopy(currentBuffer.array(), currentBufferPointer, b, offset, maxLength);
+ currentBuffer.position(currentBufferPointer);
+ currentBuffer.get(b, offset, maxLength);
// end of file reached
currentBufferPointer += maxLength;
pointer += maxLength;