JDown/src/JDown/JDown.java
/**
     * blockLen -> progress made 2 seconds before, is used to calculate speed.
     * sec -> render those information every 2 seconds
     * */
> progress made 2 seconds before, is used to calculate speed.
sec -> render those information every 2 seconds
> progress made 2 seconds before is used to calculate speed . sec - > render those information every 2 seconds
public void run(){
        long startTime = System.currentTimeMillis();
        allocate();
        long blockLen = 0;
        int sec = 0;
        long cur = tracer.getHasDown();
        while (!isWrong.get() && cur < fileSize){
            try {
                Thread.sleep(1000);
                ProgressBar.flush();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if(++sec == 1) {
                System.out.print(String.format("[Speed: %2.1fMb/s][Progress: %2.1f%%]: |-%s-|", (float)(cur-blockLen)/1024/1024, (float)cur / fileSize * 100, ProgressBar.bar((int)(cur * 25 / fileSize ))));
                sec = 0;
                blockLen = cur;
            }
            cur = tracer.getHasDown();
        }
        try {
            localFile.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        long totalTime = (System.currentTimeMillis()-startTime)/1000;
        int ms = (int)totalTime / 60;
        int ss = Math.floorMod(totalTime, 60);
        if (isWrong.get()){
            try {
                Files.delete(Paths.get(localFileName));
            } catch (IOException e) {
                e.printStackTrace();
            }
            logErr(String.format("\nDownload mission canceled! Total time: %dm%ds", ms, ss));
        }else{
            log(String.format("\nDownload mission completed! Total time: %dm%ds", ms, ss));
        }
    }
public void run ( ) { long startTime = System . currentTimeMillis ( ) ; allocate ( ) ; long blockLen = 0 ; int sec = 0 ; long cur = tracer . getHasDown ( ) ; while ( ! isWrong . get ( ) && cur < fileSize ) { try { Thread . sleep ( 1000 ) ; ProgressBar . flush ( ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } if ( ++ sec == 1 ) { System . out . print ( String . format ( "[Speed: %2.1fMb/s][Progress: %2.1f%%]: |-%s-|" , ( float ) ( cur - blockLen ) / 1024 / 1024 , ( float ) cur / fileSize * 100 , ProgressBar . bar ( ( int ) ( cur * 25 / fileSize ) ) ) ) ; sec = 0 ; blockLen = cur ; } cur = tracer . getHasDown ( ) ; } try { localFile . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } long totalTime = ( System . currentTimeMillis ( ) - startTime ) / 1000 ; int ms = ( int ) totalTime / 60 ; int ss = Math . floorMod ( totalTime , 60 ) ; if ( isWrong . get ( ) ) { try { Files . delete ( Paths . get ( localFileName ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } logErr ( String . format ( "\nDownload mission canceled! Total time: %dm%ds" , ms , ss ) ) ; } else { log ( String . format ( "\nDownload mission completed! Total time: %dm%ds" , ms , ss ) ) ; } }
blockLen -> progress made 2 seconds before, is used to calculate speed.
blockLen - > progress made 2 seconds before is used to calculate speed .