From f2e566ba7e00d7b7dfe1a035a662d7385ec8bcb3 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Tue, 13 Mar 2018 21:54:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0chunled=20=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../arialyy/aria/core/common/AbsFileer.java | 6 +----- .../aria/core/download/BaseGroupTarget.java | 2 +- .../aria/core/download/BaseNormalTarget.java | 12 +++++++---- .../core/download/DownloadGroupTarget.java | 4 ++++ .../core/download/FtpDirDownloadTarget.java | 8 ++++--- .../downloader/HttpFileInfoThread.java | 21 ++++--------------- .../download/downloader/HttpThreadTask.java | 9 ++++---- .../aria/core/scheduler/AbsSchedulers.java | 2 +- DEV_LOG.md | 3 ++- app/src/main/assets/aria_config.xml | 2 +- .../simple/download/SingleTaskActivity.java | 8 +++---- 11 files changed, 36 insertions(+), 41 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 bf30ff74..c7fb1145 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 @@ -129,11 +129,7 @@ public abstract class AbsFileer /** * 文件夹临时路径 */ - private String mDirPathTemp; + protected String mDirPathTemp; private SubTaskManager mSubTaskManager; 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 b488685e..d2daf220 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 @@ -47,6 +47,9 @@ abstract class BaseNormalTarget } mEntity = mTaskEntity.entity; mTaskEntity.refreshInfo = refreshInfo; + if (mEntity != null) { + mTempFilePath = mEntity.getDownloadPath(); + } } /** @@ -61,6 +64,9 @@ abstract class BaseNormalTarget } mEntity = mTaskEntity.entity; mTaskEntity.refreshInfo = refreshInfo; + if (mEntity != null) { + mTempFilePath = mEntity.getDownloadPath(); + } } /** @@ -97,8 +103,7 @@ abstract class BaseNormalTarget * * @deprecated {@link #isRunning()} */ - @Deprecated - public boolean isDownloading() { + @Deprecated public boolean isDownloading() { return isRunning(); } @@ -121,8 +126,7 @@ abstract class BaseNormalTarget * * @return {@code true}合法 */ - @Override - protected boolean checkEntity() { + @Override protected boolean checkEntity() { return getTargetType() < GROUP_HTTP && checkUrl() && checkFilePath(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java index 903f8b7e..6dc2d36f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java @@ -56,6 +56,10 @@ public class DownloadGroupTarget extends BaseGroupTarget { TEManager.getInstance().createTEntity(DownloadGroupTaskEntity.class, groupEntity); } mEntity = mTaskEntity.entity; + + if (mEntity != null) { + mDirPathTemp = mEntity.getDirPath(); + } } DownloadGroupTarget(List urls, String targetName) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java index cb7b2d01..04b09e5c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java @@ -26,8 +26,8 @@ import com.arialyy.aria.util.ALog; * Created by Aria.Lao on 2017/7/26. * ftp文件夹下载 */ -public class FtpDirDownloadTarget extends BaseGroupTarget implements - IFtpTarget { +public class FtpDirDownloadTarget extends BaseGroupTarget + implements IFtpTarget { private final String TAG = "FtpDirDownloadTarget"; private FtpDelegate mDelegate; @@ -44,7 +44,9 @@ public class FtpDirDownloadTarget extends BaseGroupTarget } mTaskEntity.requestType = AbsTaskEntity.D_FTP_DIR; mEntity = mTaskEntity.entity; - + if (mEntity != null) { + mDirPathTemp = mEntity.getDirPath(); + } mDelegate = new FtpDelegate<>(this, mTaskEntity); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java index 0bfaceb0..6a05844f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java @@ -15,9 +15,7 @@ */ package com.arialyy.aria.core.download.downloader; -import android.location.Address; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.OnFileInfoCallback; @@ -27,11 +25,8 @@ import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; import java.io.IOException; -import java.io.InputStream; import java.net.HttpURLConnection; -import java.net.InetAddress; import java.net.URL; -import java.net.URLConnection; import java.net.URLDecoder; import java.util.List; import java.util.Map; @@ -86,11 +81,11 @@ class HttpFileInfoThread implements Runnable { len = TextUtils.isEmpty(temp) ? -1 : Long.parseLong(temp); // 某些服务,如果设置了conn.setRequestProperty("Range", "bytes=" + 0 + "-"); // 会返回 Content-Range: bytes 0-225427911/225427913 - if (len < 0){ + if (len < 0) { temp = conn.getHeaderField("Content-Range"); - if (TextUtils.isEmpty(temp)){ + if (TextUtils.isEmpty(temp)) { len = -1; - }else { + } else { int start = temp.indexOf("/"); len = Long.parseLong(temp.substring(start + 1, temp.length())); } @@ -103,19 +98,11 @@ class HttpFileInfoThread implements Runnable { mEntity.setMd5Code(md5Code); } - Map> headers = conn.getHeaderFields(); + //Map> headers = conn.getHeaderFields(); boolean isChunked = false; - //https://my.oschina.net/ososchina/blog/666761 final String str = conn.getHeaderField("Transfer-Encoding"); if (!TextUtils.isEmpty(str) && str.equals("chunked")) { isChunked = true; - //StringBuffer sb = new StringBuffer(); - //byte[] buffer = new byte[1024]; - //InputStream is = conn.getInputStream(); - //int l = 0; - //while (true){ - // is.read() - //} } String disposition = conn.getHeaderField(mTaskEntity.dispositionKey); if (!TextUtils.isEmpty(disposition)) { 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 9f0be85c..68850799 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 @@ -90,7 +90,7 @@ final class HttpThreadTask extends AbsThreadTask>> iter = diff --git a/DEV_LOG.md b/DEV_LOG.md index f69f117e..a35dc6c3 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,7 +1,8 @@ ## 开发日志 + v_3.3.16 - 修复一个activity启动多次,无法进行回掉的bug https://github.com/AriaLyy/Aria/issues/200 - - 优化target代码结构 + - 优化target代码结构,移除路径被占用的提示 + - 添加支持chunked模式的下载 + v_3.3.14 - 修复ftp上传和下载的兼容性问题 - 如果url中的path有"//"将替换为"/" diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index 7268c227..9cd82f96 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -5,7 +5,7 @@ - + diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index be887ca3..f92518ee 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -200,7 +200,7 @@ public class SingleTaskActivity extends BaseActivity { mStart.setText("恢复"); mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light)); setBtState(true); - } else if (target.isDownloading()) { + } else if (target.isRunning()) { setBtState(false); } getBinding().setFileSize(target.getConvertFileSize()); @@ -212,12 +212,12 @@ public class SingleTaskActivity extends BaseActivity { startD(); break; case R.id.stop: - //Aria.download(this).load(DOWNLOAD_URL).stop(); - startActivity(new Intent(this, SingleTaskActivity.class)); + Aria.download(this).load(DOWNLOAD_URL).stop(); + //startActivity(new Intent(this, SingleTaskActivity.class)); //Aria.download(this).load(DOWNLOAD_URL).removeRecord(); break; case R.id.cancel: - //Aria.download(this).load(DOWNLOAD_URL).cancel(); + Aria.download(this).load(DOWNLOAD_URL).cancel(); Aria.download(this).load(DOWNLOAD_URL).removeRecord(); break; }