Search in sources :

Example 31 with WriteListener

use of javax.servlet.WriteListener in project grails-core by grails.

the class IncludeResponseWrapper method getOutputStream.

@Override
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);
            }

            @Override
            public void write(byte[] b) throws IOException {
                os.write(b);
            }

            @Override
            public void write(int b) throws IOException {
                os.write(b);
            }

            @Override
            public boolean isReady() {
                return true;
            }

            @Override
            public void setWriteListener(WriteListener writeListener) {
            // no op
            }
        };
    }
    return sos;
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) StreamByteBuffer(org.grails.buffer.StreamByteBuffer) IOException(java.io.IOException) WriteListener(javax.servlet.WriteListener)

Aggregations

WriteListener (javax.servlet.WriteListener)31 ServletOutputStream (javax.servlet.ServletOutputStream)27 IOException (java.io.IOException)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)17 HttpServletResponse (javax.servlet.http.HttpServletResponse)17 AsyncContext (javax.servlet.AsyncContext)12 Test (org.junit.Test)11 ServletException (javax.servlet.ServletException)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 HttpServlet (javax.servlet.http.HttpServlet)6 InterruptedIOException (java.io.InterruptedIOException)5 ByteBuffer (java.nio.ByteBuffer)5 ReadListener (javax.servlet.ReadListener)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Request (org.eclipse.jetty.server.Request)4 Before (org.junit.Before)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 UncheckedIOException (java.io.UncheckedIOException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3