use of org.grails.buffer.StreamByteBuffer in project grails-core by grails.
the class StreamByteBufferTest method bufferTest2.
private void bufferTest2(int streamByteBufferSize, int testBufferSize) throws IOException {
StreamByteBuffer streamBuf = new StreamByteBuffer(streamByteBufferSize);
OutputStream output = streamBuf.getOutputStream();
for (int i = 0; i < testBufferSize; i++) {
output.write(i % (Byte.MAX_VALUE * 2));
}
output.close();
InputStream input = streamBuf.getInputStream();
assertEquals(testBufferSize, input.available());
for (int i = 0; i < testBufferSize; i++) {
assertEquals((i % (Byte.MAX_VALUE * 2)), input.read());
}
assertEquals(-1, input.read());
assertEquals(-1, input.read());
assertEquals(-1, input.read());
assertEquals(-1, input.read());
input.close();
}
use of org.grails.buffer.StreamByteBuffer in project grails-core by grails.
the class StreamByteBufferTest method testToInputStream.
public void testToInputStream() throws IOException {
StreamByteBuffer byteBuffer = createTestInstance();
InputStream input = byteBuffer.getInputStream();
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(byteBuffer.totalBytesUnread());
copy(input, bytesOut, 2048);
byte[] result = bytesOut.toByteArray();
assertTrue(Arrays.equals(testbuffer, result));
}
use of org.grails.buffer.StreamByteBuffer in project grails-core by grails.
the class StreamByteBufferTest method testToByteArray.
public void testToByteArray() throws IOException {
StreamByteBuffer byteBuffer = createTestInstance();
byte[] result = byteBuffer.readAsByteArray();
assertTrue(Arrays.equals(testbuffer, result));
}
use of org.grails.buffer.StreamByteBuffer in project grails-core by grails.
the class StreamByteBufferTest method testToStringRetain.
public void testToStringRetain() throws IOException {
StreamByteBuffer byteBuffer = new StreamByteBuffer(1024, StreamByteBuffer.ReadMode.RETAIN_AFTER_READING);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(byteBuffer.getOutputStream(), "UTF-8"));
pw.print(TEST_STRING);
pw.close();
assertEquals(TEST_STRING, byteBuffer.readAsString("UTF-8"));
byteBuffer.reset();
// call a second time to test if the RETAIN_AFTER_READING mode works as expected
assertEquals(TEST_STRING, byteBuffer.readAsString("UTF-8"));
}
Aggregations