-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat[downloader]: downloader improvements
- Add download size queries through a HEAD request - Use the file size for progress instead of file count when all file size are available - Add download speed meter
- Loading branch information
Showing
5 changed files
with
129 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/SpeedCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package net.kdt.pojavlaunch.tasks; | ||
|
||
/** | ||
* A simple class to calculate the average Internet speed using a simple moving average. | ||
*/ | ||
public class SpeedCalculator { | ||
private long mLastMillis; | ||
private long mLastBytes; | ||
private int mIndex; | ||
private final double[] mPreviousInputs; | ||
private double mSum; | ||
|
||
public SpeedCalculator() { | ||
this(4); | ||
} | ||
|
||
public SpeedCalculator(int averageDepth) { | ||
mPreviousInputs = new double[averageDepth]; | ||
} | ||
|
||
private double addToAverage(double speed) { | ||
mSum -= mPreviousInputs[mIndex]; | ||
mSum += speed; | ||
mPreviousInputs[mIndex] = speed; | ||
if(++mIndex == mPreviousInputs.length) mIndex = 0; | ||
double dLength = mPreviousInputs.length; | ||
return (mSum + (dLength / 2d)) / dLength; | ||
} | ||
|
||
public double feed(long newBytes) { | ||
long millis = System.currentTimeMillis(); | ||
long deltaBytes = newBytes - mLastBytes; | ||
long deltaMillis = millis - mLastMillis; | ||
mLastBytes = deltaBytes; | ||
mLastMillis = millis; | ||
double speed = (double)deltaBytes / (double)deltaMillis; | ||
return addToAverage(speed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters