public class ContentCachingResponseWrapper
extends HttpServletResponseWrapper
javax.servlet.http.HttpServletResponse
wrapper that caches all content written to
the output stream and writer,
and allows this content to be retrieved via a byte array
.
Used e.g. by ShallowEtagHeaderFilter
.
ContentCachingRequestWrapper
Modifier and Type | Class and Description |
---|---|
private class |
ContentCachingResponseWrapper.ResponsePrintWriter |
private class |
ContentCachingResponseWrapper.ResponseServletOutputStream |
Modifier and Type | Field and Description |
---|---|
private FastByteArrayOutputStream |
content |
private java.lang.Integer |
contentLength |
private ServletOutputStream |
outputStream |
private int |
statusCode |
private java.io.PrintWriter |
writer |
Constructor and Description |
---|
ContentCachingResponseWrapper(HttpServletResponse response)
Create a new ContentCachingResponseWrapper for the given servlet response.
|
Modifier and Type | Method and Description |
---|---|
void |
copyBodyToResponse()
Copy the complete cached body content to the response.
|
protected void |
copyBodyToResponse(boolean complete)
Copy the cached body content to the response.
|
void |
flushBuffer() |
byte[] |
getContentAsByteArray()
Return the cached response content as a byte array.
|
java.io.InputStream |
getContentInputStream()
Return an
InputStream to the cached content. |
int |
getContentSize()
Return the current size of the cached content.
|
ServletOutputStream |
getOutputStream() |
int |
getStatusCode()
Return the status code as specified on the response.
|
java.io.PrintWriter |
getWriter() |
void |
reset() |
void |
resetBuffer() |
void |
sendError(int sc) |
void |
sendError(int sc,
java.lang.String msg) |
void |
sendRedirect(java.lang.String location) |
void |
setBufferSize(int size) |
void |
setContentLength(int len) |
void |
setContentLengthLong(long len) |
void |
setStatus(int sc) |
void |
setStatus(int sc,
java.lang.String sm) |
private final FastByteArrayOutputStream content
private final ServletOutputStream outputStream
private java.io.PrintWriter writer
private int statusCode
private java.lang.Integer contentLength
public ContentCachingResponseWrapper(HttpServletResponse response)
response
- the original servlet responsepublic void setStatus(int sc)
public void setStatus(int sc, java.lang.String sm)
public void sendError(int sc) throws java.io.IOException
java.io.IOException
public void sendError(int sc, java.lang.String msg) throws java.io.IOException
java.io.IOException
public void sendRedirect(java.lang.String location) throws java.io.IOException
java.io.IOException
public ServletOutputStream getOutputStream() throws java.io.IOException
java.io.IOException
public java.io.PrintWriter getWriter() throws java.io.IOException
java.io.IOException
public void flushBuffer() throws java.io.IOException
java.io.IOException
public void setContentLength(int len)
public void setContentLengthLong(long len)
public void setBufferSize(int size)
public void resetBuffer()
public void reset()
public int getStatusCode()
public byte[] getContentAsByteArray()
public java.io.InputStream getContentInputStream()
InputStream
to the cached content.public int getContentSize()
public void copyBodyToResponse() throws java.io.IOException
java.io.IOException
protected void copyBodyToResponse(boolean complete) throws java.io.IOException
complete
- whether to set a corresponding content length
for the complete cached body contentjava.io.IOException