Search in sources :

Example 11 with LoopingAlphabetReader

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader in project derby by apache.

the class UTF8UtilTest method testSkipUntilEOFOnShortStreamCJK.

public void testSkipUntilEOFOnShortStreamCJK() throws IOException {
    final int charLength = 5;
    InputStream in = new ReaderToUTF8Stream(new LoopingAlphabetReader(charLength, CharAlphabet.cjkSubset()), charLength, 0, TYPENAME, new CharStreamHeaderGenerator());
    // Skip encoded length added by ReaderToUTF8Stream.
    in.skip(HEADER_LENGTH);
    assertEquals(charLength, UTF8Util.skipUntilEOF(in));
}
Also used : 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)

Example 12 with LoopingAlphabetReader

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader 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 13 with LoopingAlphabetReader

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader 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 14 with LoopingAlphabetReader

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader 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 15 with LoopingAlphabetReader

use of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader 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)

Aggregations

LoopingAlphabetReader (org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader)57 PreparedStatement (java.sql.PreparedStatement)35 Reader (java.io.Reader)23 ResultSet (java.sql.ResultSet)23 Statement (java.sql.Statement)20 InputStream (java.io.InputStream)15 SQLException (java.sql.SQLException)10 Clob (java.sql.Clob)9 LoopingAlphabetStream (org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 StringReader (java.io.StringReader)8 ReaderToUTF8Stream (org.apache.derby.iapi.types.ReaderToUTF8Stream)8 DataInputStream (java.io.DataInputStream)7 Connection (java.sql.Connection)6 CharAlphabet (org.apache.derbyTesting.functionTests.util.streams.CharAlphabet)6 CharStreamHeaderGenerator (org.apache.derby.iapi.types.CharStreamHeaderGenerator)5 BufferedReader (java.io.BufferedReader)4 CharArrayReader (java.io.CharArrayReader)4 CallableStatement (java.sql.CallableStatement)4 Timestamp (java.sql.Timestamp)3