use of org.apache.derby.impl.jdbc.PositionedStoreStream in project derby by apache.
the class PositionedStoreStreamTest method testSimpleReadSequence.
/**
* Executes a simple read sequence against the lower case modern latin
* alphabet, which involves some repositioning.
*/
public void testSimpleReadSequence() throws IOException, StandardException {
InputStream in = new LoopingAlphabetStream(26);
PositionedStoreStream pss = new PositionedStoreStream(in);
assertEquals('a', pss.read());
pss.reposition(9);
assertEquals('j', pss.read());
pss.reposition(10);
assertEquals('k', pss.read());
pss.reposition(9);
assertEquals('j', pss.read());
pss.reposition(25);
assertEquals('z', pss.read());
assertEquals(-1, pss.read());
pss.reposition(1);
assertEquals('b', pss.read());
pss.reposition(1);
assertEquals('b', pss.read());
}
use of org.apache.derby.impl.jdbc.PositionedStoreStream in project derby by apache.
the class PositionedStoreStreamTest method testPositionAfterEOFReadArray.
/**
* Verifies that reading after EOF doesn't change the position.
*/
public void testPositionAfterEOFReadArray() throws IOException, StandardException {
InputStream in = new LoopingAlphabetStream(10);
PositionedStoreStream pss = new PositionedStoreStream(in);
assertEquals(0, pss.getPosition());
byte[] two = new byte[2];
for (int i = 0; i < 10; i += 2) {
assertEquals(2, pss.read(two, 0, 2));
assertEquals(i + 2, pss.getPosition());
}
assertEquals(10, pss.getPosition());
assertEquals(-1, pss.read(two, 0, 2));
assertEquals(10, pss.getPosition());
assertEquals(-1, pss.read(two, 0, 2));
assertEquals(0, pss.skip(21));
assertEquals(-1, pss.read());
assertEquals(10, pss.getPosition());
pss.resetStream();
assertEquals(0, pss.getPosition());
}
use of org.apache.derby.impl.jdbc.PositionedStoreStream in project derby by apache.
the class PositionedStoreStreamTest method testRepositionForwards.
public void testRepositionForwards() throws IOException, StandardException {
final long length = 20L;
InputStream in = new LoopingAlphabetStream(length);
PositionedStoreStream pss = new PositionedStoreStream(in);
assertEquals(0, pss.getPosition());
// Position forwards one by one.
for (int i = 0; i < length; i++) {
InputStream inComp = new LoopingAlphabetStream(length);
pss.reposition(i);
inComp.skip(i);
assertEquals(inComp.read(), pss.read());
}
// Position forwards two by two.
for (int i = 1; i < length; i += 2) {
InputStream inComp = new LoopingAlphabetStream(length);
pss.reposition(i);
inComp.skip(i);
assertEquals(inComp.read(), pss.read());
}
}
Aggregations