[英]How to determine that the file has finished downloaded
I am trying to calculate the bandwidth of the network by determining how much time does it take to download a fixed size file. 我试图通过确定下载固定大小的文件花费多少时间来计算网络的带宽。
starttime=Calendar.getInstance().getTimeInMillis();
HttpResponse response=cts.getContent();
if(response != null)
endtime=Calendar.getInstance().getTimeInMillis();
Here is my getContent()
method: 这是我的
getContent()
方法:
public HttpResponse getContent()
{
HttpClient httpClient = new DefaultHttpClient();
HttpGet postRequest = new HttpGet("myserverurl");
try {
Log.i(tag,"before execute");
HttpResponse response = httpClient.execute(postRequest);
Log.i(tag,"after execute");
HttpEntity httpEntity = response.getEntity();
is = httpEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
Log.i(tag,sb.toString());
response.toString();
return response;
} catch (Exception e) {
Log.i(tag,"execption="+e);
return null;
}
}
I calculate the end time when this method responds. 我计算该方法响应的结束时间。 My question is when is the right time to calculate the end time?
我的问题是什么时候才是计算结束时间的正确时间? If I take the endtime immediately after the line:
如果我在下线后立即采取结束时间:
HttpEntity httpEntity = response.getEntity();
The bandwidth I get is very high and when I do it after the while loop executes, the Bandwidth is completely different. 我获得的带宽非常高,当执行while循环后执行此操作时,带宽完全不同。
Which approach is the right one? 哪种方法是正确的? When does the file gets downloaded completely?
文件何时完全下载?
据我了解,它是同步的,反对异步的,所以在存储响应之后,下载就结束了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.