Search in sources :

Example 6 with CharacterStreamDescriptor

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CharacterStreamDescriptor(org.apache.derby.iapi.jdbc.CharacterStreamDescriptor)

Example 7 with CharacterStreamDescriptor

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());
}
Also used : InputStream(java.io.InputStream) CharacterStreamDescriptor(org.apache.derby.iapi.jdbc.CharacterStreamDescriptor)

Aggregations

InputStream (java.io.InputStream)7 CharacterStreamDescriptor (org.apache.derby.iapi.jdbc.CharacterStreamDescriptor)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Reader (java.io.Reader)2 StringDataValue (org.apache.derby.iapi.types.StringDataValue)2 InputStreamReader (java.io.InputStreamReader)1 StringReader (java.io.StringReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SQLException (java.sql.SQLException)1 PositionedStream (org.apache.derby.iapi.types.PositionedStream)1