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));
}
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.
}
}
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));
}
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;
}
Aggregations