Author: tilman
Date: Wed Oct 15 09:40:02 2025
New Revision: 1929153
Log:
PDFBOX-6083: catch length 0 case + plus test
Modified:
pdfbox/branches/3.0/io/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java
pdfbox/branches/3.0/io/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferedFileTest.java
Modified:
pdfbox/branches/3.0/io/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java
==============================================================================
---
pdfbox/branches/3.0/io/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java
Wed Oct 15 09:39:58 2025 (r1929152)
+++
pdfbox/branches/3.0/io/src/main/java/org/apache/pdfbox/io/RandomAccessRead.java
Wed Oct 15 09:40:02 2025 (r1929153)
@@ -189,7 +189,7 @@ public interface RandomAccessRead extend
throw new EOFException("Premature end of buffer reached");
}
int bytesReadTotal = 0;
- do
+ while (bytesReadTotal < length)
{
int bytesReadNow = read(b, offset + bytesReadTotal, length -
bytesReadTotal);
if (bytesReadNow <= 0)
@@ -198,6 +198,5 @@ public interface RandomAccessRead extend
}
bytesReadTotal += bytesReadNow;
}
- while (bytesReadTotal < length);
}
}
Modified:
pdfbox/branches/3.0/io/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferedFileTest.java
==============================================================================
---
pdfbox/branches/3.0/io/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferedFileTest.java
Wed Oct 15 09:39:58 2025 (r1929152)
+++
pdfbox/branches/3.0/io/src/test/java/org/apache/pdfbox/io/RandomAccessReadBufferedFileTest.java
Wed Oct 15 09:40:02 2025 (r1929153)
@@ -300,4 +300,17 @@ class RandomAccessReadBufferedFileTest
Assertions.assertArrayEquals(expectedBytes, b);
}
}
+
+ @Test
+ void testReadFullyNothing() throws IOException, URISyntaxException
+ {
+ try (RandomAccessRead randomAccessSource = new
RandomAccessReadBufferedFile(
+ new
File(getClass().getResource("RandomAccessReadFile1.txt").toURI())))
+ {
+ assertEquals(0, randomAccessSource.getPosition());
+ byte[] b = new byte[0];
+ randomAccessSource.readFully(b);
+ assertEquals(0, randomAccessSource.getPosition());
+ }
+ }
}