Search in sources :

Example 1 with StreamByteBuffer

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"));
}
Also used : StreamByteBuffer(org.grails.buffer.StreamByteBuffer) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter)

Example 2 with StreamByteBuffer

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();
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamByteBuffer(org.grails.buffer.StreamByteBuffer)

Example 3 with StreamByteBuffer

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));
}
Also used : InputStream(java.io.InputStream) StreamByteBuffer(org.grails.buffer.StreamByteBuffer) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with StreamByteBuffer

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;
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamByteBuffer(org.grails.buffer.StreamByteBuffer)

Example 5 with StreamByteBuffer

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));
}
Also used : StreamByteBuffer(org.grails.buffer.StreamByteBuffer) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

StreamByteBuffer (org.grails.buffer.StreamByteBuffer)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)5 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2 IOException (java.io.IOException)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 FastStringWriter (org.grails.buffer.FastStringWriter)1 StreamCharBuffer (org.grails.buffer.StreamCharBuffer)1