Class BufferedServletOutput

java.lang.Object
com.adobe.acs.commons.util.BufferedServletOutput

public final class BufferedServletOutput extends Object
Helper class to be used in ServletResponse wrappers. It allows to buffer the output without committing it to the underlying response. Also it exposes methods to access the buffers for the writer and output stream. When calling close it will automatically spool the buffers to the underlying response.
  • Constructor Details

    • BufferedServletOutput

      public BufferedServletOutput(javax.servlet.ServletResponse wrappedResponse)
      Creates a new servlet output buffering both the underlying writer and output stream.
      Parameters:
      wrappedResponse - the wrapped response
    • BufferedServletOutput

      public BufferedServletOutput(javax.servlet.ServletResponse wrappedResponse, StringWriter writer, ByteArrayOutputStream outputStream)
      Creates a new servlet output using the given StringWriter and OutputStream as buffers.
      Parameters:
      wrappedResponse - the wrapped response
      writer - the writer to use as buffer (may be null in case you don't want to buffer the writer)
      outputStream - the ByteArrayOutputStream to use as buffer for getOutputStream() (may be null in case you don't want to buffer the output stream)
  • Method Details

    • getWriteMethod

      Returns:
      BufferedServletOutput.ResponseWriteMethod.OUTPUTSTREAM in case getOutputStream() has been called, BufferedServletOutput.ResponseWriteMethod.WRITER in case getWriter() has been called, null in case none of those have been called yet.
    • getBufferedString

      public String getBufferedString()
      Returns:
      the buffered string which is the content of the response being written via getWriter()
      Throws:
      IllegalStateException - in case getWriter() has not been called yet or the writer was not buffered.
    • getBufferedBytes

      public byte[] getBufferedBytes()
      Returns:
      the buffered bytes which which were written via getOutputStream()
      Throws:
      IllegalStateException - in case getOutputStream() has not been called yet or the output stream was not buffered.
    • resetBuffer

      public void resetBuffer()
      Flushes the buffers bound to this object. In addition calls ServletResponse.flushBuffer() of the underlying response.
    • setFlushBufferOnClose

      public void setFlushBufferOnClose(boolean flushBufferOnClose)
      Influences the behavior of the buffered data during calling close(). If flushBufferOnClose is true (default setting) the buffer is flushed to the wrapped response, otherwise the buffer is discarded.
      Parameters:
      flushBufferOnClose -
    • flushBuffer

      public void flushBuffer() throws IOException
      Will not commit the response, but only make sure that the wrapped response's flushBuffer() is executed, once this close() is called. This only affects output which is buffered, i.e. for unbuffered output the flush is not deferred.
      Throws:
      IOException