1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.http4;
18
19 import java.io.IOException;
20
21 import org.apache.commons.vfs2.util.MonitorInputStream;
22 import org.apache.http.HttpResponse;
23 import org.apache.http.client.methods.CloseableHttpResponse;
24
25
26
27
28 final class MonitoredHttpResponseContentInputStream extends MonitorInputStream {
29
30 private final HttpResponse httpResponse;
31
32 public MonitoredHttpResponseContentInputStream(final HttpResponse httpResponse) throws IOException {
33 super(httpResponse.getEntity().getContent());
34 this.httpResponse = httpResponse;
35 }
36
37 public MonitoredHttpResponseContentInputStream(final HttpResponse httpResponse, final int bufferSize) throws IOException {
38 super(httpResponse.getEntity().getContent(), bufferSize);
39 this.httpResponse = httpResponse;
40 }
41
42
43
44
45
46 @Override
47 protected void closeSuper() throws IOException {
48 if (!(httpResponse instanceof CloseableHttpResponse)) {
49 super.closeSuper();
50 }
51 }
52
53 @Override
54 protected void onClose() throws IOException {
55 if (httpResponse instanceof CloseableHttpResponse) {
56 ((CloseableHttpResponse) httpResponse).close();
57 }
58 }
59
60 }