Author: lehmi
Date: Sun Apr 12 09:44:58 2026
New Revision: 1932991
Log:
PDFBOX-6166: replace default implementation of available and readFully
Modified:
pdfbox/branches/3.0/io/src/main/java/org/apache/pdfbox/io/NonSeekableRandomAccessReadInputStream.java
Modified:
pdfbox/branches/3.0/io/src/main/java/org/apache/pdfbox/io/NonSeekableRandomAccessReadInputStream.java
==============================================================================
---
pdfbox/branches/3.0/io/src/main/java/org/apache/pdfbox/io/NonSeekableRandomAccessReadInputStream.java
Sun Apr 12 08:30:18 2026 (r1932990)
+++
pdfbox/branches/3.0/io/src/main/java/org/apache/pdfbox/io/NonSeekableRandomAccessReadInputStream.java
Sun Apr 12 09:44:58 2026 (r1932991)
@@ -16,6 +16,7 @@
*/
package org.apache.pdfbox.io;
+import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
@@ -162,6 +163,23 @@ public class NonSeekableRandomAccessRead
return numberOfBytesRead;
}
+ @Override
+ public void readFully(byte[] b, int offset, int length) throws IOException
+ {
+ // override the default implementation as the return value from length
isn't reliable
+ checkClosed();
+ int bytesReadTotal = 0;
+ while (bytesReadTotal < length)
+ {
+ int bytesReadNow = read(b, offset + bytesReadTotal, length -
bytesReadTotal);
+ if (bytesReadNow <= 0)
+ {
+ throw new EOFException("EOF, should have been detected
earlier");
+ }
+ bytesReadTotal += bytesReadNow;
+ }
+ }
+
private void switchBuffers(int firstBuffer, int secondBuffer)
{
byte[] tmpBuffer = buffers[firstBuffer];
@@ -172,6 +190,17 @@ public class NonSeekableRandomAccessRead
bufferBytes[secondBuffer] = tmpBufferBytes;
}
+ /**
+ * Returns an estimate of the number of bytes that can be read (or skipped
over) from the underlying input stream
+ * without blocking, which may be 0, or 0 when end of stream is detected.
+ */
+ @Override
+ public int available() throws IOException
+ {
+ checkClosed();
+ return is.available();
+ }
+
private boolean fetch() throws IOException
{
checkClosed();