Mercurial > dive4elements > http-client
diff src/main/java/de/intevation/artifacts/httpclient/http/HttpClientImpl.java @ 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 | 5b62267a1c3c |
children | 79a5a2455d6d |
line wrap: on
line diff
--- 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) {