Search in sources :

Example 1 with CompressionLevel

use of org.glassfish.grizzly.http.server.CompressionLevel in project Payara by payara.

the class GenericGrizzlyListener method configureCompressionEncodings.

protected Set<ContentEncoding> configureCompressionEncodings(Http http) {
    final String mode = http.getCompression();
    int compressionMinSize = Integer.parseInt(http.getCompressionMinSizeBytes());
    CompressionLevel compressionLevel;
    try {
        compressionLevel = CompressionLevel.getCompressionLevel(mode);
    } catch (IllegalArgumentException e) {
        try {
            // Try to parse compression as an int, which would give the
            // minimum compression size
            compressionLevel = CompressionLevel.ON;
            compressionMinSize = Integer.parseInt(mode);
        } catch (Exception ignore) {
            compressionLevel = CompressionLevel.OFF;
        }
    }
    final String compressableMimeTypesString = http.getCompressableMimeType();
    final String noCompressionUserAgentsString = http.getNoCompressionUserAgents();
    final String[] compressableMimeTypes = ((compressableMimeTypesString != null) ? compressableMimeTypesString.split(",") : new String[0]);
    final String[] noCompressionUserAgents = ((noCompressionUserAgentsString != null) ? noCompressionUserAgentsString.split(",") : new String[0]);
    final ContentEncoding gzipContentEncoding = new GZipContentEncoding(GZipContentEncoding.DEFAULT_IN_BUFFER_SIZE, GZipContentEncoding.DEFAULT_OUT_BUFFER_SIZE, new CompressionEncodingFilter(compressionLevel, compressionMinSize, compressableMimeTypes, noCompressionUserAgents, GZipContentEncoding.getGzipAliases(), compressionLevel != CompressionLevel.OFF));
    final ContentEncoding lzmaEncoding = new LZMAContentEncoding(new CompressionEncodingFilter(compressionLevel, compressionMinSize, compressableMimeTypes, noCompressionUserAgents, LZMAContentEncoding.getLzmaAliases(), compressionLevel != CompressionLevel.OFF));
    final Set<ContentEncoding> set = new HashSet<ContentEncoding>(2);
    set.add(gzipContentEncoding);
    set.add(lzmaEncoding);
    return set;
}
Also used : CompressionEncodingFilter(org.glassfish.grizzly.http.server.CompressionEncodingFilter) CompressionLevel(org.glassfish.grizzly.http.server.CompressionLevel) GZipContentEncoding(org.glassfish.grizzly.http.GZipContentEncoding) LZMAContentEncoding(org.glassfish.grizzly.http.LZMAContentEncoding) ContentEncoding(org.glassfish.grizzly.http.ContentEncoding) GZipContentEncoding(org.glassfish.grizzly.http.GZipContentEncoding) LZMAContentEncoding(org.glassfish.grizzly.http.LZMAContentEncoding) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ContentEncoding (org.glassfish.grizzly.http.ContentEncoding)1 GZipContentEncoding (org.glassfish.grizzly.http.GZipContentEncoding)1 LZMAContentEncoding (org.glassfish.grizzly.http.LZMAContentEncoding)1 CompressionEncodingFilter (org.glassfish.grizzly.http.server.CompressionEncodingFilter)1 CompressionLevel (org.glassfish.grizzly.http.server.CompressionLevel)1