diff --git a/src/main/java/com/ilummc/eagletdl/Eaglet.java b/src/main/java/com/ilummc/eagletdl/Eaglet.java deleted file mode 100644 index 7e000b3..0000000 --- a/src/main/java/com/ilummc/eagletdl/Eaglet.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.ilummc.eagletdl; - -/** - * Test class - */ -public class Eaglet { - - public static void main(String[] args) { - //new EagletTask().url("http://sgp-ping.vultr.com/vultr.com.100MB.bin") - new EagletTask().url("https://gitee.com/bkm016/TabooLibCloud/raw/master/TabooMenu/TabooMenu.jar") - .file("F:\\test.dl") - .setThreads(1) - .readTimeout(1000) - .connectionTimeout(1000) - .maxRetry(30) - .setOnConnected(event -> System.out.println(event.getContentLength())) - .setOnProgress(event -> System.out.println(event.getSpeedFormatted() + " " + event.getPercentageFormatted())) - .setOnComplete(event -> System.out.println("Complete")) - .start(); - } - -} diff --git a/src/main/java/com/ilummc/eagletdl/EagletTask.java b/src/main/java/com/ilummc/eagletdl/EagletTask.java index a37d6b7..9b0c452 100644 --- a/src/main/java/com/ilummc/eagletdl/EagletTask.java +++ b/src/main/java/com/ilummc/eagletdl/EagletTask.java @@ -111,7 +111,7 @@ public class EagletTask { long progress = download.getCurrentProgress(); // fire a new progress event if (onProgress != null) { - onProgress.handle(new ProgressEvent(progress - last, this, ((double) progress) / Math.max((double) contentLength, 0D))); + onProgress.handle(new ProgressEvent(progress - last < 0 ? 0 : progress - last, this, ((double) progress) / Math.max((double) contentLength, 0D))); } last = progress; // check complete diff --git a/src/main/java/com/ilummc/eagletdl/SingleThreadDownload.java b/src/main/java/com/ilummc/eagletdl/SingleThreadDownload.java index 137762d..d03967e 100644 --- a/src/main/java/com/ilummc/eagletdl/SingleThreadDownload.java +++ b/src/main/java/com/ilummc/eagletdl/SingleThreadDownload.java @@ -35,8 +35,7 @@ class SingleThreadDownload implements Runnable { public void run() { byte[] buf = new byte[1024]; int len = 0; - try (BufferedInputStream stream = new BufferedInputStream(connection.getInputStream()); - BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(target))) { + try (BufferedInputStream stream = new BufferedInputStream(connection.getInputStream()); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(target))) { while ((len = stream.read(buf)) > 0) { outputStream.write(buf, 0, len); currentProgress += len; diff --git a/src/main/java/com/ilummc/eagletdl/SplitDownload.java b/src/main/java/com/ilummc/eagletdl/SplitDownload.java index 6727537..dd17663 100644 --- a/src/main/java/com/ilummc/eagletdl/SplitDownload.java +++ b/src/main/java/com/ilummc/eagletdl/SplitDownload.java @@ -80,7 +80,10 @@ class SplitDownload implements Runnable { } complete = true; } - } else throw new DoNotSupportMultipleThreadException(); + file.close(); + } else { + throw new DoNotSupportMultipleThreadException(); + } } catch (Exception e) { task.onError.handle(new ErrorEvent(e, task)); retry++;