From fa47ea93ae81cd06bfc72e403a5924716319697f Mon Sep 17 00:00:00 2001 From: Fateme Azizi Date: Mon, 8 Jun 2026 18:36:08 +0330 Subject: [PATCH] edit DownloadWorker.java --- src/main/java/DownloadWorker.java | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/DownloadWorker.java b/src/main/java/DownloadWorker.java index 83576d5..d3134a9 100644 --- a/src/main/java/DownloadWorker.java +++ b/src/main/java/DownloadWorker.java @@ -21,54 +21,55 @@ public class DownloadWorker implements Runnable { @Override public void run() { - // TODO: Record the chunk start time in chunkStatus. + // Record the chunk start time in chunkStatus. chunkStatus.setStartTimeMs(System.currentTimeMillis()); double downloaded = 0.0; - // TODO: Print a message that this chunk has started downloading. - System.out.println("Starting download for Chunk ID: " + chunkStatus.getChunkId()); + // Print a message that this chunk has started downloading. + System.out.println("Starting download for Chunk " + chunkStatus.getChunkId()); while (downloaded < chunkStatus.getChunkSizeMB()) { - // TODO: Generate a random sleep delay between min and max delay. + // Generate a random sleep delay between min and max delay. long minDelay = config.getMinStepDelayMs(); long maxDelay = config.getMaxStepDelayMs(); long sleepTime = minDelay + (long) ((maxDelay - minDelay) * random.nextDouble()); - // TODO: Sleep for that delay. + // Sleep for that delay. try { Thread.sleep(sleepTime); } catch (InterruptedException e) { throw new RuntimeException(e); } - // TODO: Generate a random download amount for this step. + // Generate a random download amount for this step. double minStep = config.getMinStepDownloadMB(); double maxStep = config.getMaxStepDownloadMB(); double downloadAmount = minStep + ((maxStep - minStep) * random.nextDouble()); - // TODO: Increase downloaded, but do not go beyond chunk size. + // Increase downloaded, but do not go beyond chunk size. if(downloaded + downloadAmount >= chunkStatus.getChunkSizeMB()) downloaded = chunkStatus.getChunkSizeMB(); else downloaded += downloadAmount; - // TODO: Save the updated downloaded value into chunkStatus. + // Save the updated downloaded value into chunkStatus. chunkStatus.setDownloadedMB(downloaded); - // TODO: Optionally print step-by-step progress. - System.out.println("Chunk ID: " + chunkStatus.getChunkId() + " | downloaded: " + downloaded); + // Optionally print step-by-step progress. + System.out.print("Chunk " + chunkStatus.getChunkId() + " | downloaded: "); + System.out.printf("%.2f%n", downloaded); } - // TODO: Mark the chunk as completed. + // Mark the chunk as completed. chunkStatus.setCompleted(true); - // TODO: Record the chunk end time in chunkStatus. + // Record the chunk end time in chunkStatus. chunkStatus.setEndTimeMs(System.currentTimeMillis()); - // TODO: Print a message that this chunk has finished downloading. - System.out.println("Chunk ID: " + chunkStatus.getChunkId() + " | COMPLETED!"); + // Print a message that this chunk has finished downloading. + System.out.println("\nChunk " + chunkStatus.getChunkId() + " | COMPLETED!\n"); } }