use of org.apache.derby.iapi.jdbc.CharacterStreamDescriptor in project derby by apache.
the class CharacterStreamDescriptorTest method testCopyState.
public void testCopyState() {
final long charLength = 1023;
final long byteLength = 1023 * 2;
final long curBytePos = 4;
final long curCharPos = 2;
final long dataOffset = 2;
final long maxCharLen = 3021;
InputStream emptyStream = new ByteArrayInputStream(new byte[] {});
CharacterStreamDescriptor.Builder b1 = new CharacterStreamDescriptor.Builder().bufferable(true).byteLength(byteLength).charLength(charLength).curBytePos(curBytePos).curCharPos(curCharPos).dataOffset(dataOffset).maxCharLength(maxCharLen).stream(emptyStream);
CharacterStreamDescriptor csd1 = b1.build();
CharacterStreamDescriptor.Builder b2 = new CharacterStreamDescriptor.Builder().copyState(csd1);
CharacterStreamDescriptor csd2 = b2.build();
// Test the values.
assertEquals(csd2.isBufferable(), csd1.isBufferable());
assertEquals(csd2.isPositionAware(), csd1.isPositionAware());
assertEquals(csd2.getDataOffset(), csd1.getDataOffset());
assertEquals(csd2.getCurBytePos(), csd1.getCurBytePos());
assertEquals(csd2.getCurCharPos(), csd1.getCurCharPos());
assertEquals(csd2.getByteLength(), csd1.getByteLength());
assertEquals(csd2.getCharLength(), csd1.getCharLength());
assertEquals(csd2.getMaxCharLength(), csd1.getMaxCharLength());
assertTrue(csd2.getStream() == csd1.getStream());
// Override one value.
CharacterStreamDescriptor.Builder b3 = new CharacterStreamDescriptor.Builder().copyState(csd1).maxCharLength(8765);
CharacterStreamDescriptor csd3 = b3.build();
assertEquals(8765, csd3.getMaxCharLength());
// Demonstrate that copying the state after setting a value explicitly
// overwrites the the set value.
CharacterStreamDescriptor.Builder b4 = new CharacterStreamDescriptor.Builder().maxCharLength(8765).copyState(csd1);
CharacterStreamDescriptor csd4 = b4.build();
assertEquals(csd1.getMaxCharLength(), csd4.getMaxCharLength());
}
use of org.apache.derby.iapi.jdbc.CharacterStreamDescriptor in project derby by apache.
the class SmallStoreStreamClobTest method setUp.
public void setUp() throws Exception {
super.initialCharLength = CLOBLENGTH;
super.headerLength = 2 + 3;
// The fake stream uses ascii. Add header and EOF marker.
super.initialByteLength = CLOBLENGTH + headerLength;
super.bytesPerChar = BYTES_PER_CHAR;
EmbedStatement embStmt = (EmbedStatement) createStatement();
InputStream is = new FakeStoreStream(CLOBLENGTH);
CharacterStreamDescriptor csd = new CharacterStreamDescriptor.Builder().stream(is).charLength(initialCharLength).byteLength(0L).curCharPos(CharacterStreamDescriptor.BEFORE_FIRST).dataOffset(2L).build();
iClob = new StoreStreamClob(csd, embStmt);
assertEquals(CLOBLENGTH, iClob.getCharLength());
}
Aggregations