hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1794442 - in /httpcomponents/httpclient/branches/4.5.x: ./ httpclient/src/main/java/org/apache/http/client/entity/ httpclient/src/main/java/org/apache/http/client/protocol/
Date Mon, 08 May 2017 19:17:42 GMT
Author: ggregory
Date: Mon May  8 19:17:42 2017
New Revision: 1794442

URL: http://svn.apache.org/viewvc?rev=1794442&view=rev
Log:
[HTTPCLIENT-1845]: Extract InputStreamFactory classes out of GzipDecompressingEntity and 
DeflateDecompressingEntity for reuse and to create less garbage.

Added:
    httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateInputStreamFactory.java
    httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/GZIPInputStreamFactory.java
Modified:
    httpcomponents/httpclient/branches/4.5.x/RELEASE_NOTES.txt
    httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java
    httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/GzipDecompressingEntity.java
    httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java

Modified: httpcomponents/httpclient/branches/4.5.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/RELEASE_NOTES.txt?rev=1794442&r1=1794441&r2=1794442&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.5.x/RELEASE_NOTES.txt Mon May  8 19:17:42 2017
@@ -25,6 +25,10 @@ Changelog:
 
 * [HTTPCLIENT-1836] DefaultHostnameVerifier#getSubjectAltNames(X509Certificate) throws java.lang.ClassCastException.
   Contributed by Gary Gregory <ggregory at apache.org>, Ilian Iliev <ilian_iliev
at yahoo.com>
+  
+* [HTTPCLIENT-1845]: Extract InputStreamFactory classes out of GzipDecompressingEntity and

+  DeflateDecompressingEntity for reuse and to create less garbage.
+  Contributed by Gary Gregory <ggregory at apache.org>
 
 
 Release 4.5.3

Modified: httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java?rev=1794442&r1=1794441&r2=1794442&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java
(original)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java
Mon May  8 19:17:42 2017
@@ -26,9 +26,6 @@
  */
 package org.apache.http.client.entity;
 
-import java.io.IOException;
-import java.io.InputStream;
-
 import org.apache.http.HttpEntity;
 
 /**
@@ -57,14 +54,7 @@ public class DeflateDecompressingEntity
      *            a non-null {@link HttpEntity} to be wrapped
      */
     public DeflateDecompressingEntity(final HttpEntity entity) {
-        super(entity, new InputStreamFactory() {
-
-            @Override
-            public InputStream create(final InputStream instream) throws IOException {
-                return new DeflateInputStream(instream);
-            }
-
-        });
+        super(entity, DeflateInputStreamFactory.getInstance());
     }
 
 }

Added: httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateInputStreamFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateInputStreamFactory.java?rev=1794442&view=auto
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateInputStreamFactory.java
(added)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateInputStreamFactory.java
Mon May  8 19:17:42 2017
@@ -0,0 +1,63 @@
+/*
+ * ====================================================================
+ * 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.http.client.entity;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.http.annotation.Contract;
+import org.apache.http.annotation.ThreadingBehavior;
+
+/**
+ * {@link InputStreamFactory} for handling Deflate Content Coded responses.
+ *
+ * @since 4.5.4
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public class DeflateInputStreamFactory implements InputStreamFactory {
+
+    /**
+     * Singleton instance.
+     */
+    private static final DeflateInputStreamFactory INSTANCE = new DeflateInputStreamFactory();
+
+    /**
+     * Gets the singleton instance.
+     *
+     * @return the singleton instance.
+     */
+    public static DeflateInputStreamFactory getInstance() {
+        return INSTANCE;
+    }
+
+    @Override
+    public InputStream create(final InputStream inputStream) throws IOException {
+        return new DeflateInputStream(inputStream);
+    }
+
+}

Added: httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/GZIPInputStreamFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/GZIPInputStreamFactory.java?rev=1794442&view=auto
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/GZIPInputStreamFactory.java
(added)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/GZIPInputStreamFactory.java
Mon May  8 19:17:42 2017
@@ -0,0 +1,64 @@
+/*
+ * ====================================================================
+ * 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.http.client.entity;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.GZIPInputStream;
+
+import org.apache.http.annotation.Contract;
+import org.apache.http.annotation.ThreadingBehavior;
+
+/**
+ * {@link InputStreamFactory} for handling GZIPContent Coded responses.
+ *
+ * @since 4.5.4
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public class GZIPInputStreamFactory implements InputStreamFactory {
+
+    /**
+     * Singleton instance.
+     */
+    private static final GZIPInputStreamFactory INSTANCE = new GZIPInputStreamFactory();
+
+    /**
+     * Gets the singleton instance.
+     *
+     * @return the singleton instance.
+     */
+    public static GZIPInputStreamFactory getInstance() {
+        return INSTANCE;
+    }
+
+    @Override
+    public InputStream create(final InputStream inputStream) throws IOException {
+        return new GZIPInputStream(inputStream);
+    }
+
+}

Modified: httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/GzipDecompressingEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/GzipDecompressingEntity.java?rev=1794442&r1=1794441&r2=1794442&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/GzipDecompressingEntity.java
(original)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/entity/GzipDecompressingEntity.java
Mon May  8 19:17:42 2017
@@ -26,10 +26,6 @@
  */
 package org.apache.http.client.entity;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.GZIPInputStream;
-
 import org.apache.http.HttpEntity;
 
 /**
@@ -48,14 +44,7 @@ public class GzipDecompressingEntity ext
      *            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, GZIPInputStreamFactory.getInstance());
     }
 
 }

Modified: httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java?rev=1794442&r1=1794441&r2=1794442&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java
(original)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java
Mon May  8 19:17:42 2017
@@ -27,9 +27,7 @@
 package org.apache.http.client.protocol;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.Locale;
-import java.util.zip.GZIPInputStream;
 
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
@@ -41,7 +39,8 @@ import org.apache.http.annotation.Contra
 import org.apache.http.annotation.ThreadingBehavior;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.entity.DecompressingEntity;
-import org.apache.http.client.entity.DeflateInputStream;
+import org.apache.http.client.entity.DeflateInputStreamFactory;
+import org.apache.http.client.entity.GZIPInputStreamFactory;
 import org.apache.http.client.entity.InputStreamFactory;
 import org.apache.http.config.Lookup;
 import org.apache.http.config.RegistryBuilder;
@@ -61,23 +60,6 @@ public class ResponseContentEncoding imp
 
     public static final String UNCOMPRESSED = "http.client.response.uncompressed";
 
-    private final static InputStreamFactory GZIP = new InputStreamFactory() {
-
-        @Override
-        public InputStream create(final InputStream instream) throws IOException {
-            return new GZIPInputStream(instream);
-        }
-    };
-
-    private final static InputStreamFactory DEFLATE = new InputStreamFactory() {
-
-        @Override
-        public InputStream create(final InputStream instream) throws IOException {
-            return new DeflateInputStream(instream);
-        }
-
-    };
-
     private final Lookup<InputStreamFactory> decoderRegistry;
     private final boolean ignoreUnknown;
 
@@ -87,9 +69,9 @@ public class ResponseContentEncoding imp
     public ResponseContentEncoding(final Lookup<InputStreamFactory> decoderRegistry,
final boolean ignoreUnknown) {
         this.decoderRegistry = decoderRegistry != null ? decoderRegistry :
             RegistryBuilder.<InputStreamFactory>create()
-                    .register("gzip", GZIP)
-                    .register("x-gzip", GZIP)
-                    .register("deflate", DEFLATE)
+                    .register("gzip", GZIPInputStreamFactory.getInstance())
+                    .register("x-gzip", GZIPInputStreamFactory.getInstance())
+                    .register("deflate", DeflateInputStreamFactory.getInstance())
                     .build();
         this.ignoreUnknown = ignoreUnknown;
     }



Mime
View raw message