garydgregory commented on code in PR #580: URL: https://github.com/apache/httpcomponents-client/pull/580#discussion_r1768616169
########## httpclient5/src/main/java/org/apache/hc/client5/http/entity/CompressorFactory.java: ########## @@ -0,0 +1,294 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +package org.apache.hc.client5.http.entity; + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Collections; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; + +import org.apache.commons.compress.compressors.CompressorStreamFactory; +import org.apache.commons.compress.compressors.deflate.DeflateCompressorInputStream; +import org.apache.commons.compress.compressors.deflate.DeflateParameters; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.util.Args; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A factory class for managing compression and decompression of HTTP entities using different compression formats. + * <p> + * This factory uses a cache to optimize access to available input and output stream providers for compression formats. + * It also allows the use of aliases (e.g., "gzip" and "x-gzip") and automatically formats the compression names + * to ensure consistency. + * </p> + * + * <p> + * Supported compression formats include gzip, deflate, and other available formats provided by the + * {@link CompressorStreamFactory}. + * </p> + * + * <p> + * This class is thread-safe and uses {@link AtomicReference} to cache the available input and output stream providers. + * </p> + */ +public class CompressorFactory { + + private static final Logger LOG = LoggerFactory.getLogger(CompressorFactory.class); + /** + * Singleton instance of the factory. + */ + public static final CompressorFactory INSTANCE = new CompressorFactory(); + + private final CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory(); + private final AtomicReference<Set<String>> inputProvidersCache = new AtomicReference<>(); + private final AtomicReference<Set<String>> outputProvidersCache = new AtomicReference<>(); + private final Map<String, String> formattedNameCache = new ConcurrentHashMap<>(); + + private static final Map<String, String> COMPRESSION_ALIASES; + static { + final Map<String, String> aliases = new HashMap<>(); Review Comment: @arturobernalg Should I add an API to return `org.apache.commons.compress.compressors.CompressorStreamFactory.ALL_NAMES`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org