public final class BufferedServletOutput extends Object
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.| Modifier and Type | Class and Description |
|---|---|
static class |
BufferedServletOutput.ResponseWriteMethod |
| Constructor and Description |
|---|
BufferedServletOutput(javax.servlet.ServletResponse wrappedResponse)
Creates a new servlet output buffering both the underlying writer and output stream.
|
BufferedServletOutput(javax.servlet.ServletResponse wrappedResponse,
StringWriter writer,
ByteArrayOutputStream outputStream)
Creates a new servlet output using the given StringWriter and OutputStream as buffers.
|
| Modifier and Type | Method and Description |
|---|---|
void |
flushBuffer()
Will not commit the response, but only make sure that the wrapped response's
flushBuffer() is executed, once this close() is called. |
byte[] |
getBufferedBytes() |
String |
getBufferedString() |
BufferedServletOutput.ResponseWriteMethod |
getWriteMethod() |
void |
resetBuffer()
Flushes the buffers bound to this object.
|
void |
setFlushBufferOnClose(boolean flushBufferOnClose)
Influences the behavior of the buffered data during calling
close(). |
public BufferedServletOutput(javax.servlet.ServletResponse wrappedResponse)
wrappedResponse - the wrapped responsepublic BufferedServletOutput(javax.servlet.ServletResponse wrappedResponse,
StringWriter writer,
ByteArrayOutputStream outputStream)
wrappedResponse - the wrapped responsewriter - 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)public BufferedServletOutput.ResponseWriteMethod getWriteMethod()
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.public String getBufferedString()
getWriter()IllegalStateException - in case getWriter() has not been called yet or the writer was not buffered.public byte[] getBufferedBytes()
getOutputStream()IllegalStateException - in case getOutputStream() has not been called yet or the output stream was not buffered.public void resetBuffer()
ServletResponse.flushBuffer() of the underlying response.public void setFlushBufferOnClose(boolean flushBufferOnClose)
close().
If flushBufferOnClose is true (default setting) the buffer is flushed to the wrapped response, otherwise the buffer is discarded.flushBufferOnClose - public void flushBuffer()
throws IOException
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.IOExceptionCopyright © 2013–2021 Adobe. All rights reserved.