mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
revert back to use EntityUtils.consumeQuietly - as it simply closes the
underlying stream
This commit is contained in:
parent
4f0392e93e
commit
4fc876f4a3
|
@ -827,50 +827,14 @@ public class HTTPClient {
|
|||
public void finish() throws IOException {
|
||||
try {
|
||||
if (this.httpResponse != null) {
|
||||
final HttpEntity httpEntity = this.httpResponse.getEntity();
|
||||
if (httpEntity != null && httpEntity.isStreaming()) {
|
||||
/*
|
||||
* Try to fully consume the eventual remaining of the
|
||||
* content stream : if too long abort the request. Not using
|
||||
* EntityUtils.consumeQuietly(httpEntity) because too long
|
||||
* to perform on large resources when calling this before
|
||||
* full stream processing end : for example on caller
|
||||
* exception handling .
|
||||
*/
|
||||
InputStream contentStream = null;
|
||||
try {
|
||||
contentStream = httpEntity.getContent();
|
||||
if (contentStream != null) {
|
||||
byte[] buffer = new byte[2048];
|
||||
int count = 0;
|
||||
int readNb = contentStream.read(buffer);
|
||||
while (readNb >= 0 && count < 10) {
|
||||
readNb = contentStream.read(buffer);
|
||||
count++;
|
||||
}
|
||||
if (readNb >= 0) {
|
||||
if (this.currentRequest != null) {
|
||||
this.currentRequest.abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(IOException e){
|
||||
/* Silently ignore here IOException (for example caused by stream already closed) as in EntityUtils.consumeQuietly() */
|
||||
} finally {
|
||||
if (contentStream != null) {
|
||||
try {
|
||||
contentStream.close();
|
||||
} catch(IOException ignored) {}
|
||||
}
|
||||
this.httpResponse.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Ensures that the entity content Stream is closed.
|
||||
EntityUtils.consumeQuietly(this.httpResponse.getEntity());
|
||||
this.httpResponse.close();
|
||||
}
|
||||
} finally {
|
||||
if (this.currentRequest != null) {
|
||||
ConnectionInfo.removeConnection(this.currentRequest.hashCode());
|
||||
this.currentRequest.abort();
|
||||
this.currentRequest = null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user