*/
public void testDerby3781()
throws IOException, StandardException {
final long size = 10;
InputStream in = new LoopingAlphabetStream(size);
PositionedStoreStream pss = new PositionedStoreStream(in);
assertEquals("Invalid initial position", 0L, pss.getPosition());
pss.reposition(size -1); // Goto end.
assertEquals(size -1, pss.getPosition());
assertEquals('j', pss.read());
assertEquals(size, pss.getPosition());
assertEquals(-1, pss.read());
// This step is crucial, position must be different than zero when the
// first exception below is thrown.
pss.reposition(size / 2); // Goto middle.
assertEquals(size / 2, pss.getPosition());
try {
pss.reposition(size *2); // Try to go past end.
fail("Should have failed with EOFException");
} catch (EOFException eofe) {
// Ignore this exception
}
// Failed here before, because internal state was inconsistent.
// Assumed: pos = 5, underlying stream at pos 5, skipped (size -1 - pos)
// Actual: pos = 5, underlying stream at pos (size -1)
pss.reposition(size -1); // Goto end.
assertEquals(size -1, pss.getPosition());
assertEquals('j', pss.read());
}