Top Description Inners Fields Constructors Methods
org.springframework.web.util

public Class ContentCachingResponseWrapper

extends HttpServletResponseWrapper
Class Inheritance
Known Direct Subclasses
org.springframework.web.filter.ShallowEtagHeaderFilter.ConditionalContentCachingResponseWrapper
Imports
java.io.IOException, .InputStream, .OutputStreamWriter, .PrintWriter, .UnsupportedEncodingException, java.util.ArrayList, .Collection, .Collections, .List, jakarta.servlet.ServletOutputStream, .WriteListener, jakarta.servlet.http.HttpServletResponse, .HttpServletResponseWrapper, org.springframework.http.HttpHeaders, org.springframework.lang.Nullable, org.springframework.util.FastByteArrayOutputStream

jakarta.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 org.springframework.web.filter.ShallowEtagHeaderFilter.

Author
Juergen Hoeller
Since
4.1.3
See Also
ContentCachingRequestWrapper

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private final FastByteArrayOutputStream
private Integer
private String
private ServletOutputStream
private PrintWriter

Constructor Summary

AccessConstructor and Description
public
ContentCachingResponseWrapper(HttpServletResponse
the original servlet response
response
)

Create a new ContentCachingResponseWrapper for the given servlet response.

Method Summary

Modifier and TypeMethod and Description
public void
addHeader(String
the name of the header
name
,
String
the additional header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)
value
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.addHeader.

Implements jakarta.servlet.http.HttpServletResponse.addHeader.

The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object.
public void
addIntHeader(String
the name of the header
name
,
int
the assigned integer value
value
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.addIntHeader.

Implements jakarta.servlet.http.HttpServletResponse.addIntHeader.

The default behavior of this method is to call addIntHeader(String name, int value) on the wrapped response object.
public boolean
containsHeader(String
the header name
name
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.containsHeader.

Implements jakarta.servlet.http.HttpServletResponse.containsHeader.

The default behavior of this method is to call containsHeader(String name) on the wrapped response object.
public void
copyBodyToResponse()

Copy the complete cached body content to the response.

protected void
copyBodyToResponse(boolean
whether to set a corresponding content length for the complete cached body content
complete
)

Copy the cached body content to the response.

public void
flushBuffer()

Overrides jakarta.servlet.ServletResponseWrapper.flushBuffer.

Implements jakarta.servlet.ServletResponse.flushBuffer.

Forces any content in the buffer to be written to the client.
public byte[]
getContentAsByteArray()

Return the cached response content as a byte array.

public InputStream
getContentInputStream()

Return an InputStream to the cached content.

public int
getContentSize()

Return the current size of the cached content.

public String
getContentType()

Overrides jakarta.servlet.ServletResponseWrapper.getContentType.

Implements jakarta.servlet.ServletResponse.getContentType.

Returns the content type used for the MIME body sent in this response.
public String
getHeader(String
Header name to look up
name
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.getHeader.

Implements jakarta.servlet.http.HttpServletResponse.getHeader.

Return the value for the specified header, or null if this header has not been set.
public Collection<String>
public Collection<String>
getHeaders(String
Header name to look up
name
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.getHeaders.

Implements jakarta.servlet.http.HttpServletResponse.getHeaders.

Return a Collection of all the header values associated with the specified header name.
public ServletOutputStream
public PrintWriter
getWriter()

Overrides jakarta.servlet.ServletResponseWrapper.getWriter.

Implements jakarta.servlet.ServletResponse.getWriter.

Returns a PrintWriter object that can send character text to the client.
public void
reset()

Overrides jakarta.servlet.ServletResponseWrapper.reset.

Implements jakarta.servlet.ServletResponse.reset.

Clears any data that exists in the buffer as well as the status code and headers.
public void
resetBuffer()

Overrides jakarta.servlet.ServletResponseWrapper.resetBuffer.

Implements jakarta.servlet.ServletResponse.resetBuffer.

Clears the content of the underlying buffer in the response without clearing headers or status code.
public void
sendError(int
the error status code
sc
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.sendError.

Implements jakarta.servlet.http.HttpServletResponse.sendError.

The default behavior of this method is to call sendError(int sc) on the wrapped response object.
public void
sendError(int
the error status code
sc
,
String
the descriptive message
msg
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.sendError.

Implements jakarta.servlet.http.HttpServletResponse.sendError.

The default behavior of this method is to call sendError(int sc, String msg) on the wrapped response object.
public void
sendRedirect(String
the redirect location URL (may be absolute or relative)
location
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.sendRedirect.

Implements jakarta.servlet.http.HttpServletResponse.sendRedirect.

The default behavior of this method is to call sendRedirect(String location) on the wrapped response object.
public void
setBufferSize(int
the preferred buffer size
size
)

Overrides jakarta.servlet.ServletResponseWrapper.setBufferSize.

Implements jakarta.servlet.ServletResponse.setBufferSize.

Sets the preferred buffer size for the body of the response.
public void
setContentLength(int
an integer specifying the length of the content being returned to the client; sets the Content-Length header
len
)

Overrides jakarta.servlet.ServletResponseWrapper.setContentLength.

Implements jakarta.servlet.ServletResponse.setContentLength.

Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
public void
setContentLengthLong(long
an integer specifying the length of the content being returned to the client; sets the Content-Length header
len
)

Overrides jakarta.servlet.ServletResponseWrapper.setContentLengthLong.

Implements jakarta.servlet.ServletResponse.setContentLengthLong.

Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
public void
setContentType(String
a String specifying the MIME type of the content
type
)

Overrides jakarta.servlet.ServletResponseWrapper.setContentType.

Implements jakarta.servlet.ServletResponse.setContentType.

Sets the content type of the response being sent to the client, if the response has not been committed yet.
public void
setHeader(String
the name of the header
name
,
String
the header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)
value
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.setHeader.

Implements jakarta.servlet.http.HttpServletResponse.setHeader.

The default behavior of this method is to return setHeader(String name, String value) on the wrapped response object.
public void
setIntHeader(String
the name of the header
name
,
int
the assigned integer value
value
)

Overrides jakarta.servlet.http.HttpServletResponseWrapper.setIntHeader.

Implements jakarta.servlet.http.HttpServletResponse.setIntHeader.

The default behavior of this method is to call setIntHeader(String name, int value) on the wrapped response object.
Inherited from jakarta.servlet.http.HttpServletResponseWrapper:
addCookieaddDateHeaderencodeRedirectURLencodeURLgetStatusgetTrailerFieldssetDateHeadersetStatussetTrailerFields