hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1469230 - in /httpcomponents/httpclient/branches/4.2.x: RELEASE_NOTES.txt httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java
Date Thu, 18 Apr 2013 09:07:58 GMT
Author: olegk
Date: Thu Apr 18 09:07:57 2013
New Revision: 1469230

URL: http://svn.apache.org/r1469230
Log:
HTTPCLIENT-1341] DeflateDecompressingEntity does not call Inflater#end

Modified:
    httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java

Modified: httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt?rev=1469230&r1=1469229&r2=1469230&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt Thu Apr 18 09:07:57 2013
@@ -1,6 +1,9 @@
 Changes since Release 4.2.4
 -------------------
 
+* [HTTPCLIENT-1341] DeflateDecompressingEntity does not call Inflater#end.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-1299] (regression) cache incorrectly disposes of the underlying cache resource

   when storing variant entry.
   Contributed by James Leigh <james at 3roundstones.com> 

Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java?rev=1469230&r1=1469229&r2=1469230&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java
Thu Apr 18 09:07:57 2013
@@ -1,20 +1,21 @@
 /*
  * ====================================================================
- *
- *  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.
+ * 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
@@ -22,7 +23,7 @@
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  *
-*/
+ */
 package org.apache.http.client.entity;
 
 import java.io.IOException;
@@ -97,20 +98,20 @@ public class DeflateDecompressingEntity 
          */
 
         /* We read a small buffer to sniff the content. */
-        byte[] peeked = new byte[6];
+        final byte[] peeked = new byte[6];
 
-        PushbackInputStream pushback = new PushbackInputStream(wrapped, peeked.length);
+        final PushbackInputStream pushback = new PushbackInputStream(wrapped, peeked.length);
 
-        int headerLength = pushback.read(peeked);
+        final int headerLength = pushback.read(peeked);
 
         if (headerLength == -1) {
             throw new IOException("Unable to read the response");
         }
 
         /* We try to read the first uncompressed byte. */
-        byte[] dummy = new byte[1];
+        final byte[] dummy = new byte[1];
 
-        Inflater inf = new Inflater();
+        final Inflater inf = new Inflater();
 
         try {
             int n;
@@ -141,13 +142,15 @@ public class DeflateDecompressingEntity 
              * and return an unused InputStream now.
              */
             pushback.unread(peeked, 0, headerLength);
-            return new InflaterInputStream(pushback);
-        } catch (DataFormatException e) {
+            return new DeflateStream(pushback, new Inflater());
+        } catch (final DataFormatException e) {
 
             /* Presume that it's an RFC1951 deflate stream rather than RFC1950 zlib stream
and try
              * again. */
             pushback.unread(peeked, 0, headerLength);
-            return new InflaterInputStream(pushback, new Inflater(true));
+            return new DeflateStream(pushback, new Inflater(true));
+        } finally {
+            inf.end();
         }
     }
 
@@ -171,4 +174,24 @@ public class DeflateDecompressingEntity 
         return -1;
     }
 
+    static class DeflateStream extends InflaterInputStream {
+
+        private boolean closed = false;
+
+        public DeflateStream(final InputStream in, final Inflater inflater) {
+            super(in, inflater);
+        }
+
+        @Override
+        public void close() throws IOException {
+            if (closed) {
+                return;
+            }
+            closed = true;
+            inf.end();
+            super.close();
+        }
+
+    }
+
 }



Mime
View raw message