Search in sources :

Example 1 with DelegatingServletOutputStream

use of org.apereo.portal.utils.DelegatingServletOutputStream in project uPortal by Jasig.

the class PortletHttpServletResponseWrapper method getOutputStream.

@Override
public ServletOutputStream getOutputStream() throws IOException {
    if (this.servletOutputStream == null) {
        final OutputStream out;
        if (logger.isDebugEnabled()) {
            out = new ByteArrayOutputStream() {

                @Override
                public void close() throws IOException {
                    super.close();
                    final byte[] data = this.toByteArray();
                    if (data.length > 0) {
                        logger.warn("Ignored {} bytes written to ServletOutputStream by {}\n\n{}", new Object[] { data.length, portletWindow, new String(data) });
                    }
                }
            };
        } else {
            out = new CountingOutputStream(NullOutputStream.NULL_OUTPUT_STREAM) {

                @Override
                public void close() throws IOException {
                    super.close();
                    final long byteCount = this.getByteCount();
                    if (byteCount > 0) {
                        logger.warn("Ignored {} bytes written to ServletOutputStream by {}, turn on DEBUG logging to see the output", byteCount, portletWindow);
                    }
                }
            };
        }
        this.servletOutputStream = new DelegatingServletOutputStream(out);
    }
    return this.servletOutputStream;
}
Also used : DelegatingServletOutputStream(org.apereo.portal.utils.DelegatingServletOutputStream) CountingOutputStream(org.apache.commons.io.output.CountingOutputStream) OutputStream(java.io.OutputStream) CountingOutputStream(org.apache.commons.io.output.CountingOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServletOutputStream(javax.servlet.ServletOutputStream) NullOutputStream(org.apache.commons.io.output.NullOutputStream) DelegatingServletOutputStream(org.apereo.portal.utils.DelegatingServletOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 CountingOutputStream (org.apache.commons.io.output.CountingOutputStream)1 NullOutputStream (org.apache.commons.io.output.NullOutputStream)1 DelegatingServletOutputStream (org.apereo.portal.utils.DelegatingServletOutputStream)1