From d791e0d89efe090183e62c94b951a5acd3e1b500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Wed, 24 Oct 2018 22:51:27 +0800 Subject: [PATCH] =?UTF-8?q?+=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E4=B8=8B=E8=BD=BD=E5=90=8E=E4=B8=8D=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=B5=81=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ilummc/eagletdl/Eaglet.java | 22 ------------------- .../java/com/ilummc/eagletdl/EagletTask.java | 2 +- .../ilummc/eagletdl/SingleThreadDownload.java | 3 +-- .../com/ilummc/eagletdl/SplitDownload.java | 5 ++++- 4 files changed, 6 insertions(+), 26 deletions(-) delete mode 100644 src/main/java/com/ilummc/eagletdl/Eaglet.java 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++;