Mercurial > dive4elements > http-client
comparison 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 |
comparison
equal
deleted
inserted
replaced
16:337eddebc88a | 17:5cb8513b9e78 |
---|---|
211 + "/" + target; | 211 + "/" + target; |
212 | 212 |
213 ResponseHandler handler = new StreamResponseHandler(); | 213 ResponseHandler handler = new StreamResponseHandler(); |
214 | 214 |
215 InputStream stream = (InputStream) handler.handle(doPost(url, doc)); | 215 InputStream stream = (InputStream) handler.handle(doPost(url, doc)); |
216 | 216 try { |
217 byte[] b = new byte[4096]; | 217 byte[] b = new byte[4096]; |
218 int i = -1; | 218 int i; |
219 while ((i = stream.read(b)) > 0) { | 219 while ((i = stream.read(b)) >= 0) { |
220 out.write(b, 0, i); | 220 out.write(b, 0, i); |
221 } | |
222 } | |
223 finally { | |
224 stream.close(); | |
221 } | 225 } |
222 } | 226 } |
223 catch (IOException ioe) { | 227 catch (IOException ioe) { |
224 throw new ConnectionException( | 228 throw new ConnectionException( |
225 "Connection to server failed: " + ioe.getMessage()); | 229 "Connection to server failed: " + ioe.getMessage()); |
397 { | 401 { |
398 try { | 402 try { |
399 InputStream stream = collectionOut(doc, uuid, type); | 403 InputStream stream = collectionOut(doc, uuid, type); |
400 | 404 |
401 byte[] b = new byte[4096]; | 405 byte[] b = new byte[4096]; |
402 int i = -1; | 406 try { |
403 while ((i = stream.read(b)) > 0) { | 407 int i; |
404 out.write(b, 0, i); | 408 while ((i = stream.read(b)) >= 0) { |
409 out.write(b, 0, i); | |
410 } | |
411 } | |
412 finally { | |
413 stream.close(); | |
405 } | 414 } |
406 } | 415 } |
407 catch (IOException ioe) { | 416 catch (IOException ioe) { |
408 throw new ConnectionException(ioe.getMessage(), ioe); | 417 throw new ConnectionException(ioe.getMessage(), ioe); |
409 } | 418 } |