Package org.grails.buffer

Examples of org.grails.buffer.CodecPrintWriter


        if (out instanceof EncodedAppenderWriterFactory) {
            encodingWriter=((EncodedAppenderWriterFactory)out).getWriterForEncoder(encoder, encodingStateRegistry);
        } else if (encoder instanceof StreamingEncoder) {
            encodingWriter=new StreamingEncoderWriter(out, (StreamingEncoder)encoder, encodingStateRegistry);
        } else {
            encodingWriter=new CodecPrintWriter(out, encoder, encodingStateRegistry);
        }
        return encodingWriter;
    }
View Full Code Here


    }

    @Test
    public void testPrintString() {
        FastStringWriter stringwriter=new FastStringWriter();
        CodecPrintWriter writer=new CodecPrintWriter(stringwriter, getEncoder(new MockGrailsApplication(), HTMLCodec.class), registry);
        writer.print("&&");
        writer.flush();
        assertEquals("&&", stringwriter.getValue());
    }
View Full Code Here

    }

    @Test
    public void testPrintStringWithClosure() {
        FastStringWriter stringwriter=new FastStringWriter();
        CodecPrintWriter writer=new CodecPrintWriter(stringwriter, getEncoder(new MockGrailsApplication(), CodecWithClosureProperties.class), registry);
        writer.print("hello");
        writer.flush();
        assertEquals("-> hello <-", stringwriter.getValue());
    }
View Full Code Here

    }

    @Test
    public void testPrintStreamCharBuffer() throws IOException {
        FastStringWriter stringwriter=new FastStringWriter();
        CodecPrintWriter writer=new CodecPrintWriter(stringwriter, getEncoder(new MockGrailsApplication(), HTMLCodec.class), registry);
        StreamCharBuffer buf=new StreamCharBuffer();
        buf.getWriter().write("&&");
        writer.write(buf);
        writer.flush();
        assertEquals("&amp;&amp;", stringwriter.getValue());
    }
View Full Code Here

    }

    @Test
    public void testPrintStreamCharBufferWithClosure() throws IOException {
        FastStringWriter stringwriter=new FastStringWriter();
        CodecPrintWriter writer=new CodecPrintWriter(stringwriter, getEncoder(new MockGrailsApplication(), CodecWithClosureProperties.class), registry);
        StreamCharBuffer buf=new StreamCharBuffer();
        buf.getWriter().write("hola");
        writer.write(buf);
        writer.flush();
        assertEquals("-> hola <-", stringwriter.getValue());
    }
View Full Code Here

        // Initialize out and codecOut as it is done in GroovyPage.initRun
        OutputEncodingStack outputStack = OutputEncodingStack.currentStack(true, target, false, true);
        GrailsPrintWriter out = outputStack.getOutWriter();
        webRequest.setOut(out);
        GrailsPrintWriter codecOut = new CodecPrintWriter(out, getEncoder(new MockGrailsApplication(), CodecWithClosureProperties.class), registry);

        // print some output
        codecOut.print("hola");
        codecOut.flush();
        out.print("1");
        out.print("2");
        out.print("3");

        // similar as taglib call
        FastStringWriter bufferWriter=new FastStringWriter();
        GrailsPrintWriter out2=new GrailsPrintWriter(bufferWriter);
        outputStack.push(out2);
        out.print("4");
        codecOut.print("A");
        codecOut.flush();
        outputStack.pop();

        // add output before appending "taglib output"
        out.print("added");
        codecOut.print("too");
        codecOut.flush();

        // append "taglib output"
        out.leftShift(bufferWriter.getBuffer());

        // print some more output
        codecOut.print("B");
        codecOut.flush();
        out.print("5");
        codecOut.print("C");
        codecOut.flush();

        // clear thread local
        RequestContextHolder.setRequestAttributes(null);

        assertEquals("-> hola <-123added-> too <-4-> A <--> B <-5-> C <-", target.getValue());

        codecOut.close();
    }
View Full Code Here

                if (out instanceof EncodedAppenderWriterFactory) {
                    out = ((EncodedAppenderWriterFactory)out).getWriterForEncoder(encoder, webRequest.getEncodingStateRegistry());
                } else if (encoder instanceof StreamingEncoder) {
                    out=new StreamingEncoderWriter(out, (StreamingEncoder)encoder, webRequest.getEncodingStateRegistry());
                } else {
                    out = new CodecPrintWriter(out, encoder, webRequest.getEncodingStateRegistry());
                }
            }
        }
        return out;
    }
View Full Code Here

TOP

Related Classes of org.grails.buffer.CodecPrintWriter

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.