Package jakarta.servlet
Class ServletResponseWrapper
java.lang.Object
jakarta.servlet.ServletResponseWrapper
- All Implemented Interfaces:
ServletResponse
- Direct Known Subclasses:
HttpServletResponseWrapper
Provides a convenient implementation of the ServletResponse interface that can be subclassed by developers wishing to
adapt the response from a Servlet. This class implements the Wrapper or Decorator pattern. Methods default to calling
through to the wrapped response object.
- Since:
- Servlet 2.3
- Author:
- Various
- See Also:
-
Constructor Summary
ConstructorDescriptionServletResponseWrapper
(ServletResponse response) Creates a ServletResponse adaptor wrapping the given response object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
The default behavior of this method is to call flushBuffer() on the wrapped response object.int
The default behavior of this method is to return getBufferSize() on the wrapped response object.The default behavior of this method is to return getCharacterEncoding() on the wrapped response object.The default behavior of this method is to return getContentType() on the wrapped response object.The default behavior of this method is to return getLocale() on the wrapped response object.The default behavior of this method is to return getOutputStream() on the wrapped response object.Return the wrapped ServletResponse object.The default behavior of this method is to return getWriter() on the wrapped response object.boolean
The default behavior of this method is to return isCommitted() on the wrapped response object.boolean
isWrapperFor
(ServletResponse wrapped) Checks (recursively) if this ServletResponseWrapper wraps the givenServletResponse
instance.boolean
isWrapperFor
(Class<?> wrappedType) Checks (recursively) if this ServletResponseWrapper wraps aServletResponse
of the given class type.void
reset()
The default behavior of this method is to call reset() on the wrapped response object.void
The default behavior of this method is to call resetBuffer() on the wrapped response object.void
setBufferSize
(int size) The default behavior of this method is to call setBufferSize(int size) on the wrapped response object.void
setCharacterEncoding
(String encoding) The default behavior of this method is to call setCharacterEncoding(String encoding) on the wrapped response object.void
setCharacterEncoding
(Charset encoding) The default behavior of this method is to call setCharacterEncoding(Charset encoding) on the wrapped response object.void
setContentLength
(int len) The default behavior of this method is to call setContentLength(int len) on the wrapped response object.void
setContentLengthLong
(long len) The default behavior of this method is to call setContentLengthLong(long len) on the wrapped response object.void
setContentType
(String type) The default behavior of this method is to call setContentType(String type) on the wrapped response object.void
The default behavior of this method is to call setLocale(Locale loc) on the wrapped response object.void
setResponse
(ServletResponse response) Sets the response being wrapped.
-
Constructor Details
-
ServletResponseWrapper
Creates a ServletResponse adaptor wrapping the given response object.- Parameters:
response
- theServletResponse
to be wrapped- Throws:
IllegalArgumentException
- if the response is null.
-
-
Method Details
-
getResponse
Return the wrapped ServletResponse object.- Returns:
- the wrapped
ServletResponse
-
setResponse
Sets the response being wrapped.- Parameters:
response
- theServletResponse
to be installed- Throws:
IllegalArgumentException
- if the response is null.
-
setCharacterEncoding
The default behavior of this method is to call setCharacterEncoding(String encoding) on the wrapped response object.- Specified by:
setCharacterEncoding
in interfaceServletResponse
- Parameters:
encoding
- a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets) ornull
- Since:
- Servlet 2.4
- See Also:
-
setCharacterEncoding
The default behavior of this method is to call setCharacterEncoding(Charset encoding) on the wrapped response object.- Specified by:
setCharacterEncoding
in interfaceServletResponse
- Parameters:
encoding
- a Charset instance representing the encoding to use ornull
- Since:
- Servlet 6.1
- See Also:
-
getCharacterEncoding
The default behavior of this method is to return getCharacterEncoding() on the wrapped response object.- Specified by:
getCharacterEncoding
in interfaceServletResponse
- Returns:
- a
String
specifying the name of the character encoding, for example,UTF-8
-
getOutputStream
The default behavior of this method is to return getOutputStream() on the wrapped response object.- Specified by:
getOutputStream
in interfaceServletResponse
- Returns:
- a
ServletOutputStream
for writing binary data - Throws:
IOException
- if an input or output exception occurred- See Also:
-
getWriter
The default behavior of this method is to return getWriter() on the wrapped response object.- Specified by:
getWriter
in interfaceServletResponse
- Returns:
- a
PrintWriter
object that can return character data to the client - Throws:
UnsupportedEncodingException
- if the character encoding returned bygetCharacterEncoding
cannot be usedIOException
- if an input or output exception occurred- See Also:
-
setContentLength
public void setContentLength(int len) The default behavior of this method is to call setContentLength(int len) on the wrapped response object.- Specified by:
setContentLength
in interfaceServletResponse
- Parameters:
len
- an integer specifying the length of the content being returned to the client; sets the Content-Length header
-
setContentLengthLong
public void setContentLengthLong(long len) The default behavior of this method is to call setContentLengthLong(long len) on the wrapped response object.- Specified by:
setContentLengthLong
in interfaceServletResponse
- Parameters:
len
- a long specifying the length of the content being returned to the client; sets the Content-Length header- Since:
- Servlet 3.1
-
setContentType
The default behavior of this method is to call setContentType(String type) on the wrapped response object.- Specified by:
setContentType
in interfaceServletResponse
- Parameters:
type
- aString
specifying the MIME type of the content ornull
- See Also:
-
getContentType
The default behavior of this method is to return getContentType() on the wrapped response object.- Specified by:
getContentType
in interfaceServletResponse
- Returns:
- a
String
specifying the content type, for example,text/html; charset=UTF-8
, or null - Since:
- Servlet 2.4
-
setBufferSize
public void setBufferSize(int size) The default behavior of this method is to call setBufferSize(int size) on the wrapped response object.- Specified by:
setBufferSize
in interfaceServletResponse
- Parameters:
size
- the preferred buffer size- See Also:
-
getBufferSize
public int getBufferSize()The default behavior of this method is to return getBufferSize() on the wrapped response object.- Specified by:
getBufferSize
in interfaceServletResponse
- Returns:
- the actual buffer size used
- See Also:
-
flushBuffer
The default behavior of this method is to call flushBuffer() on the wrapped response object.- Specified by:
flushBuffer
in interfaceServletResponse
- Throws:
IOException
- if the act of flushing the buffer cannot be completed.- See Also:
-
isCommitted
public boolean isCommitted()The default behavior of this method is to return isCommitted() on the wrapped response object.- Specified by:
isCommitted
in interfaceServletResponse
- Returns:
- a boolean indicating if the response has been committed
- See Also:
-
reset
public void reset()The default behavior of this method is to call reset() on the wrapped response object.- Specified by:
reset
in interfaceServletResponse
- See Also:
-
resetBuffer
public void resetBuffer()The default behavior of this method is to call resetBuffer() on the wrapped response object.- Specified by:
resetBuffer
in interfaceServletResponse
- See Also:
-
setLocale
The default behavior of this method is to call setLocale(Locale loc) on the wrapped response object.- Specified by:
setLocale
in interfaceServletResponse
- Parameters:
loc
- the locale of the response or {code @null}- See Also:
-
getLocale
The default behavior of this method is to return getLocale() on the wrapped response object.- Specified by:
getLocale
in interfaceServletResponse
- Returns:
- the Locale for this response.
- See Also:
-
isWrapperFor
Checks (recursively) if this ServletResponseWrapper wraps the givenServletResponse
instance.- Parameters:
wrapped
- the ServletResponse instance to search for- Returns:
- true if this ServletResponseWrapper wraps the given ServletResponse instance, false otherwise
- Since:
- Servlet 3.0
-
isWrapperFor
Checks (recursively) if this ServletResponseWrapper wraps aServletResponse
of the given class type.- Parameters:
wrappedType
- the ServletResponse class type to search for- Returns:
- true if this ServletResponseWrapper wraps a ServletResponse of the given class type, false otherwise
- Throws:
IllegalArgumentException
- if the given class does not implementServletResponse
- Since:
- Servlet 3.0
-