Search in sources :

Example 6 with ReaderToUTF8Stream

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

the class UTF8UtilTest method testMixedSkipOnStreamTamil.

/**
 * Tests a sequence of skip calls.
 */
public void testMixedSkipOnStreamTamil() throws IOException {
    final int charLength = 161019;
    InputStream in = new ReaderToUTF8Stream(new LoopingAlphabetReader(charLength, CharAlphabet.tamil()), charLength, 0, TYPENAME, new CharStreamHeaderGenerator());
    // Skip encoded length added by ReaderToUTF8Stream.
    in.skip(HEADER_LENGTH);
    int firstSkip = 10078;
    assertEquals(firstSkip * 3, UTF8Util.skipFully(in, firstSkip));
    assertEquals(charLength - firstSkip, UTF8Util.skipUntilEOF(in));
    try {
        UTF8Util.skipFully(in, 1L);
        fail("Should have failed because the stream has been drained.");
    } catch (EOFException eofe) {
    // As expected, do nothing
    }
}
Also used : DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ReaderToUTF8Stream(org.apache.derby.iapi.types.ReaderToUTF8Stream) EOFException(java.io.EOFException) CharStreamHeaderGenerator(org.apache.derby.iapi.types.CharStreamHeaderGenerator) LoopingAlphabetReader(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader)

Example 7 with ReaderToUTF8Stream

use of org.apache.derby.iapi.types.ReaderToUTF8Stream 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 8 with ReaderToUTF8Stream

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

the class UTF8UtilTest method testEqualityOfModifedUTF8AndASCII.

/**
 * Ensure the assumption that the default looping alphabet stream and the
 * modified UTF-8 encoding is equal.
 * <p>
 * If this assumption is broken, several of the other tests will fail.
 */
public void testEqualityOfModifedUTF8AndASCII() throws IOException {
    final int length = 12706;
    InputStream ascii = new LoopingAlphabetStream(length);
    InputStream modUTF8 = new ReaderToUTF8Stream(new LoopingAlphabetReader(length), length, 0, TYPENAME, new CharStreamHeaderGenerator());
    // Skip encoded length added by ReaderToUTF8Stream.
    modUTF8.skip(HEADER_LENGTH);
    assertEquals(ascii, modUTF8);
}
Also used : DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ReaderToUTF8Stream(org.apache.derby.iapi.types.ReaderToUTF8Stream) LoopingAlphabetStream(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream) CharStreamHeaderGenerator(org.apache.derby.iapi.types.CharStreamHeaderGenerator) LoopingAlphabetReader(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader)

Example 9 with ReaderToUTF8Stream

use of org.apache.derby.iapi.types.ReaderToUTF8Stream 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)

Example 10 with ReaderToUTF8Stream

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

the class UTF8UtilTest method testSkipFullyOnInvalidStreamCJK.

/**
 * Tests that <code>skipFully</code> throws exception if there is a UTF-8
 * encoding error in the stream
 *
 * @throws IOException if the test fails for some unexpected reason
 */
public void testSkipFullyOnInvalidStreamCJK() throws IOException {
    final int charLength = 10;
    InputStream in = new ReaderToUTF8Stream(new LoopingAlphabetReader(charLength, CharAlphabet.cjkSubset()), charLength, 0, TYPENAME, new CharStreamHeaderGenerator());
    // Skip encoded length added by ReaderToUTF8Stream.
    in.skip(HEADER_LENGTH);
    // Skip one more byte to trigger a UTF error.
    in.skip(1L);
    try {
        UTF8Util.skipFully(in, charLength);
        fail("Should have failed because of UTF error.");
    } catch (UTFDataFormatException udfe) {
    // As expected, do nothing.
    }
}
Also used : UTFDataFormatException(java.io.UTFDataFormatException) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ReaderToUTF8Stream(org.apache.derby.iapi.types.ReaderToUTF8Stream) CharStreamHeaderGenerator(org.apache.derby.iapi.types.CharStreamHeaderGenerator) LoopingAlphabetReader(org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader)

Aggregations

ReaderToUTF8Stream (org.apache.derby.iapi.types.ReaderToUTF8Stream)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)8 LoopingAlphabetReader (org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader)8 DataInputStream (java.io.DataInputStream)7 CharStreamHeaderGenerator (org.apache.derby.iapi.types.CharStreamHeaderGenerator)5 ClobStreamHeaderGenerator (org.apache.derby.iapi.types.ClobStreamHeaderGenerator)3 EOFException (java.io.EOFException)2 StringDataValue (org.apache.derby.iapi.types.StringDataValue)2 StandardException (org.apache.derby.shared.common.error.StandardException)2 Reader (java.io.Reader)1 UTFDataFormatException (java.io.UTFDataFormatException)1 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)1 LoopingAlphabetStream (org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)1