Package com.adobe.acs.commons.util
Class BufferedServletOutput
- java.lang.Object
-
- com.adobe.acs.commons.util.BufferedServletOutput
-
public final class BufferedServletOutput extends Object
Helper class to be used inServletResponsewrappers. 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 Modifier and Type Class Description static classBufferedServletOutput.ResponseWriteMethod
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidflushBuffer()Will not commit the response, but only make sure that the wrapped response'sflushBuffer()is executed, once thisclose()is calledbyte[]getBufferedBytes()StringgetBufferedString()BufferedServletOutput.ResponseWriteMethodgetWriteMethod()voidresetBuffer()Flushes the buffers bound to this object.
-
-
-
Constructor Detail
-
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 Detail
-
getWriteMethod
public BufferedServletOutput.ResponseWriteMethod 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
public String 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.
-
flushBuffer
public void flushBuffer()
Will not commit the response, but only make sure that the wrapped response'sflushBuffer()is executed, once thisclose()is called
-
-