Package com.adobe.acs.commons.util
Class BufferedServletOutput
java.lang.Object
com.adobe.acs.commons.util.BufferedServletOutput
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.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionBufferedServletOutput(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. -
Method Summary
Modifier and TypeMethodDescriptionvoidWill not commit the response, but only make sure that the wrapped response'sflushBuffer()is executed, once thisclose()is called.byte[]voidFlushes the buffers bound to this object.voidsetFlushBufferOnClose(boolean flushBufferOnClose) Influences the behavior of the buffered data during callingclose().
-
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 responsewriter- the writer to use as buffer (may benullin case you don't want to buffer the writer)outputStream- theByteArrayOutputStreamto use as buffer for getOutputStream() (may benullin case you don't want to buffer the output stream)
-
-
Method Details
-
getWriteMethod
- Returns:
BufferedServletOutput.ResponseWriteMethod.OUTPUTSTREAMin casegetOutputStream()has been called,BufferedServletOutput.ResponseWriteMethod.WRITERin casegetWriter()has been called,nullin case none of those have been called yet.
-
getBufferedString
- Returns:
- the buffered string which is the content of the response being written via
getWriter() - Throws:
IllegalStateException- in casegetWriter()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 casegetOutputStream()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 callsServletResponse.flushBuffer()of the underlying response. -
setFlushBufferOnClose
public void setFlushBufferOnClose(boolean flushBufferOnClose) Influences the behavior of the buffered data during callingclose(). IfflushBufferOnCloseistrue(default setting) the buffer is flushed to the wrapped response, otherwise the buffer is discarded.- Parameters:
flushBufferOnClose-
-
flushBuffer
Will not commit the response, but only make sure that the wrapped response'sflushBuffer()is executed, once thisclose()is called. This only affects output which is buffered, i.e. for unbuffered output the flush is not deferred.- Throws:
IOException
-