You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Gary Gregory <ga...@gmail.com> on 2017/05/08 01:31:21 UTC
org.apache.hc.client5.http.entity.GzipDecompressingEntity refactoring
(less garbage)
Hi all,
How about making DecompressingEntity implementations reuse their same
factories since they are stateless?
Like this:
Index:
src/main/java/org/apache/hc/client5/http/entity/GzipDecompressingEntity.java
===================================================================
---
src/main/java/org/apache/hc/client5/http/entity/GzipDecompressingEntity.java
(revision
1794275)
+++
src/main/java/org/apache/hc/client5/http/entity/GzipDecompressingEntity.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
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: org.apache.hc.client5.http.entity.GzipDecompressingEntity
refactoring (less garbage)
Posted by Gary Gregory <ga...@gmail.com>.
Thoughts for or against porting this to 4.4.x?
Gary
On Mon, May 8, 2017 at 9:27 AM, Gary Gregory <ga...@gmail.com> wrote:
> I'm going to take this patch a little further since I found more than one
> place that does a "new InputStreamFactory() {...}". I am creating a
> GZIPInputStreamFactory class and DeflateInputStreamFactory class which will
> have singletons. That's what will be reused. That should make things
> clearer and neater esp. looking ahead to the httpclient5-compress module.
>
> Gary
>
> Gary
>
> On Mon, May 8, 2017 at 12:09 AM, Oleg Kalnichevski <ol...@apache.org>
> wrote:
>
>> 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: dev-unsubscribe@hc.apache.org
>> For additional commands, e-mail: dev-help@hc.apache.org
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
> JUnit in Action, Second Edition
> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
> Spring Batch in Action
> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: org.apache.hc.client5.http.entity.GzipDecompressingEntity
refactoring (less garbage)
Posted by Gary Gregory <ga...@gmail.com>.
I'm going to take this patch a little further since I found more than one
place that does a "new InputStreamFactory() {...}". I am creating a
GZIPInputStreamFactory class and DeflateInputStreamFactory class which will
have singletons. That's what will be reused. That should make things
clearer and neater esp. looking ahead to the httpclient5-compress module.
Gary
Gary
On Mon, May 8, 2017 at 12:09 AM, Oleg Kalnichevski <ol...@apache.org> wrote:
> 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: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: org.apache.hc.client5.http.entity.GzipDecompressingEntity
refactoring (less garbage)
Posted by Oleg Kalnichevski <ol...@apache.org>.
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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org