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..
ContentCachingRequestWrapper
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private final FastByteArrayOutputStream | |
| private Integer | |
| private String | |
| private ServletOutputStream | |
| private PrintWriter |
| Access | Constructor and Description |
|---|---|
| public | ContentCachingResponseWrapper(HttpServletResponse
the original servlet response response)Create a new ContentCachingResponseWrapper for the given servlet response. |
| Modifier and Type | Method 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. Implements jakarta. 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. Implements jakarta. 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. Implements jakarta. The default behavior of this method is to call containsHeader(String name) on the wrapped response object. |
| public void | |
| 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. Implements jakarta. Forces any content in the buffer to be written to the client. |
| public byte[] | |
| public InputStream | |
| public int | |
| public String | getContentType()
Overrides jakarta. Implements jakarta. 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. Implements jakarta. Return the value for the specified header, or |
| public Collection | getHeaderNames()
Overrides jakarta. Implements jakarta. Get the header names set for this HTTP response. |
| public Collection | getHeaders(String
Header name to look up name)Overrides jakarta. Implements jakarta. Return a Collection of all the header values associated with the specified header name. |
| public ServletOutputStream | getOutputStream()
Overrides jakarta. Implements jakarta. Returns a |
| public PrintWriter | getWriter()
Overrides jakarta. Implements jakarta. Returns a |
| public void | reset()
Overrides jakarta. Implements jakarta. Clears any data that exists in the buffer as well as the status code and headers. |
| public void | resetBuffer()
Overrides jakarta. Implements jakarta. 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. Implements jakarta. 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. Implements jakarta. 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. Implements jakarta. 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. Implements jakarta. 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. Implements jakarta. 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. Implements jakarta. 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 type)String specifying the MIME type of the contentOverrides jakarta. Implements jakarta. 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. Implements jakarta. 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. Implements jakarta. The default behavior of this method is to call setIntHeader(String name, int value) on the wrapped response object. |
| content | back to summary |
|---|---|
| private final FastByteArrayOutputStream content | |
| contentLength | back to summary |
|---|---|
| private Integer contentLength
| |
| contentType | back to summary |
|---|---|
| private String contentType
| |
| outputStream | back to summary |
|---|---|
| private ServletOutputStream outputStream
| |
| writer | back to summary |
|---|---|
| private PrintWriter writer
| |
| ContentCachingResponseWrapper | back to summary |
|---|---|
| public ContentCachingResponseWrapper(HttpServletResponse response) Create a new ContentCachingResponseWrapper for the given servlet response.
| |
| addHeader | back to summary |
|---|---|
| public void addHeader(String name, String value) Overrides jakarta. Implements jakarta. Doc from jakarta. The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object.
| |
| addIntHeader | back to summary |
|---|---|
| public void addIntHeader(String name, int value) Overrides jakarta. Implements jakarta. Doc from jakarta. The default behavior of this method is to call addIntHeader(String name, int value) on the wrapped response object.
| |
| containsHeader | back to summary |
|---|---|
| public boolean containsHeader(String name) Overrides jakarta. Implements jakarta. Doc from jakarta. The default behavior of this method is to call containsHeader(String name) on the wrapped response object.
| |
| copyBodyToResponse | back to summary |
|---|---|
| public void copyBodyToResponse() throws IOException Copy the complete cached body content to the response.
| |
| copyBodyToResponse | back to summary |
|---|---|
| protected void copyBodyToResponse(boolean complete) throws IOException Copy the cached body content to the response.
| |
| flushBuffer | back to summary |
|---|---|
| public void flushBuffer() throws IOException Overrides jakarta. Implements jakarta. Doc from jakarta. Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.
| |
| getContentAsByteArray | back to summary |
|---|---|
| public byte[] getContentAsByteArray() Return the cached response content as a byte array. | |
| getContentInputStream | back to summary |
|---|---|
| public InputStream getContentInputStream() Return an
| |
| getContentSize | back to summary |
|---|---|
| public int getContentSize() Return the current size of the cached content.
| |
| getContentType | back to summary |
|---|---|
| public String getContentType() Overrides jakarta. Implements jakarta. Doc from jakarta. Returns the content type used for the MIME body sent in this response. The content type proper must have been
specified using | |
| getHeader | back to summary |
|---|---|
| public String getHeader(String name) Overrides jakarta. Implements jakarta. Doc from jakarta. Return the value for the specified header, or
The default implementation is to call
| |
| getHeaderNames | back to summary |
|---|---|
| public Collection Overrides jakarta. Implements jakarta. Doc from jakarta. Get the header names set for this HTTP response.
The default implementation is to call
| |
| getHeaders | back to summary |
|---|---|
| public Collection Overrides jakarta. Implements jakarta. Doc from jakarta. Return a Collection of all the header values associated with the specified header name.
The default implementation is to call
| |
| getOutputStream | back to summary |
|---|---|
| public ServletOutputStream getOutputStream() throws IOException Overrides jakarta. Implements jakarta. Doc from jakarta. Returns a
Calling flush() on the ServletOutputStream commits the response. Either this method or
| |
| getWriter | back to summary |
|---|---|
| public PrintWriter getWriter() throws IOException Overrides jakarta. Implements jakarta. Doc from jakarta. Returns a
Calling flush() on the
Either this method or
| |
| reset | back to summary |
|---|---|
| public void reset() Overrides jakarta. Implements jakarta. Doc from jakarta. Clears any data that exists in the buffer as well as the status code and headers. If the response has been
committed, this method throws an
| |
| resetBuffer | back to summary |
|---|---|
| public void resetBuffer() Overrides jakarta. Implements jakarta. Doc from jakarta. Clears the content of the underlying buffer in the response without clearing headers or status code. If the
response has been committed, this method throws an
| |
| sendError | back to summary |
|---|---|
| public void sendError(int sc) throws IOException Overrides jakarta. Implements jakarta. Doc from jakarta. The default behavior of this method is to call sendError(int sc) on the wrapped response object.
| |
| sendError | back to summary |
|---|---|
| public void sendError(int sc, String msg) throws IOException Overrides jakarta. Implements jakarta. Doc from jakarta. The default behavior of this method is to call sendError(int sc, String msg) on the wrapped response object.
| |
| sendRedirect | back to summary |
|---|---|
| public void sendRedirect(String location) throws IOException Overrides jakarta. Implements jakarta. Doc from jakarta. The default behavior of this method is to call sendRedirect(String location) on the wrapped response object.
| |
| setBufferSize | back to summary |
|---|---|
| public void setBufferSize(int size) Overrides jakarta. Implements jakarta. Doc from jakarta. Sets the preferred buffer size for the body of the response. The servlet container will use a buffer at least as
large as the size requested. The actual buffer size used can be found using A larger buffer allows more content to be written before anything is actually sent, thus providing the servlet with more time to set appropriate status codes and headers. A smaller buffer decreases server memory load and allows the client to start receiving data more quickly.
This method must be called before any response body content is written; if content has been written or the
response object has been committed, this method throws an
| |
| setContentLength | back to summary |
|---|---|
| public void setContentLength(int len) Overrides jakarta. Implements jakarta. Doc from jakarta. Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
| |
| setContentLengthLong | back to summary |
|---|---|
| public void setContentLengthLong(long len) Overrides jakarta. Implements jakarta. Doc from jakarta. Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
| |
| setContentType | back to summary |
|---|---|
| public void setContentType(String type) Overrides jakarta. Implements jakarta. Doc from jakarta. Sets the content type of the response being sent to the client, if the response has not been committed yet. The
given content type may include a character encoding specification, for example,
This method may be called repeatedly to change content type and character encoding. This method has no effect if
called after the response has been committed. It does not set the response's character encoding if it is called
after
Containers must communicate the content type and the character encoding used for the servlet response's writer to
the client if the protocol provides a way for doing so. In the case of HTTP, the | |
| setHeader | back to summary |
|---|---|
| public void setHeader(String name, String value) Overrides jakarta. Implements jakarta. Doc from jakarta. The default behavior of this method is to return setHeader(String name, String value) on the wrapped response object.
| |
| setIntHeader | back to summary |
|---|---|
| public void setIntHeader(String name, int value) Overrides jakarta. Implements jakarta. Doc from jakarta. The default behavior of this method is to call setIntHeader(String name, int value) on the wrapped response object.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | write(char[]
Array of characters buf, int Offset from which to start writing characters off, int Number of characters to write len)Overrides java. Writes A Portion of an array of characters. |
| public void | write(String
A String s, int Offset from which to start writing characters off, int Number of characters to write len)Overrides java. Writes a portion of a string. |
| public void | write(int
int specifying a character to be written. c)Overrides java. Writes a single character. |
| ResponsePrintWriter | back to summary |
|---|---|
| public ResponsePrintWriter(String characterEncoding) throws UnsupportedEncodingException | |
| write | back to summary |
|---|---|
| public void write(char[] buf, int off, int len) Overrides java. Doc from java. Writes A Portion of an array of characters.
| |
| write | back to summary |
|---|---|
| public void write(String s, int off, int len) Overrides java. Doc from java. Writes a portion of a string. | |
| write | back to summary |
|---|---|
| public void write(int c) Overrides java. Doc from java. Writes a single character.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final ServletOutputStream |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | isReady()
Implements abstract jakarta. Checks if a non-blocking write will succeed. |
| public void | setWriteListener(WriteListener
The non-blocking IO write listener writeListener)Implements abstract jakarta. Sets the |
| public void | write(int
the b)byte.Implements abstract java. Writes the specified byte to this output stream. |
| public void | write(byte[]
the data. b, int the start offset in the data. off, int the number of bytes to write. len)Overrides java. Writes |
| os | back to summary |
|---|---|
| private final ServletOutputStream os | |
| ResponseServletOutputStream | back to summary |
|---|---|
| public ResponseServletOutputStream(ServletOutputStream os) | |
| isReady | back to summary |
|---|---|
| public boolean isReady() Implements abstract jakarta. Doc from jakarta. Checks if a non-blocking write will succeed. If this returns
| |
| setWriteListener | back to summary |
|---|---|
| public void setWriteListener(WriteListener writeListener) Implements abstract jakarta. Doc from jakarta. Sets the
| |
| write | back to summary |
|---|---|
| public void write(int b) throws IOException Implements abstract java. Doc from java. Writes the specified byte to this output stream. The general
contract for
| |
| write | back to summary |
|---|---|
| public void write(byte[] b, int off, int len) throws IOException Overrides java. Doc from java. Writes
If
If
| |