Class SmartOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    class SmartOutputStream
    extends TemporaryBuffer
    Buffers a response, trying to gzip it if the user agent supports that.

    If the response overflows the buffer, gzip is skipped and the response is streamed to the client as its produced, most likely using HTTP/1.1 chunked encoding. This is useful for servlets that produce mixed-mode content, where smaller payloads are primarily pure text that compresses well, while much larger payloads are heavily compressed binary data. UploadPackServlet is one such servlet.

    • Field Detail

      • req

        private final javax.servlet.http.HttpServletRequest req
      • rsp

        private final javax.servlet.http.HttpServletResponse rsp
      • compressStream

        private boolean compressStream
      • startedOutput

        private boolean startedOutput
    • Constructor Detail

      • SmartOutputStream

        SmartOutputStream​(javax.servlet.http.HttpServletRequest req,
                          javax.servlet.http.HttpServletResponse rsp,
                          boolean compressStream)
    • Method Detail

      • overflow

        protected java.io.OutputStream overflow()
                                         throws java.io.IOException
        Open the overflow output stream, so the remaining output can be stored.
        Specified by:
        overflow in class TemporaryBuffer
        Returns:
        the output stream to receive the buffered content, followed by the remaining output.
        Throws:
        java.io.IOException - the buffer cannot create the overflow stream.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class TemporaryBuffer
        Throws:
        java.io.IOException
      • writeResponse

        private void writeResponse​(TemporaryBuffer out)
                            throws java.io.IOException
        Throws:
        java.io.IOException