# HG changeset patch # User Sascha L. Teichmann # Date 1305795695 0 # Node ID 5cb8513b9e78b06fddad35167c226504e8ac8340 # Parent 337eddebc88ae008efc70857d194a11785ddc53c Improved the stream handling. http-client/trunk@1947 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 337eddebc88a -r 5cb8513b9e78 ChangeLog --- 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 + + * src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java: + Improved the stream handling. + 2011-05-18 Sascha L. Teichmann * pom.xml: Bumped restlet version to 2.0.7 diff -r 337eddebc88a -r 5cb8513b9e78 src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java --- 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) {