store duration of fetching

This commit is contained in:
Athou
2013-04-19 09:37:07 +02:00
parent a4a7f6389c
commit 185c5de7af

View File

@@ -43,6 +43,7 @@ public class HttpGetter {
public HttpResult getBinary(String url, String lastModified, String eTag) public HttpResult getBinary(String url, String lastModified, String eTag)
throws ClientProtocolException, IOException, NotModifiedException { throws ClientProtocolException, IOException, NotModifiedException {
HttpResult result = null; HttpResult result = null;
long start = System.currentTimeMillis();
DefaultHttpClient httpclient = new DefaultHttpClient(); DefaultHttpClient httpclient = new DefaultHttpClient();
HttpParams params = httpclient.getParams(); HttpParams params = httpclient.getParams();
@@ -97,9 +98,10 @@ public class HttpGetter {
if (entity != null) { if (entity != null) {
content = EntityUtils.toByteArray(entity); content = EntityUtils.toByteArray(entity);
} }
long duration = System.currentTimeMillis() - start;
result = new HttpResult(content, lastModifiedHeader == null ? null result = new HttpResult(content, lastModifiedHeader == null ? null
: lastModifiedHeader.getValue(), eTagHeader == null ? null : lastModifiedHeader.getValue(), eTagHeader == null ? null
: eTagHeader.getValue()); : eTagHeader.getValue(), duration);
} finally { } finally {
httpclient.getConnectionManager().shutdown(); httpclient.getConnectionManager().shutdown();
} }
@@ -111,11 +113,14 @@ public class HttpGetter {
private byte[] content; private byte[] content;
private String lastModifiedSince; private String lastModifiedSince;
private String eTag; private String eTag;
private long duration;
public HttpResult(byte[] content, String lastModifiedSince, String eTag) { public HttpResult(byte[] content, String lastModifiedSince,
String eTag, long duration) {
this.content = content; this.content = content;
this.lastModifiedSince = lastModifiedSince; this.lastModifiedSince = lastModifiedSince;
this.eTag = eTag; this.eTag = eTag;
this.duration = duration;
} }
public byte[] getContent() { public byte[] getContent() {
@@ -130,6 +135,10 @@ public class HttpGetter {
return eTag; return eTag;
} }
public long getDuration() {
return duration;
}
} }
public static class NotModifiedException extends Exception { public static class NotModifiedException extends Exception {