public class BufferResponseWrapper
extends javax.servlet.http.HttpServletResponseWrapper
Modifier and Type | Field and Description |
---|---|
protected Buffer |
buffer |
protected static java.lang.String |
CONTENT_LENGTH |
protected static java.lang.String |
CONTENT_TYPE |
protected ContentTypeHeaderResolver |
contentTypeResolver |
protected static java.lang.String |
LAST_MODIFIED |
protected LastModifiedData |
lastModifiedData |
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_FOUND, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
Constructor and Description |
---|
BufferResponseWrapper(javax.servlet.http.HttpServletResponse originalResponse) |
BufferResponseWrapper(javax.servlet.http.HttpServletResponse originalResponse,
LastModifiedData lastModifiedData) |
Modifier and Type | Method and Description |
---|---|
void |
addDateHeader(java.lang.String name,
long value) |
void |
addHeader(java.lang.String name,
java.lang.String value)
Prevents setting content-length if buffering enabled.
|
void |
addIntHeader(java.lang.String name,
int value)
Prevents setting content-length if buffering enabled.
|
protected boolean |
bufferContentType(java.lang.String contentType,
java.lang.String mimeType,
java.lang.String encoding)
Determines if some content type has to be buffered.
|
protected boolean |
bufferStatusCode(int statusCode)
Determines if buffering should be used for some HTTP status code.
|
void |
commitResponse()
Commits a response if not already committed.
|
protected void |
disableBuffering()
Disables buffering by transferring the output to original destinations.
|
protected void |
enableBuffering()
Enables buffering by transferring the output to the buffer.
|
void |
flushBuffer()
Prevents flushing buffer if buffering enabled.
|
byte[] |
getBufferContentAsBytes()
Returns buffered content as bytes, no matter if stream or writer is used.
|
char[] |
getBufferContentAsChars()
Returns buffered content as chars, no matter if stream or writer is used.
|
byte[] |
getBufferedBytes()
Returns buffered bytes or
null if buffering was not enabled. |
char[] |
getBufferedChars()
Returns buffered content or
null if buffering was not enabled. |
java.lang.String |
getContentMimeType()
Returns content mime type or
null . |
java.lang.String |
getContentTypeEncoding()
Returns content encoding or
null . |
LastModifiedData |
getLastModifiedData()
Returns last modified data.
|
javax.servlet.ServletOutputStream |
getOutputStream()
Returns buffered output stream if buffering is enabled,
otherwise returns the original stream.
|
java.io.PrintWriter |
getWriter()
Returns buffered writer if buffering is enabled,
otherwise returns the original writer.
|
boolean |
isBufferingEnabled()
Returns
true if buffering is enabled. |
boolean |
isBufferStreamBased()
Returns
true if underlying buffer was written to
using getOutputStream() (as opposed to getWriter() . |
protected void |
preResponseCommit()
Called just before stream or writer is accessed.
|
void |
print(java.lang.String string)
Appends string to the buffer.
|
void |
sendError(int statusCode) |
void |
sendError(int statusCode,
java.lang.String reason) |
void |
sendRedirect(java.lang.String location) |
void |
setContentLength(int contentLength)
Prevents content-length being set if buffering enabled.
|
void |
setContentType(java.lang.String type)
Sets the content type and enables or disables buffering.
|
void |
setDateHeader(java.lang.String name,
long value) |
void |
setHeader(java.lang.String name,
java.lang.String value)
Prevents setting content-length if buffering enabled.
|
void |
setIntHeader(java.lang.String name,
int value)
Prevents setting content-length if buffering enabled.
|
void |
setStatus(int statusCode) |
void |
setStatus(int statusCode,
java.lang.String reason) |
protected void |
stopBufferingForStatusCode(int statusCode) |
void |
writeContentToResponse()
Writes (unmodified) buffered content, using either output stream or writer.
|
void |
writeContentToResponse(char[] content)
Writes content to original output stream, using either output stream or writer, depending
on how the content was buffered.
|
addCookie, containsHeader, encodeRedirectUrl, encodeRedirectURL, encodeUrl, encodeURL, getHeader, getHeaderNames, getHeaders, getStatus
getBufferSize, getCharacterEncoding, getContentType, getLocale, getResponse, isCommitted, isWrapperFor, isWrapperFor, reset, resetBuffer, setBufferSize, setCharacterEncoding, setContentLengthLong, setLocale, setResponse
protected static final java.lang.String CONTENT_TYPE
protected static final java.lang.String CONTENT_LENGTH
protected static final java.lang.String LAST_MODIFIED
protected final LastModifiedData lastModifiedData
protected Buffer buffer
protected ContentTypeHeaderResolver contentTypeResolver
public BufferResponseWrapper(javax.servlet.http.HttpServletResponse originalResponse)
public BufferResponseWrapper(javax.servlet.http.HttpServletResponse originalResponse, LastModifiedData lastModifiedData)
protected void preResponseCommit()
public void commitResponse()
preResponseCommit()
if response is going to
be committed.protected void enableBuffering()
protected void disableBuffering()
public boolean isBufferingEnabled()
true
if buffering is enabled.public boolean isBufferStreamBased()
true
if underlying buffer was written to
using getOutputStream()
(as opposed to getWriter()
.
If buffering was not enabled at all, false
will be returned,
therefore an additional check
is required.public java.io.PrintWriter getWriter() throws java.io.IOException
getWriter
in interface javax.servlet.ServletResponse
getWriter
in class javax.servlet.ServletResponseWrapper
java.io.IOException
public javax.servlet.ServletOutputStream getOutputStream() throws java.io.IOException
getOutputStream
in interface javax.servlet.ServletResponse
getOutputStream
in class javax.servlet.ServletResponseWrapper
java.io.IOException
public LastModifiedData getLastModifiedData()
public char[] getBufferedChars()
null
if buffering was not enabled.public byte[] getBufferedBytes()
null
if buffering was not enabled.public char[] getBufferContentAsChars()
null
if buffering was not enabled.public byte[] getBufferContentAsBytes()
null
if buffering was not enabled.public void writeContentToResponse(char[] content) throws java.io.IOException
java.io.IOException
public void writeContentToResponse() throws java.io.IOException
modify
buffered data by altering the buffer content.java.io.IOException
public java.lang.String getContentTypeEncoding()
null
.public java.lang.String getContentMimeType()
null
.protected boolean bufferContentType(java.lang.String contentType, java.lang.String mimeType, java.lang.String encoding)
true
.contentType
- full content-type, e.g. "text/html; charset=utf-8"mimeType
- extracted mime-type, e.g. "text/html"encoding
- extracted encoding, e.g. "utf-8" (may be null
)public void setContentType(java.lang.String type)
setContentType
in interface javax.servlet.ServletResponse
setContentType
in class javax.servlet.ServletResponseWrapper
public void flushBuffer() throws java.io.IOException
flushBuffer
in interface javax.servlet.ServletResponse
flushBuffer
in class javax.servlet.ServletResponseWrapper
java.io.IOException
public void setContentLength(int contentLength)
setContentLength
in interface javax.servlet.ServletResponse
setContentLength
in class javax.servlet.ServletResponseWrapper
public void setHeader(java.lang.String name, java.lang.String value)
setHeader
in interface javax.servlet.http.HttpServletResponse
setHeader
in class javax.servlet.http.HttpServletResponseWrapper
public void addHeader(java.lang.String name, java.lang.String value)
addHeader
in interface javax.servlet.http.HttpServletResponse
addHeader
in class javax.servlet.http.HttpServletResponseWrapper
public void setIntHeader(java.lang.String name, int value)
setIntHeader
in interface javax.servlet.http.HttpServletResponse
setIntHeader
in class javax.servlet.http.HttpServletResponseWrapper
public void addIntHeader(java.lang.String name, int value)
addIntHeader
in interface javax.servlet.http.HttpServletResponse
addIntHeader
in class javax.servlet.http.HttpServletResponseWrapper
public void setDateHeader(java.lang.String name, long value)
setDateHeader
in interface javax.servlet.http.HttpServletResponse
setDateHeader
in class javax.servlet.http.HttpServletResponseWrapper
public void addDateHeader(java.lang.String name, long value)
addDateHeader
in interface javax.servlet.http.HttpServletResponse
addDateHeader
in class javax.servlet.http.HttpServletResponseWrapper
public void setStatus(int statusCode)
setStatus
in interface javax.servlet.http.HttpServletResponse
setStatus
in class javax.servlet.http.HttpServletResponseWrapper
public void setStatus(int statusCode, java.lang.String reason)
setStatus
in interface javax.servlet.http.HttpServletResponse
setStatus
in class javax.servlet.http.HttpServletResponseWrapper
public void sendError(int statusCode) throws java.io.IOException
sendError
in interface javax.servlet.http.HttpServletResponse
sendError
in class javax.servlet.http.HttpServletResponseWrapper
java.io.IOException
public void sendError(int statusCode, java.lang.String reason) throws java.io.IOException
sendError
in interface javax.servlet.http.HttpServletResponse
sendError
in class javax.servlet.http.HttpServletResponseWrapper
java.io.IOException
public void sendRedirect(java.lang.String location) throws java.io.IOException
sendRedirect
in interface javax.servlet.http.HttpServletResponse
sendRedirect
in class javax.servlet.http.HttpServletResponseWrapper
java.io.IOException
protected void stopBufferingForStatusCode(int statusCode)
protected boolean bufferStatusCode(int statusCode)
true
only for status code 200.public void print(java.lang.String string) throws java.io.IOException
java.io.IOException
Copyright © 2003-present Jodd Team