org.clazzes.util.http
Class CompressionHelper
java.lang.Object
org.clazzes.util.http.CompressionHelper
public abstract class CompressionHelper
- extends Object
This class provides static functionality for handling compression algorithms
controlled through the Content-Coding
header field.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_SUPPORTED_ENCODINGS
public static final String[] DEFAULT_SUPPORTED_ENCODINGS
- A default set of supported encodings.
CompressionHelper
public CompressionHelper()
selectCompressionCoding
public static String selectCompressionCoding(String acceptEncoding,
String[] supportedEncodings)
- Parameters:
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.
- Returns:
- The encoding selected to use for the given browser of
null
, if the response
should not be compressed.
setupResponseOutputStream
public static OutputStream setupResponseOutputStream(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
throws IOException
- Parse the
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.
- Parameters:
req
- The HTTP request to examine.resp
- The HTTP response.
- Returns:
- A compressed or uncompressed stream based on the
Accept-Encoding
header of the client. The retuned stream should be finished
after writing the whole response using finishOutputStream(OutputStream)
.
- Throws:
IOException
- Upon errors when setting response headers or setting up streams.
isCompressed
public static boolean isCompressed(OutputStream os)
- Parameters:
os
- An output stream previously set up using
setupResponseOutputStream(HttpServletRequest, HttpServletResponse)
.
- Returns:
- Whether the output stream is compressed or not.
finishOutputStream
public static void finishOutputStream(OutputStream os)
throws IOException
- Finish writing to a possibly compressed servlet output stream.
- Parameters:
os
- An OutputStream returned by setupResponseOutputStream(HttpServletRequest, HttpServletResponse)
.
- Throws:
IOException
- Upon I/O errors.
Copyright © 2011. All Rights Reserved.