HTTPCLIENT-2206: Corrected resource de-allocation by fluent response objects
This commit is contained in:
parent
c4e480ef78
commit
73e72f2268
|
@ -26,6 +26,7 @@
|
|||
*/
|
||||
package org.apache.http.client.fluent;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -116,6 +117,7 @@ public class Response {
|
|||
|
||||
public void saveContent(final File file) throws IOException {
|
||||
assertNotConsumed();
|
||||
try {
|
||||
final StatusLine statusLine = response.getStatusLine();
|
||||
if (statusLine.getStatusCode() >= 300) {
|
||||
throw new HttpResponseException(statusLine.getStatusCode(),
|
||||
|
@ -128,9 +130,14 @@ public class Response {
|
|||
entity.writeTo(out);
|
||||
}
|
||||
} finally {
|
||||
this.consumed = true;
|
||||
out.close();
|
||||
}
|
||||
} finally {
|
||||
this.consumed = true;
|
||||
if (this.response instanceof Closeable) {
|
||||
((Closeable) this.response).close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue