Die Messung Download-Geschwindigkeit Von Java

Arbeite ich auf das herunterladen einer Datei auf einer software, dies ist, was ich habe, es sucesfully download, und auch ich kann Fortschritt, aber noch 1 Sache übrig, die ich nicht wissen, wie zu tun ist. Messen Sie die download-Geschwindigkeit. Ich würde Ihre Hilfe schätzen. Danke.
Dies ist die aktuelle download-Methode code

    public void run()
    {
        OutputStream out = null;
        URLConnection conn = null;
        InputStream in = null;
        try
        {
            URL url1 = new URL(url);
            out = new BufferedOutputStream(
            new FileOutputStream(sysDir+"\\"+where));
            conn = url1.openConnection();
            in = conn.getInputStream();
            byte[] buffer = new byte[1024];
            int numRead;
            long numWritten = 0;
            double progress1;
            while ((numRead = in.read(buffer)) != -1)
            {
                out.write(buffer, 0, numRead);
                numWritten += numRead;
                this.speed= (int) (((double)
                buffer.length)/8);
                progress1 = (double) numWritten;
                this.progress=(int) progress1;
            }
        }
        catch (Exception ex)
        {
            echo("Unknown Error: " + ex);
        }
        finally
        {
            try
            {
                if (in != null)
                {
                    in.close();
                }
                if (out != null)
                {
                    out.close();
                }
            }
            catch (IOException ex)
            {
                echo("Unknown Error: " + ex);
            }
        }
    }

InformationsquelleAutor Jesus David Gulfo Agudelo | 2011-06-12

Schreibe einen Kommentar