Author: lehmi
Date: Tue Feb 24 06:51:58 2026
New Revision: 1932019

Log:
PDFBOX-6166: replace default implementation of available and readFully

Modified:
   
pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/NonSeekableRandomAccessReadInputStream.java

Modified: 
pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/NonSeekableRandomAccessReadInputStream.java
==============================================================================
--- 
pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/NonSeekableRandomAccessReadInputStream.java
      Tue Feb 24 04:20:03 2026        (r1932018)
+++ 
pdfbox/trunk/io/src/main/java/org/apache/pdfbox/io/NonSeekableRandomAccessReadInputStream.java
      Tue Feb 24 06:51:58 2026        (r1932019)
@@ -16,6 +16,7 @@
  */
 package org.apache.pdfbox.io;
 
+import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -164,6 +165,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];
@@ -222,6 +240,16 @@ public class NonSeekableRandomAccessRead
         return true;
     }
 
+    /**
+     * 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();
+    }
 
     /**
      * {@inheritDoc}

Reply via email to