On Sun, 2017-05-07 at 18:31 -0700, Gary Gregory wrote:
> Hi all,
>
> How about making DecompressingEntity implementations reuse their same
> factories since they are stateless?
>
+1
Oleg
> Like this:
>
> Index:
> src/main/java/org/apache/hc/client5/http/entity/GzipDecompressingEnti
> ty.java
> ===================================================================
> ---
> src/main/java/org/apache/hc/client5/http/entity/GzipDecompressingEnti
> ty.java
> (revision
> 1794275)
> +++
> src/main/java/org/apache/hc/client5/http/entity/GzipDecompressingEnti
> ty.java
> (working
> copy)
> @@ -33,29 +33,31 @@
> import org.apache.hc.core5.http.HttpEntity;
>
> /**
> - * {@link org.apache.hc.core5.http.io.entity.HttpEntityWrapper} for
> handling gzip
> - * Content Coded responses.
> + * {@link org.apache.hc.core5.http.io.entity.HttpEntityWrapper} for
> handling
> + * gzip Content Coded responses.
> *
> * @since 4.1
> */
> public class GzipDecompressingEntity extends DecompressingEntity {
>
> + private static final InputStreamFactory inputStreamFactory = new
> InputStreamFactory() {
> +
> + @Override
> + public InputStream create(final InputStream instream) throws
> IOException {
> + return new GZIPInputStream(instream);
> + }
> +
> + };
> +
> /**
> - * Creates a new {@link GzipDecompressingEntity} which will wrap
> the
> specified
> - * {@link HttpEntity}.
> + * Creates a new {@link GzipDecompressingEntity} which will wrap
> the
> + * specified {@link HttpEntity}.
> *
> * @param entity
> * the non-null {@link HttpEntity} to be wrapped
> */
> public GzipDecompressingEntity(final HttpEntity entity) {
> - super(entity, new InputStreamFactory() {
> -
> - @Override
> - public InputStream create(final InputStream instream)
> throws
> IOException {
> - return new GZIPInputStream(instream);
> - }
> -
> - });
> + super(entity, inputStreamFactory);
> }
>
> }
>
> and the same for other DecompressingEntity implementations.
>
> Gary
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]