Search in sources :

Example 1 with ClobStreamHeaderGenerator

use of org.apache.derby.iapi.types.ClobStreamHeaderGenerator in project derby by apache.

the class ReaderToUTF8StreamTest method testHeaderPresentInStream_Internal.

/**
 * Makes sure that the header bytes are copied when creating a new buffer
 * to hold all the required bytes when the stream has been marked.
 * This will only happen the first time the buffer is filled, i.e. when the
 * stream is marked before the first read (mark at position zero).
 *
 * @throws IOException if something goes wrong
 */
public void testHeaderPresentInStream_Internal() throws IOException {
    final int valueLen = DEFAULT_INTERNAL_BUFFER_SIZE + 5 * 1024;
    InputStream is = getStream(valueLen);
    is.mark(valueLen - 1024);
    // Obtain a header generator to compare with.
    ClobStreamHeaderGenerator hdrGen = new ClobStreamHeaderGenerator(false);
    byte[] hdrTmp = new byte[100];
    int headerLen = hdrGen.generateInto(hdrTmp, 0, valueLen);
    byte[] hdr1 = new byte[headerLen];
    System.arraycopy(hdrTmp, 0, hdr1, 0, headerLen);
    byte[] hdr2 = new byte[headerLen];
    // Get the first bytes from the stream being tested.
    assertEquals(headerLen, is.read(hdr2));
    assertEquals(new ByteArrayInputStream(hdr1), new ByteArrayInputStream(hdr2));
}
Also used : ClobStreamHeaderGenerator(org.apache.derby.iapi.types.ClobStreamHeaderGenerator) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 2 with ClobStreamHeaderGenerator

use of org.apache.derby.iapi.types.ClobStreamHeaderGenerator in project derby by apache.

the class UTF8UtilTest method testSkipFullyOnTooShortStreamCJK.

/**
 * Tests that <code>skipFully</code> throws exception if the stream contains
 * less characters than the requested number of characters to skip.
 *
 * @throws IOException if the test fails for some unexpected reason
 */
public void testSkipFullyOnTooShortStreamCJK() throws IOException {
    final int charLength = 161019;
    InputStream in = new ReaderToUTF8Stream(new LoopingAlphabetReader(charLength, CharAlphabet.cjkSubset()), charLength, 0, TYPENAME, new ClobStreamHeaderGenerator(true));
    // Skip encoded length added by ReaderToUTF8Stream.
    in.skip(HEADER_LENGTH);
    try {
        UTF8Util.skipFully(in, charLength + 100);
        fail("Should have failed because of too short stream.");
    } catch (EOFException eofe) {
    // As expected, do nothing.
    }
}
Also used : ClobStreamHeaderGenerator(org.apache.derby.iapi.types.ClobStreamHeaderGenerator) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ReaderToUTF8Stream(org.apache.derby.iapi.types.ReaderToUTF8Stream) EOFException(java.io.EOFException) LoopingAlphabetReader(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader)

Example 3 with ClobStreamHeaderGenerator

use of org.apache.derby.iapi.types.ClobStreamHeaderGenerator in project derby by apache.

the class UTF8UtilTest method testSkipUntilEOFOnLongStreamCJK.

public void testSkipUntilEOFOnLongStreamCJK() throws IOException {
    final int charLength = 127019;
    InputStream in = new ReaderToUTF8Stream(new LoopingAlphabetReader(charLength, CharAlphabet.cjkSubset()), charLength, 0, TYPENAME, new ClobStreamHeaderGenerator(true));
    // Skip encoded length added by ReaderToUTF8Stream.
    in.skip(HEADER_LENGTH);
    assertEquals(charLength, UTF8Util.skipUntilEOF(in));
}
Also used : ClobStreamHeaderGenerator(org.apache.derby.iapi.types.ClobStreamHeaderGenerator) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ReaderToUTF8Stream(org.apache.derby.iapi.types.ReaderToUTF8Stream) LoopingAlphabetReader(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader)

Example 4 with ClobStreamHeaderGenerator

use of org.apache.derby.iapi.types.ClobStreamHeaderGenerator in project derby by apache.

the class ReaderToUTF8StreamTest method getStream.

/**
 * Returns a stream to test, loaded with the repeating modern latin
 * lowercase alphabet.
 *
 * @param length the length of the stream in characters
 * @return A stream serving bytes.
 */
private InputStream getStream(int length) {
    Reader src = new LoopingAlphabetReader(length, CharAlphabet.modernLatinLowercase());
    InputStream is = new ReaderToUTF8Stream(src, length, 0, "CLOB", new ClobStreamHeaderGenerator(false));
    assertTrue("The stream doesn't support mark/reset", is.markSupported());
    return is;
}
Also used : ClobStreamHeaderGenerator(org.apache.derby.iapi.types.ClobStreamHeaderGenerator) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ReaderToUTF8Stream(org.apache.derby.iapi.types.ReaderToUTF8Stream) LoopingAlphabetReader(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader) Reader(java.io.Reader) LoopingAlphabetReader(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 ClobStreamHeaderGenerator (org.apache.derby.iapi.types.ClobStreamHeaderGenerator)4 ReaderToUTF8Stream (org.apache.derby.iapi.types.ReaderToUTF8Stream)3 LoopingAlphabetReader (org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader)3 DataInputStream (java.io.DataInputStream)2 EOFException (java.io.EOFException)1 Reader (java.io.Reader)1