add bonus tasks
This commit is contained in:
@@ -16,6 +16,7 @@ public class ProgressMonitor implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
double previousProgress = 0.0;
|
||||
|
||||
while (true) {
|
||||
double totalDownloadedMB = 0.0;
|
||||
@@ -34,15 +35,36 @@ public class ProgressMonitor implements Runnable {
|
||||
percent = (totalDownloadedMB * 100.0) / totalSizeMB;
|
||||
}
|
||||
|
||||
System.out.printf(
|
||||
"Progress for %s: %.1f/%.1f MB (%.2f%%), completed chunks: %d/%d%n",
|
||||
fileName,
|
||||
totalDownloadedMB,
|
||||
(double) totalSizeMB,
|
||||
percent,
|
||||
completedChunks,
|
||||
chunks.size()
|
||||
);
|
||||
|
||||
double deltaMB = totalDownloadedMB - previousProgress;
|
||||
double speedMBps = deltaMB / (monitorDelayMs / 1000.0);
|
||||
previousProgress = totalDownloadedMB;
|
||||
|
||||
|
||||
double remainingMB = totalSizeMB - totalDownloadedMB;
|
||||
long etaSeconds = (speedMBps > 0) ? (long)(remainingMB / speedMBps) : 0;
|
||||
|
||||
|
||||
int barWidth = 30;
|
||||
int filled = (int)(percent / 100.0 * barWidth);
|
||||
filled = Math.min(filled, barWidth);
|
||||
String bar = "=".repeat(filled) + (filled < barWidth ? ">" : "") + " ".repeat(Math.max(0, barWidth - filled - 1));
|
||||
|
||||
|
||||
System.out.printf("\r[%-30s] %5.1f%% | %5.1f/%d MB | Speed: %.2f MB/s | ETA: %ds | Chunks: %d/%d ",
|
||||
bar, percent, totalDownloadedMB, totalSizeMB,
|
||||
speedMBps, etaSeconds,
|
||||
completedChunks, chunks.size());
|
||||
|
||||
// System.out.printf(
|
||||
// "Progress for %s: %.1f/%.1f MB (%.2f%%), completed chunks: %d/%d%n",
|
||||
// fileName,
|
||||
// totalDownloadedMB,
|
||||
// (double) totalSizeMB,
|
||||
// percent,
|
||||
// completedChunks,
|
||||
// chunks.size()
|
||||
// );
|
||||
|
||||
|
||||
if (completedChunks == chunks.size()) {
|
||||
|
||||
Reference in New Issue
Block a user