hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1096489 - in /httpcomponents/httpcore/trunk: RELEASE_NOTES.txt httpcore/src/main/java/org/apache/http/entity/InputStreamEntity.java
Date Mon, 25 Apr 2011 14:23:57 GMT
Author: olegk
Date: Mon Apr 25 14:23:57 2011
New Revision: 1096489

URL: http://svn.apache.org/viewvc?rev=1096489&view=rev
Log:
HTTPCORE-255: Fixed resource management in InputStreamEntity#writeTo method

Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/InputStreamEntity.java

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=1096489&r1=1096488&r2=1096489&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Mon Apr 25 14:23:57 2011
@@ -1,5 +1,8 @@
 Changes since 4.1
 
+* [HTTPCORE-255]: Fixed resource management in InputStreamEntity#writeTo()
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCORE-254]: Erratic results from metrics (sebb)
 
 * [HTTPCORE-242]: Fixed NPE in AsyncNHttpClientHandler caused by an early response to an

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/InputStreamEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/InputStreamEntity.java?rev=1096489&r1=1096488&r2=1096489&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/InputStreamEntity.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/InputStreamEntity.java
Mon Apr 25 14:23:57 2011
@@ -70,24 +70,28 @@ public class InputStreamEntity extends A
             throw new IllegalArgumentException("Output stream may not be null");
         }
         InputStream instream = this.content;
-        byte[] buffer = new byte[BUFFER_SIZE];
-        int l;
-        if (this.length < 0) {
-            // consume until EOF
-            while ((l = instream.read(buffer)) != -1) {
-                outstream.write(buffer, 0, l);
-            }
-        } else {
-            // consume no more than length
-            long remaining = this.length;
-            while (remaining > 0) {
-                l = instream.read(buffer, 0, (int)Math.min(BUFFER_SIZE, remaining));
-                if (l == -1) {
-                    break;
+        try {
+            byte[] buffer = new byte[BUFFER_SIZE];
+            int l;
+            if (this.length < 0) {
+                // consume until EOF
+                while ((l = instream.read(buffer)) != -1) {
+                    outstream.write(buffer, 0, l);
+                }
+            } else {
+                // consume no more than length
+                long remaining = this.length;
+                while (remaining > 0) {
+                    l = instream.read(buffer, 0, (int)Math.min(BUFFER_SIZE, remaining));
+                    if (l == -1) {
+                        break;
+                    }
+                    outstream.write(buffer, 0, l);
+                    remaining -= l;
                 }
-                outstream.write(buffer, 0, l);
-                remaining -= l;
             }
+        } finally {
+            instream.close();
         }
     }
 



Mime
View raw message