FrancesTwisk commented on code in PR #224:
URL: https://github.com/apache/ant/pull/224#discussion_r2481473836
##########
src/main/org/apache/tools/ant/taskdefs/Get.java:
##########
@@ -654,8 +662,109 @@ public void endDownload() {
}
}
- private class GetThread extends Thread {
+ public class ProgressBarProgress implements DownloadProgress {
+ private long contentLength;
+ private long downloadedBytes;
+ private long lastDownloadedBytes;
+ private final PrintStream out;
+ private long lastTime;
+ private int previousLineLength = 0;
+
+ public ProgressBarProgress(PrintStream out) {
+ this.out = out;
+ }
+
+ public void setContentLength(long contentLength) {
+ this.contentLength = contentLength;
+ }
+
+ @Override
+ public void beginDownload() {
+ downloadedBytes = 0;
+ lastDownloadedBytes = 0;
+ lastTime = System.nanoTime();
+ }
+
+ @Override
+ public void onTick() {
+ int downloadedBytesPercentage = (int) ((downloadedBytes * 100) /
contentLength);
+ printProgressBar(downloadedBytesPercentage,
calculateDownloadSpeed());
+ }
+
+ public double calculateDownloadSpeed() {
+ long bytesSinceLast = downloadedBytes - lastDownloadedBytes;
+ long elapsedTime = System.nanoTime() - lastTime;
+ return (elapsedTime > 0)
+ ? (bytesSinceLast / (elapsedTime / 1_000_000_000.0))
+ : 0.0;
+ }
+
+ public void printProgressBar(int downloadedBytesPercentage, double
downloadSpeed) {
+ int size = 50;
Review Comment:
const is not a keyword in Java I think, but since the size variable doesn't
change I can add the final keyword.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]