use of org.apache.derby.iapi.types.CharStreamHeaderGenerator in project derby by apache.
the class UTF8UtilTest method testSkipFullyOnValidLongStreamCJK.
/**
* Tests that <code>skipFully</code> successfully skips the requested
* characters and returns the correct number of bytes skipped.
*
* @throws IOException if the test fails for some unexpected reason
*/
public void testSkipFullyOnValidLongStreamCJK() throws IOException {
final int charLength = 161019;
InputStream in = new ReaderToUTF8Stream(new LoopingAlphabetReader(charLength, CharAlphabet.cjkSubset()), charLength, 0, TYPENAME, new CharStreamHeaderGenerator());
// Skip encoded length added by ReaderToUTF8Stream.
in.skip(HEADER_LENGTH);
// Returns count in bytes, we are using CJK chars so multiply length
// with 3 to get expected number of bytes.
assertEquals(charLength * 3, UTF8Util.skipFully(in, charLength));
}
use of org.apache.derby.iapi.types.CharStreamHeaderGenerator 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));
}
use of org.apache.derby.iapi.types.CharStreamHeaderGenerator 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
}
}
use of org.apache.derby.iapi.types.CharStreamHeaderGenerator 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);
}
use of org.apache.derby.iapi.types.CharStreamHeaderGenerator 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.
}
}
Aggregations