Package jakarta.servlet
Class ServletResponseWrapper
- java.lang.Object
-
- jakarta.servlet.ServletResponseWrapper
-
- All Implemented Interfaces:
ServletResponse
- Direct Known Subclasses:
HttpServletResponseWrapper
public class ServletResponseWrapper extends Object implements ServletResponse
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:
ServletResponse
-
-
Constructor Summary
Constructors Constructor Description ServletResponseWrapper(ServletResponse response)Creates a ServletResponse adaptor wrapping the given response object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidflushBuffer()The default behavior of this method is to call flushBuffer() on the wrapped response object.intgetBufferSize()The default behavior of this method is to return getBufferSize() on the wrapped response object.StringgetCharacterEncoding()The default behavior of this method is to return getCharacterEncoding() on the wrapped response object.StringgetContentType()The default behavior of this method is to return getContentType() on the wrapped response object.LocalegetLocale()The default behavior of this method is to return getLocale() on the wrapped response object.ServletOutputStreamgetOutputStream()The default behavior of this method is to return getOutputStream() on the wrapped response object.ServletResponsegetResponse()Return the wrapped ServletResponse object.PrintWritergetWriter()The default behavior of this method is to return getWriter() on the wrapped response object.booleanisCommitted()The default behavior of this method is to return isCommitted() on the wrapped response object.booleanisWrapperFor(ServletResponse wrapped)Checks (recursively) if this ServletResponseWrapper wraps the givenServletResponseinstance.booleanisWrapperFor(Class<?> wrappedType)Checks (recursively) if this ServletResponseWrapper wraps aServletResponseof the given class type.voidreset()The default behavior of this method is to call reset() on the wrapped response object.voidresetBuffer()The default behavior of this method is to call resetBuffer() on the wrapped response object.voidsetBufferSize(int size)The default behavior of this method is to call setBufferSize(int size) on the wrapped response object.voidsetCharacterEncoding(String charset)The default behavior of this method is to call setCharacterEncoding(String charset) on the wrapped response object.voidsetContentLength(int len)The default behavior of this method is to call setContentLength(int len) on the wrapped response object.voidsetContentLengthLong(long len)The default behavior of this method is to call setContentLengthLong(long len) on the wrapped response object.voidsetContentType(String type)The default behavior of this method is to call setContentType(String type) on the wrapped response object.voidsetLocale(Locale loc)The default behavior of this method is to call setLocale(Locale loc) on the wrapped response object.voidsetResponse(ServletResponse response)Sets the response being wrapped.
-
-
-
Constructor Detail
-
ServletResponseWrapper
public ServletResponseWrapper(ServletResponse response)
Creates a ServletResponse adaptor wrapping the given response object.- Parameters:
response- theServletResponseto be wrapped- Throws:
IllegalArgumentException- if the response is null.
-
-
Method Detail
-
getResponse
public ServletResponse getResponse()
Return the wrapped ServletResponse object.- Returns:
- the wrapped
ServletResponse
-
setResponse
public void setResponse(ServletResponse response)
Sets the response being wrapped.- Parameters:
response- theServletResponseto be installed- Throws:
IllegalArgumentException- if the response is null.
-
setCharacterEncoding
public void setCharacterEncoding(String charset)
The default behavior of this method is to call setCharacterEncoding(String charset) on the wrapped response object.- Specified by:
setCharacterEncodingin interfaceServletResponse- Parameters:
charset- 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:
ServletResponse.setContentType(java.lang.String),ServletResponse.setLocale(java.util.Locale)
-
getCharacterEncoding
public String getCharacterEncoding()
The default behavior of this method is to return getCharacterEncoding() on the wrapped response object.- Specified by:
getCharacterEncodingin interfaceServletResponse- Returns:
- a
Stringspecifying the name of the character encoding, for example,UTF-8
-
getOutputStream
public ServletOutputStream getOutputStream() throws IOException
The default behavior of this method is to return getOutputStream() on the wrapped response object.- Specified by:
getOutputStreamin interfaceServletResponse- Returns:
- a
ServletOutputStreamfor writing binary data - Throws:
IOException- if an input or output exception occurred- See Also:
ServletResponse.getWriter(),ServletResponse.reset()
-
getWriter
public PrintWriter getWriter() throws IOException
The default behavior of this method is to return getWriter() on the wrapped response object.- Specified by:
getWriterin interfaceServletResponse- Returns:
- a
PrintWriterobject that can return character data to the client - Throws:
UnsupportedEncodingException- if the character encoding returned bygetCharacterEncodingcannot be usedIOException- if an input or output exception occurred- See Also:
ServletResponse.getOutputStream(),ServletResponse.setCharacterEncoding(java.lang.String),ServletResponse.reset()
-
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:
setContentLengthin 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:
setContentLengthLongin 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
public void setContentType(String type)
The default behavior of this method is to call setContentType(String type) on the wrapped response object.- Specified by:
setContentTypein interfaceServletResponse- Parameters:
type- aStringspecifying the MIME type of the content ornull- See Also:
ServletResponse.setLocale(java.util.Locale),ServletResponse.setCharacterEncoding(java.lang.String),ServletResponse.getOutputStream(),ServletResponse.getWriter()
-
getContentType
public String getContentType()
The default behavior of this method is to return getContentType() on the wrapped response object.- Specified by:
getContentTypein interfaceServletResponse- Returns:
- a
Stringspecifying 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:
setBufferSizein interfaceServletResponse- Parameters:
size- the preferred buffer size- See Also:
ServletResponse.getBufferSize(),ServletResponse.flushBuffer(),ServletResponse.isCommitted(),ServletResponse.reset()
-
getBufferSize
public int getBufferSize()
The default behavior of this method is to return getBufferSize() on the wrapped response object.- Specified by:
getBufferSizein interfaceServletResponse- Returns:
- the actual buffer size used
- See Also:
ServletResponse.setBufferSize(int),ServletResponse.flushBuffer(),ServletResponse.isCommitted(),ServletResponse.reset()
-
flushBuffer
public void flushBuffer() throws IOExceptionThe default behavior of this method is to call flushBuffer() on the wrapped response object.- Specified by:
flushBufferin interfaceServletResponse- Throws:
IOException- if the act of flushing the buffer cannot be completed.- See Also:
ServletResponse.setBufferSize(int),ServletResponse.getBufferSize(),ServletResponse.isCommitted(),ServletResponse.reset()
-
isCommitted
public boolean isCommitted()
The default behavior of this method is to return isCommitted() on the wrapped response object.- Specified by:
isCommittedin interfaceServletResponse- Returns:
- a boolean indicating if the response has been committed
- See Also:
ServletResponse.setBufferSize(int),ServletResponse.getBufferSize(),ServletResponse.flushBuffer(),ServletResponse.reset()
-
reset
public void reset()
The default behavior of this method is to call reset() on the wrapped response object.- Specified by:
resetin interfaceServletResponse- See Also:
ServletResponse.setBufferSize(int),ServletResponse.getBufferSize(),ServletResponse.flushBuffer(),ServletResponse.isCommitted()
-
resetBuffer
public void resetBuffer()
The default behavior of this method is to call resetBuffer() on the wrapped response object.- Specified by:
resetBufferin interfaceServletResponse- See Also:
ServletResponse.setBufferSize(int),ServletResponse.getBufferSize(),ServletResponse.isCommitted(),ServletResponse.reset()
-
setLocale
public void setLocale(Locale loc)
The default behavior of this method is to call setLocale(Locale loc) on the wrapped response object.- Specified by:
setLocalein interfaceServletResponse- Parameters:
loc- the locale of the response or {code @null}- See Also:
ServletResponse.getLocale(),ServletResponse.setContentType(java.lang.String),ServletResponse.setCharacterEncoding(java.lang.String)
-
getLocale
public Locale getLocale()
The default behavior of this method is to return getLocale() on the wrapped response object.- Specified by:
getLocalein interfaceServletResponse- Returns:
- the Locale for this response.
- See Also:
ServletResponse.setLocale(java.util.Locale)
-
isWrapperFor
public boolean isWrapperFor(ServletResponse wrapped)
Checks (recursively) if this ServletResponseWrapper wraps the givenServletResponseinstance.- 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
public boolean isWrapperFor(Class<?> wrappedType)
Checks (recursively) if this ServletResponseWrapper wraps aServletResponseof 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
-
-