From 8201eef57161c890b0bbfdb362fde5df55643abe Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Tue, 3 Jul 2018 20:10:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8B=E8=BD=BD=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E5=AE=8C=E6=95=B4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../arialyy/aria/core/common/AbsFileer.java | 48 +++++++++--- .../arialyy/aria/core/common/ProxyHelper.java | 2 +- .../aria/core/common/StateConstance.java | 6 +- .../aria/core/download/BaseNormalTarget.java | 4 +- .../download/downloader/HttpThreadTask.java | 24 ++++-- .../com/arialyy/aria/util/CommonUtil.java | 2 +- app/src/main/AndroidManifest.xml | 4 +- .../download/group/DownloadGroupActivity.java | 6 +- .../simple/download/group/GroupModule.java | 74 +++++++++++++++++++ .../arialyy/simple/test/AnyRunActivity.java | 7 +- .../arialyy/simple/test/AnyRunnModule.java | 2 +- 11 files changed, 148 insertions(+), 31 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java index 47ed0589..df094f64 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java @@ -245,7 +245,7 @@ public abstract class AbsFileer tr.endLocation) { + ALog.w(TAG, String.format("分块【%s】错误,将重新开始该分块", temp.getPath())); + temp.delete(); + tr.startLocation = i * blockLen; + } + mStartThreadNum++; + } } } - mTotalThreadNum = mRecord.threadRecords.size(); - mTaskEntity.setNewTask(false); + i++; } + mTotalThreadNum = mRecord.threadRecords.size(); + mTaskEntity.setNewTask(false); } else { File file = new File(mRecord.filePath); if (!file.exists()) { - ALog.w(TAG, String.format("下载文件【%s】不存在,任务将重新开始", file.getPath())); + ALog.w(TAG, String.format("文件【%s】不存在,任务将重新开始", file.getPath())); mRecord.deleteData(); initRecord(true); return; @@ -483,22 +507,24 @@ public abstract class AbsFileer= 0) { - Long r = tr.startLocation; + if (tr.startLocation > 0) { + long r = tr.startLocation; //记录的位置需要在线程区间中 - if (startL < r && r < (i == (mTotalThreadNum - 1) ? fileLength : endL)) { + if (startL < r && r <= (i == (mTotalThreadNum - 1) ? fileLength : endL)) { mConstance.CURRENT_LOCATION += r - startL; startL = r; } ALog.d(TAG, String.format("任务【%s】线程__%s__恢复任务", mEntity.getFileName(), i)); + } else { + tr.startLocation = startL; } //最后一个线程的结束位置即为文件的总长度 if (i == (mTotalThreadNum - 1)) { endL = fileLength; } - // 更新记录 - tr.startLocation = startL; - tr.endLocation = endL; + if (tr.endLocation <= 0) { + tr.endLocation = endL; + } if (isNewTr) { mRecord.threadRecords.add(tr); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java b/Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java index c5e59eb4..480795d3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java @@ -47,7 +47,7 @@ public class ProxyHelper { } private void init() { - List classes = CommonUtil.getClassName(AriaManager.APP, + List classes = CommonUtil.getPkgClassNames(AriaManager.APP, "com.arialyy.aria.ProxyClassCounter"); for (String className : classes) { count(className); diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java b/Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java index b3cae98b..cad1c6e1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java @@ -50,14 +50,16 @@ public class StateConstance { * 所有子线程是否都已经停止 */ public boolean isStop() { - return STOP_NUM == START_THREAD_NUM; + ALog.d(TAG, String.format("stop_num=%s; start_thread_num=%s; complete_num=%s", STOP_NUM, + START_THREAD_NUM, COMPLETE_THREAD_NUM)); + return STOP_NUM == START_THREAD_NUM || STOP_NUM + COMPLETE_THREAD_NUM == START_THREAD_NUM; } /** * 所有子线程是否都已经失败 */ public boolean isFail() { - ALog.d(TAG, String.format("fail_num=%s; start_thread_num=%s, complete_num=%s", FAIL_NUM, + ALog.d(TAG, String.format("fail_num=%s; start_thread_num=%s; complete_num=%s", FAIL_NUM, START_THREAD_NUM, COMPLETE_THREAD_NUM)); return COMPLETE_THREAD_NUM != START_THREAD_NUM && (FAIL_NUM == START_THREAD_NUM || FAIL_NUM + COMPLETE_THREAD_NUM == START_THREAD_NUM); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java index 5bc9abdc..b272d294 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java @@ -162,7 +162,7 @@ abstract class BaseNormalTarget } } - //设置文件保存路径,如果新文件路径和就文件路径不同,则修改路径 + //设置文件保存路径,如果新文件路径和旧文件路径不同,则修改路径 if (!filePath.equals(mEntity.getDownloadPath())) { if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=?", filePath)) { ALog.e(TAG, "下载失败,保存路径【" + filePath + "】已经被其它任务占用,请设置其它保存路径"); @@ -200,7 +200,7 @@ abstract class BaseNormalTarget ALog.e(TAG, "下载失败,url【" + url + "】不合法"); return false; } - if (!TextUtils.isEmpty(newUrl)){ + if (!TextUtils.isEmpty(newUrl)) { mEntity.setUrl(newUrl); mTaskEntity.setUrl(newUrl); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java index 7708c4f6..23caeacd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java @@ -76,7 +76,6 @@ final class HttpThreadTask extends AbsThreadTask 0) { Thread.sleep(mSleepTime); } - bf.flip(); - foc.write(bf); - bf.compact(); - progress(len); + // + //bf.flip(); + //foc.write(bf); + //bf.compact(); + //progress(len); + if (mChildCurrentLocation + len >= mConfig.END_LOCATION) { + len = (int) (mConfig.END_LOCATION - mChildCurrentLocation); + bf.flip(); + fos.write(bf.array(), 0, len); + bf.compact(); + progress(len); + break; + } else { + bf.flip(); + foc.write(bf); + bf.compact(); + progress(len); + } } handleComplete(); } catch (InterruptedException e) { @@ -157,6 +170,7 @@ final class HttpThreadTask extends AbsThreadTask getClassName(Context context, String className) { + public static List getPkgClassNames(Context context, String className) { List classNameList = new ArrayList<>(); String pPath = context.getPackageCodePath(); File dir = new File(pPath).getParentFile(); diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8051a8c7..04f66b2a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,10 +16,10 @@ + - diff --git a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java index 1544e4a5..6811af74 100644 --- a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java @@ -45,7 +45,7 @@ public class DownloadGroupActivity extends BaseActivity getSubName2() { + List taskSubFile; + taskSubFile = new ArrayList<>(); + //taskSubFile.add("2156.mp4"); + // taskSubFile.add("2115.mp4"); + //taskSubFile.add("2009.mp4"); + //taskSubFile.add("1893.mp4"); + //taskSubFile.add("1952.mp4"); + //taskSubFile.add("1958.mp4"); + taskSubFile.add("1994.mp4"); + //taskSubFile.add("2083.mp4"); + taskSubFile.add("2305.JPG"); + taskSubFile.add("2183.JPG"); + taskSubFile.add("2154.JPG"); + taskSubFile.add("2153.JPG"); + taskSubFile.add("2152.JPG"); + taskSubFile.add("2151.JPG"); + taskSubFile.add("2149.JPG"); + taskSubFile.add("2148.JPG"); + taskSubFile.add("2147.JPG"); + taskSubFile.add("2146.JPG"); + taskSubFile.add("1949.JPG"); + taskSubFile.add("1887.JPG"); + taskSubFile.add("1996.txt"); + return taskSubFile; + } + + public List getUrls2() { + List downLoadUrls; + downLoadUrls = new ArrayList<>(); + //downLoadUrls.add( + // "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2156&clientId=A000011106034058176"); + // downLoadUrls.add("http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2115&clientId=A000011106034058176"); + //downLoadUrls.add( + // "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2009&clientId=A000011106034058176"); + //downLoadUrls.add( + // "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1893&clientId=A000011106034058176"); + //downLoadUrls.add( + // "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1952&clientId=A000011106034058176"); + //downLoadUrls.add( + // "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1958&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1994&clientId=A000011106034058176"); + //downLoadUrls.add( + // "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2083&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2305&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2183&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2154&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2153&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2152&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2151&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2149&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2148&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2147&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=2146&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1949&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1887&clientId=A000011106034058176"); + downLoadUrls.add( + "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1996&clientId=A000011106034058176"); + return downLoadUrls; + } } diff --git a/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java b/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java index fef44ccf..caa1047b 100644 --- a/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java +++ b/app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java @@ -27,7 +27,8 @@ public class AnyRunActivity extends BaseActivity { //String URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; //private final String URL = "ftp://192.168.29.140:21/download/AriaPrj.rar"; //String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe"; - String URL = "ftp://192.168.29.140:21/download/SDK_Demo-release.apk"; + //String URL = "ftp://192.168.29.140:21/download/SDK_Demo-release.apk"; + String URL = "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1994&clientId=A000011106034058176"; //String URL = "ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]猩球崛起3:终极之战BD国英双语中英双字.mkv"; //private String URL = "https://www.bilibili.com/bangumi/play/ep77693"; //private String URL = "http://cn-hbsjz-cmcc-v-03.acgvideo.com/upgcxcode/63/82/5108263/5108263-1-80.flv?expires=1530178500&platform=pc&ssig=vr7gLl0duyqWqSMnIpzaDA&oi=3746029570&nfa=BpfiWF+i4mNW8KzjZFHzBQ==&dynamic=1&hfa=2030547937&hfb=Yjk5ZmZjM2M1YzY4ZjAwYTMzMTIzYmIyNWY4ODJkNWI=&trid=3476be01a9254115b15f8cc7198600fe&nfc=1"; @@ -49,8 +50,8 @@ public class AnyRunActivity extends BaseActivity { public void onClick(View view) { switch (view.getId()) { case R.id.start: - //module.start(URL); - module.startFtp(URL); + module.start(URL); + //module.startFtp(URL); break; case R.id.stop: module.stop(URL); diff --git a/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java b/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java index c54fa1eb..40f2632f 100644 --- a/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java +++ b/app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java @@ -65,7 +65,7 @@ public class AnyRunnModule { void start(String url) { mUrl = url; - String path = Environment.getExternalStorageDirectory().getPath() + "/aaas.apk"; + String path = Environment.getExternalStorageDirectory().getPath() + "/mmm.mp4"; Aria.download(this) .load(url) .setRequestMode(RequestEnum.GET)