Package org.grails.buffer

Examples of org.grails.buffer.StreamCharBuffer$LazyInitializingMultipleWriter


     * @return  A GSPResponseWriter instance
     */
    private static GSPResponseWriter getInstance(final ServletResponse response, final int max) {
        final BoundedCharsAsEncodedBytesCounter bytesCounter=new BoundedCharsAsEncodedBytesCounter();

        final StreamCharBuffer streamBuffer = new StreamCharBuffer(max, 0, max);
        streamBuffer.setChunkMinSize(max/2);
        streamBuffer.setNotifyParentBuffersEnabled(false);

        final StreamCharBuffer.LazyInitializingWriter lazyResponseWriter = new StreamCharBuffer.LazyInitializingWriter() {
            public Writer getWriter() throws IOException {
                return response.getWriter();
            }
        };

        if (!(response instanceof GrailsContentBufferingResponse)) {
            streamBuffer.connectTo(new StreamCharBuffer.LazyInitializingMultipleWriter() {
                public Writer getWriter() throws IOException {
                    return null;
                }

                public LazyInitializingWriter[] initializeMultiple(StreamCharBuffer buffer, boolean autoFlush) throws IOException {
                    final StreamCharBuffer.LazyInitializingWriter[] lazyWriters;
                    if (CONTENT_LENGTH_COUNTING_ENABLED) {
                        lazyWriters=new StreamCharBuffer.LazyInitializingWriter[] {new StreamCharBuffer.LazyInitializingWriter() {
                            public Writer getWriter() throws IOException {
                                bytesCounter.setCapacity(max * 2);
                                bytesCounter.setEncoding(response.getCharacterEncoding());
                                return bytesCounter.getCountingWriter();
                            }
                        }, lazyResponseWriter};
                    } else {
                        lazyWriters=new StreamCharBuffer.LazyInitializingWriter[] {lazyResponseWriter};
                    }
                    return lazyWriters;
                }
            }, AUTOFLUSH_ENABLED);
        } else {
            streamBuffer.connectTo(lazyResponseWriter);
        }

        if (instantiator != null) {
            GSPResponseWriter instance = (GSPResponseWriter)instantiator.newInstance();
            instance.initialize(streamBuffer, response, bytesCounter);
View Full Code Here


     * @return  A GSPResponseWriter instance
     */
    @SuppressWarnings("unused")
    private static GSPResponseWriter getInstance(Writer target, int max) {
        if (BUFFERING_ENABLED && !(target instanceof GrailsRoutablePrintWriter) && !(target instanceof StreamCharBufferWriter)) {
            StreamCharBuffer streamBuffer=new StreamCharBuffer(max, 0, max);
            streamBuffer.connectTo(target, false);
            target=streamBuffer.getWriter();
        }

        if (instantiator == null) {
            return new GSPResponseWriter(target);
        }
View Full Code Here

        if(encoders==null || encoders.isEmpty()) {
            streamEncodeable.encodeTo(appender, null);
        } else {    
            StreamEncodeable lastStreamEncodeable = streamEncodeable;
            if(encoders.size() > 1) {
                StreamCharBuffer buffer;
                if(streamEncodeable instanceof StreamCharBuffer) {
                    buffer = (StreamCharBuffer)streamEncodeable;
                } else {
                    buffer = new StreamCharBuffer();
                    streamEncodeable.encodeTo(((StreamCharBuffer.StreamCharBufferWriter)buffer.getWriter()).getEncodedAppender(), null);
                }
                for(int i=0;i < encoders.size()-1;i++) {
                    buffer = buffer.encodeToBuffer(encoders.get(i));
                }
                lastStreamEncodeable = buffer;
            }
            lastStreamEncodeable.encodeTo(appender, encoders.get(encoders.size()-1));
        }
View Full Code Here

        public PrintWriter getWriter() {
            if (charBuffer == null) {
                if (byteBuffer != null) {
                    throw new IllegalStateException("response.getWriter() called after response.getOutputStream()");
                }
                charBuffer=new StreamCharBuffer();
                charBuffer.setNotifyParentBuffersEnabled(false);
                if (gspSitemeshPage != null) {
                    gspSitemeshPage.setPageBuffer(charBuffer);
                }
                exposedWriter = GrailsPrintWriterAdapter.newInstance(charBuffer.getWriter());
View Full Code Here

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

        if (!usingWriter) {
            usingWriter = true;
            charBuffer = new StreamCharBuffer();
            charBuffer.setNotifyParentBuffersEnabled(false);
            pw = GrailsPrintWriterAdapter.newInstance(charBuffer.getWriter());
        }
        return pw;
    }
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

    }

    public InputStream parse() {
        resolveKeepGeneratedDirectory();

        StreamCharBuffer streamBuffer = new StreamCharBuffer(1024);
        StreamByteBuffer byteOutputBuffer = new StreamByteBuffer(1024,
                StreamByteBuffer.ReadMode.RETAIN_AFTER_READING);

        try {
            streamBuffer.connectTo(new OutputStreamWriter(byteOutputBuffer.getOutputStream(),
                    GROOVY_SOURCE_CHAR_ENCODING), true);
        }
        catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Grails cannot run unless your environment supports UTF-8!");
        }

        File keepGeneratedFile = null;
        Writer keepGeneratedWriter = null;
        if (keepGeneratedDirectory != null) {
            keepGeneratedFile = new File(keepGeneratedDirectory, className);
            try {
                keepGeneratedWriter = new OutputStreamWriter(
                        new FileOutputStream(keepGeneratedFile),
                        GROOVY_SOURCE_CHAR_ENCODING);
            }
            catch (IOException e) {
                LOG.warn("Cannot open keepgenerated file for writing. File's absolute path is '" +
                        keepGeneratedFile.getAbsolutePath() + "'");
                keepGeneratedFile = null;
            }
            streamBuffer.connectTo(keepGeneratedWriter, true);
        }

        Writer target = streamBuffer.getWriter();
        try {
            generateGsp(target, false);

            if (LOG.isDebugEnabled()) {
                if (keepGeneratedFile != null) {
View Full Code Here

        super(out);
        if (buffer) initBuffer();
    }

    void initBuffer() {
        streamBuffer = new StreamCharBuffer();
        streamBufferWriter = streamBuffer.getWriter();
    }
View Full Code Here

TOP

Related Classes of org.grails.buffer.StreamCharBuffer$LazyInitializingMultipleWriter

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.