use of org.apache.derby.iapi.types.PositionedStream in project derby by apache.
the class CharacterStreamDescriptorTest method testSetValues.
public void testSetValues() {
final long charLength = 1023;
final long byteLength = 1023 * 2;
final long curBytePos = 4;
final long curCharPos = 2;
final long dataOffset = 2;
final long maxCharLen = 2459;
InputStream emptyStream = new ByteArrayInputStream(new byte[] {});
CharacterStreamDescriptor.Builder b = new CharacterStreamDescriptor.Builder().bufferable(true).byteLength(byteLength).charLength(charLength).curBytePos(curBytePos).curCharPos(curCharPos).dataOffset(dataOffset).maxCharLength(maxCharLen).stream(emptyStream);
CharacterStreamDescriptor csd = b.build();
// Test the values.
assertEquals(true, csd.isBufferable());
assertEquals(false, csd.isPositionAware());
assertEquals(dataOffset, csd.getDataOffset());
assertEquals(curBytePos, csd.getCurBytePos());
assertEquals(curCharPos, csd.getCurCharPos());
assertEquals(byteLength, csd.getByteLength());
assertEquals(charLength, csd.getCharLength());
assertEquals(maxCharLen, csd.getMaxCharLength());
PositionedStream emptyPS = new PositionedTestStream(curBytePos);
// Set only a few values.
csd = new CharacterStreamDescriptor.Builder().bufferable(true).positionAware(true).maxCharLength(maxCharLen).stream(emptyPS.asInputStream()).build();
assertEquals(true, csd.isBufferable());
assertEquals(true, csd.isPositionAware());
assertEquals(maxCharLen, csd.getMaxCharLength());
// Set data offset and update the character position accordingly.
csd = new CharacterStreamDescriptor.Builder().bufferable(true).positionAware(true).dataOffset(dataOffset).curCharPos(CharacterStreamDescriptor.BEFORE_FIRST).stream(emptyPS.asInputStream()).build();
assertEquals(true, csd.isBufferable());
assertEquals(true, csd.isPositionAware());
assertEquals(dataOffset, csd.getDataOffset());
assertEquals(CharacterStreamDescriptor.BEFORE_FIRST, csd.getCurCharPos());
}
Aggregations