changeset 17:5cb8513b9e78

Improved the stream handling. http-client/trunk@1947 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 19 May 2011 09:01:35 +0000
parents 337eddebc88a
children 3dec58aa15ac 5e7a8bbdc39a
files ChangeLog src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java
diffstat 2 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed May 18 09:19:47 2011 +0000
+++ b/ChangeLog	Thu May 19 09:01:35 2011 +0000
@@ -1,3 +1,8 @@
+2011-05-19  Sascha L. Teichmann  <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java:
+	  Improved the stream handling.
+
 2011-05-18  Sascha L. Teichmann  <sascha.teichmann@intevation.de>
 
 	* pom.xml: Bumped restlet version to 2.0.7
--- a/src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java	Wed May 18 09:19:47 2011 +0000
+++ b/src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java	Thu May 19 09:01:35 2011 +0000
@@ -213,11 +213,15 @@
             ResponseHandler handler = new StreamResponseHandler();
 
             InputStream stream = (InputStream) handler.handle(doPost(url, doc));
-
-            byte[] b = new byte[4096];
-            int i = -1;
-            while ((i = stream.read(b)) > 0) {
-                out.write(b, 0, i);
+            try {
+                byte[] b = new byte[4096];
+                int i;
+                while ((i = stream.read(b)) >= 0) {
+                    out.write(b, 0, i);
+                }
+            }
+            finally {
+                stream.close();
             }
         }
         catch (IOException ioe) {
@@ -399,9 +403,14 @@
             InputStream stream = collectionOut(doc, uuid, type);
 
             byte[] b = new byte[4096];
-            int i = -1;
-            while ((i = stream.read(b)) > 0) {
-                out.write(b, 0, i);
+            try {
+                int i;
+                while ((i = stream.read(b)) >= 0) {
+                    out.write(b, 0, i);
+                }
+            }
+            finally {
+                stream.close();
             }
         }
         catch (IOException ioe) {

http://dive4elements.wald.intevation.org