Package org.grails.buffer

Examples of org.grails.buffer.StreamByteBuffer$StreamByteBufferChunk


        public ServletOutputStream getOutputStream() {
            if (byteBuffer == null) {
                if (charBuffer != null) {
                    throw new IllegalStateException("response.getOutputStream() called after response.getWriter()");
                }
                byteBuffer = new StreamByteBuffer();
                final OutputStream out=byteBuffer.getOutputStream();
                exposedStream = new ServletOutputStream() {
                    @Override
                    public void write(byte[] b, int off, int len) throws IOException {
                        out.write(b, off, len);
View Full Code Here


     */
    public abstract Template createTemplate(Resource resource, boolean cacheable);

    @Override
    public final Template createTemplate(Reader reader) throws IOException {
        StreamByteBuffer buf=new StreamByteBuffer();
        IOUtils.copy(reader, new OutputStreamWriter(buf.getOutputStream(), GROOVY_SOURCE_CHAR_ENCODING));
        return createTemplate(buf.getInputStream());
    }
View Full Code Here

    public ServletOutputStream getOutputStream() throws IOException {
        if (usingWriter) throw new IllegalStateException("Method getWriter() already called");

        if (!usingStream) {
            usingStream = true;
            byteBuffer = new StreamByteBuffer();
            os = byteBuffer.getOutputStream();
            sos = new ServletOutputStream() {
                @Override
                public void write(byte[] b, int off, int len) throws IOException {
                    os.write(b, off, len);
View Full Code Here

            }
        }
    }

    public void testToByteArray() throws IOException {
        StreamByteBuffer byteBuffer = createTestInstance();
        byte[] result = byteBuffer.readAsByteArray();
        assertTrue(Arrays.equals(testbuffer, result));
    }
View Full Code Here

        byte[] result = byteBuffer.readAsByteArray();
        assertTrue(Arrays.equals(testbuffer, result));
    }

    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"));
    }
View Full Code Here

        pw.close();
        assertEquals(TEST_STRING, byteBuffer.readAsString("UTF-8"));
    }

    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"));
    }
View Full Code Here

        // call a second time to test if the RETAIN_AFTER_READING mode works as expected
        assertEquals(TEST_STRING, byteBuffer.readAsString("UTF-8"));
    }

    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));
    }
View Full Code Here

        byte[] result = bytesOut.toByteArray();
        assertTrue(Arrays.equals(testbuffer, result));
    }

    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());
View Full Code Here

        assertEquals(-1, input.read());
        input.close();
    }

    public void testStreamByteBuffer2() throws Exception {
        StreamByteBuffer streamBuf=new StreamByteBuffer(32000);
        OutputStream output=streamBuf.getOutputStream();
        byte[] bytes=new byte[]{(byte)1,(byte)2,(byte)3};
        output.write(bytes);
        output.close();
        InputStream input=streamBuf.getInputStream();
        assertEquals(1, input.read());
        assertEquals(2, input.read());
        assertEquals(3, input.read());
        assertEquals(-1, input.read());
        input.close();
View Full Code Here

        bufferTest2(10000,2);
        bufferTest2(10000,1);
    }

    private void bufferTest(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();
        byte[] buffer = new byte[testBufferSize];
        InputStream input = streamBuf.getInputStream();
        assertEquals(testBufferSize, input.available());
        int readBytes = input.read(buffer);
        assertEquals(readBytes, testBufferSize);
        for (int i = 0; i < buffer.length; i++) {
            assertEquals((byte)(i % (Byte.MAX_VALUE*2)), buffer[i]);
View Full Code Here

TOP

Related Classes of org.grails.buffer.StreamByteBuffer$StreamByteBufferChunk

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.