Android:了解下载过程

时间:2014-05-06 11:23:19

标签: android download wifi inputstream

我试图计算我的wifi速度。所以我从服务器下载文件(10 Mb)。那下载工作得很好。但我不确定如何计算每个接收到的数据包的下载速度。

这部分代码我正在使用。我想知道两种尺寸之间的区别:8192和1024,每种尺寸的净化。

 InputStream input = new BufferedInputStream(url.openStream(), 8192);

这一行

 byte data[] = new byte[1024];

这就是我用它们的方式:

protected String doInBackground(String... f_url) {
    int count;
    int lenghtOfFile = 0;

    try {
        URL url = new URL(f_url[0]);
        comm = (HttpURLConnection)url.openConnection();
        URLConnection conection = url.openConnection();
        conection.connect();
         lenghtOfFile = conection.getContentLength();

        // download the file
        InputStream input = new BufferedInputStream(url.openStream(), 8192);

        // Output stream
        OutputStream output = new FileOutputStream("/sdcard/downloadedfile.jpg");

     byte data[] = new byte[1024];
        long total = 0;
        while ((count = input.read(data)) != -1) {
            actuaStartlTime = System.currentTimeMillis();
            total += count;

}}

这是输出样本:当前时间和下载数据。我没有看到下载数据大小之间的任何相关性。

    05-06 15:32:36.883: I/downloaded data(13146): 244392
05-06 15:32:36.883: I/current time in millisecond(13146): 1399386756881
05-06 15:32:37.329: I/downloaded data(13146): 245840
05-06 15:32:37.329: I/current time in millisecond(13146): 1399386757328
05-06 15:32:37.331: I/downloaded data(13146): 247288
05-06 15:32:37.332: I/current time in millisecond(13146): 1399386757330
05-06 15:32:37.334: I/downloaded data(13146): 250184
05-06 15:32:37.334: I/current time in millisecond(13146): 1399386757333
05-06 15:32:37.347: I/downloaded data(13146): 251632
05-06 15:32:37.347: I/current time in millisecond(13146): 1399386757345
05-06 15:32:37.349: I/downloaded data(13146): 262144
05-06 15:32:37.349: I/current time in millisecond(13146): 1399386757348
05-06 15:32:37.637: I/downloaded data(13146): 288208
05-06 15:32:37.637: I/current time in millisecond(13146): 1399386757636
05-06 15:32:38.050: I/downloaded data(13146): 289656
05-06 15:32:38.050: I/current time in millisecond(13146): 1399386758049
05-06 15:32:38.063: I/downloaded data(13146): 298344
05-06 15:32:38.063: I/current time in millisecond(13146): 1399386758062
05-06 15:32:38.067: I/downloaded data(13146): 304136
05-06 15:32:38.068: I/current time in millisecond(13146): 1399386758066
05-06 15:32:38.070: I/downloaded data(13146): 309928
05-06 15:32:38.071: I/current time in millisecond(13146): 1399386758069
05-06 15:32:38.079: I/downloaded data(13146): 317168

提前谢谢。

0 个答案:

没有答案