org.clazzes.util.http
public abstract class CompressionHelper extends Object
Content-Coding
header field.Modifier and Type | Field and Description |
---|---|
static String[] |
DEFAULT_SUPPORTED_ENCODINGS
A default set of supported encodings.
|
Constructor and Description |
---|
CompressionHelper() |
Modifier and Type | Method and Description |
---|---|
static void |
finishOutputStream(OutputStream os)
Finish writing to a possibly compressed servlet output stream.
|
static boolean |
isCompressed(OutputStream os) |
static String |
selectCompressionCoding(String acceptEncoding,
String[] supportedEncodings) |
static void |
sendError(javax.servlet.http.HttpServletResponse resp,
OutputStream os,
int status,
String message)
Write an error response to the servlet output stream.
|
static void |
sendError(javax.servlet.http.HttpServletResponse resp,
OutputStream os,
int status,
String message,
Throwable e)
Write an error response to the servlet output stream.
|
static OutputStream |
setupResponseOutputStream(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
Parse the
Accept-Encoding header of the request and set up a possibly compressed
output stream to write to. |
public static final String[] DEFAULT_SUPPORTED_ENCODINGS
public static String selectCompressionCoding(String acceptEncoding, String[] supportedEncodings)
acceptEncoding
- The content of an Accept-Encoding header (see section 14.3 of RFC2616).supportedEncodings
- A list of supported encodings to choose from. This list should
not contain the identity
encoding, because
noop compression is selected through a null
encoding value.null
, if the response
should not be compressed.public static OutputStream setupResponseOutputStream(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws IOException
Accept-Encoding
header of the request and set up a possibly compressed
output stream to write to. If the output is chosen to be compressed, an appropriate
Content-Encoding
is set on the passed HTTP response.req
- The HTTP request to examine.resp
- The HTTP response.Accept-Encoding
header of the client. The returned stream should be finished
after writing the whole response using finishOutputStream(OutputStream)
.IOException
- Upon errors when setting response headers or setting up streams.public static boolean isCompressed(OutputStream os)
os
- An output stream previously set up using
setupResponseOutputStream(HttpServletRequest, HttpServletResponse)
.public static void finishOutputStream(OutputStream os) throws IOException
os
- An OutputStream returned by setupResponseOutputStream(HttpServletRequest, HttpServletResponse)
.IOException
- Upon I/O errors.public static void sendError(javax.servlet.http.HttpServletResponse resp, OutputStream os, int status, String message) throws IOException
setupResponseOutputStream(HttpServletRequest, HttpServletResponse)
has been invoked before.resp
- The servlet response.os
- An output stream previously set up using
setupResponseOutputStream(HttpServletRequest, HttpServletResponse)
.status
- A HTTP status, which corresponds to the given error situation.message
- An optional error message.IOException
- Upon errors writing the response to the stream.public static void sendError(javax.servlet.http.HttpServletResponse resp, OutputStream os, int status, String message, Throwable e) throws IOException
setupResponseOutputStream(HttpServletRequest, HttpServletResponse)
has been invoked before.resp
- The servlet response.os
- An output stream previously set up using
setupResponseOutputStream(HttpServletRequest, HttpServletResponse)
.status
- A HTTP status, which corresponds to the given error situation.message
- An optional error message.e
- An optional exception to render.IOException
- Upon errors writing the response to the stream.Copyright © 2013 Clazzes.org. All Rights Reserved.