Skip to content

Commit b59505e

Browse files
committed
PDFBOX-5965: reset EOF if rewind is possible; improve test
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1924161 13f79535-47bb-0310-9956-ffa450edef68
1 parent 7a085ca commit b59505e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

io/src/main/java/org/apache/pdfbox/io/NonSeekableRandomAccessReadInputStream.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ else if (bufferBytes[LAST] > 0)
243243
bufferBytes[LAST] = -1;
244244
currentBufferPointer = bufferBytes[CURRENT] - remainingBytesToRewind;
245245
position -= bytes;
246+
isEOF = false;
246247
}
247248
else
248249
{

io/src/test/java/org/apache/pdfbox/io/NonSeekableRandomAccessReadInputStreamTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,25 @@ void testPositionUnreadBytes() throws IOException
152152
assertEquals(7, randomAccessSource.getPosition());
153153
randomAccessSource.rewind(4);
154154
assertEquals(3, randomAccessSource.getPosition());
155+
156+
// PDFBOX-5965: check that it also works near EOF
157+
assertEquals(3, randomAccessSource.read());
158+
assertEquals(4, randomAccessSource.read());
159+
assertEquals(5, randomAccessSource.read());
160+
assertEquals(6, randomAccessSource.read());
161+
assertEquals(7, randomAccessSource.read());
162+
assertEquals(8, randomAccessSource.read());
163+
assertEquals(9, randomAccessSource.read());
164+
assertEquals(10, randomAccessSource.read());
165+
assertEquals(-1, randomAccessSource.read());
166+
assertTrue(randomAccessSource.isEOF());
167+
randomAccessSource.rewind(4);
168+
assertFalse(randomAccessSource.isEOF());
169+
assertEquals(7, randomAccessSource.read());
170+
assertEquals(8, randomAccessSource.read());
171+
assertEquals(9, randomAccessSource.read());
172+
assertEquals(10, randomAccessSource.read());
173+
assertEquals(-1, randomAccessSource.read());
155174
}
156175
}
157176

0 commit comments

Comments
 (0)