/** Checks if the {@link File} with the given content-type could be compressed. */
  private boolean canBeCompressed(final File cacheFile, final String contentType) {
    switch (compressionConfig.getCompressionMode()) {
      case FORCE:
        return true;
      case OFF:
        return false;
      case ON:
        {
          if (cacheFile.length() < compressionConfig.getCompressionMinSize()) {
            return false;
          }

          return compressionConfig.checkMimeType(contentType);
        }

      default:
        throw new IllegalStateException("Unknown mode");
    }
  }
Beispiel #2
0
  protected Set<ContentEncoding> configureCompressionEncodings(final NetworkListener listener) {

    final CompressionConfig compressionConfig = listener.getCompressionConfig();

    if (compressionConfig.getCompressionMode() != CompressionMode.OFF) {
      final ContentEncoding gzipContentEncoding =
          new GZipContentEncoding(
              GZipContentEncoding.DEFAULT_IN_BUFFER_SIZE,
              GZipContentEncoding.DEFAULT_OUT_BUFFER_SIZE,
              new CompressionEncodingFilter(
                  compressionConfig, GZipContentEncoding.getGzipAliases()));
      final ContentEncoding lzmaEncoding =
          new LZMAContentEncoding(
              new CompressionEncodingFilter(
                  compressionConfig, LZMAContentEncoding.getLzmaAliases()));
      final Set<ContentEncoding> set = new HashSet<ContentEncoding>(2);
      set.add(gzipContentEncoding);
      set.add(lzmaEncoding);
      return set;
    } else {
      return Collections.emptySet();
    }
  }