use of org.grails.buffer.StreamByteBuffer in project grails-core by grails.
the class StreamByteBufferTest method testToString.
public void testToString() throws IOException {
StreamByteBuffer byteBuffer = new StreamByteBuffer();
PrintWriter pw = new PrintWriter(new OutputStreamWriter(byteBuffer.getOutputStream(), "UTF-8"));
pw.print(TEST_STRING);
pw.close();
assertEquals(TEST_STRING, byteBuffer.readAsString("UTF-8"));
}
use of org.grails.buffer.StreamByteBuffer in project grails-core by grails.
the class StreamByteBufferTest method testStreamByteBuffer.
public void testStreamByteBuffer() throws Exception {
StreamByteBuffer streamBuf = new StreamByteBuffer(32000);
OutputStream output = streamBuf.getOutputStream();
output.write(1);
output.write(2);
output.write(3);
output.write(255);
output.close();
InputStream input = streamBuf.getInputStream();
assertEquals(1, input.read());
assertEquals(2, input.read());
assertEquals(3, input.read());
assertEquals(255, input.read());
assertEquals(-1, input.read());
input.close();
}
use of org.grails.buffer.StreamByteBuffer in project grails-core by grails.
the class StreamByteBufferTest method testToInputStreamOneByOne.
public void testToInputStreamOneByOne() throws IOException {
StreamByteBuffer byteBuffer = createTestInstance();
InputStream input = byteBuffer.getInputStream();
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(byteBuffer.totalBytesUnread());
copyOneByOne(input, bytesOut);
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 createTestInstance.
private StreamByteBuffer createTestInstance() throws IOException {
StreamByteBuffer byteBuffer = new StreamByteBuffer();
OutputStream output = byteBuffer.getOutputStream();
copyAllFromTestBuffer(output, 27);
return byteBuffer;
}
use of org.grails.buffer.StreamByteBuffer in project grails-core by grails.
the class StreamByteBufferTest method testWriteTo.
public void testWriteTo() throws IOException {
StreamByteBuffer byteBuffer = createTestInstance();
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(byteBuffer.totalBytesUnread());
byteBuffer.writeTo(bytesOut);
byte[] result = bytesOut.toByteArray();
assertTrue(Arrays.equals(testbuffer, result));
}
Aggregations