添加chunled 支持
This commit is contained in:
@@ -129,11 +129,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
final int num =
|
final int num =
|
||||||
mEntity.getFileSize() <= SUB_LEN || mTaskEntity.requestType == AbsTaskEntity.D_FTP_DIR ? 1
|
mEntity.getFileSize() <= SUB_LEN || mTaskEntity.requestType == AbsTaskEntity.D_FTP_DIR ? 1
|
||||||
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum();
|
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum();
|
||||||
if (mTaskEntity instanceof DownloadTaskEntity && ((DownloadTaskEntity) mTaskEntity).isChunked) {
|
mStartThreadNum = num;
|
||||||
mStartThreadNum = 1;
|
|
||||||
} else {
|
|
||||||
mStartThreadNum = num;
|
|
||||||
}
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
|
|||||||
/**
|
/**
|
||||||
* 文件夹临时路径
|
* 文件夹临时路径
|
||||||
*/
|
*/
|
||||||
private String mDirPathTemp;
|
protected String mDirPathTemp;
|
||||||
|
|
||||||
private SubTaskManager mSubTaskManager;
|
private SubTaskManager mSubTaskManager;
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
|||||||
}
|
}
|
||||||
mEntity = mTaskEntity.entity;
|
mEntity = mTaskEntity.entity;
|
||||||
mTaskEntity.refreshInfo = refreshInfo;
|
mTaskEntity.refreshInfo = refreshInfo;
|
||||||
|
if (mEntity != null) {
|
||||||
|
mTempFilePath = mEntity.getDownloadPath();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,6 +64,9 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
|||||||
}
|
}
|
||||||
mEntity = mTaskEntity.entity;
|
mEntity = mTaskEntity.entity;
|
||||||
mTaskEntity.refreshInfo = refreshInfo;
|
mTaskEntity.refreshInfo = refreshInfo;
|
||||||
|
if (mEntity != null) {
|
||||||
|
mTempFilePath = mEntity.getDownloadPath();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,8 +103,7 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
|||||||
*
|
*
|
||||||
* @deprecated {@link #isRunning()}
|
* @deprecated {@link #isRunning()}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated public boolean isDownloading() {
|
||||||
public boolean isDownloading() {
|
|
||||||
return isRunning();
|
return isRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,8 +126,7 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
|
|||||||
*
|
*
|
||||||
* @return {@code true}合法
|
* @return {@code true}合法
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override protected boolean checkEntity() {
|
||||||
protected boolean checkEntity() {
|
|
||||||
return getTargetType() < GROUP_HTTP && checkUrl() && checkFilePath();
|
return getTargetType() < GROUP_HTTP && checkUrl() && checkFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
|
|||||||
TEManager.getInstance().createTEntity(DownloadGroupTaskEntity.class, groupEntity);
|
TEManager.getInstance().createTEntity(DownloadGroupTaskEntity.class, groupEntity);
|
||||||
}
|
}
|
||||||
mEntity = mTaskEntity.entity;
|
mEntity = mTaskEntity.entity;
|
||||||
|
|
||||||
|
if (mEntity != null) {
|
||||||
|
mDirPathTemp = mEntity.getDirPath();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadGroupTarget(List<String> urls, String targetName) {
|
DownloadGroupTarget(List<String> urls, String targetName) {
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ import com.arialyy.aria.util.ALog;
|
|||||||
* Created by Aria.Lao on 2017/7/26.
|
* Created by Aria.Lao on 2017/7/26.
|
||||||
* ftp文件夹下载
|
* ftp文件夹下载
|
||||||
*/
|
*/
|
||||||
public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget> implements
|
public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget>
|
||||||
IFtpTarget<FtpDirDownloadTarget> {
|
implements IFtpTarget<FtpDirDownloadTarget> {
|
||||||
private final String TAG = "FtpDirDownloadTarget";
|
private final String TAG = "FtpDirDownloadTarget";
|
||||||
private FtpDelegate<FtpDirDownloadTarget, DownloadGroupEntity, DownloadGroupTaskEntity> mDelegate;
|
private FtpDelegate<FtpDirDownloadTarget, DownloadGroupEntity, DownloadGroupTaskEntity> mDelegate;
|
||||||
|
|
||||||
@@ -44,7 +44,9 @@ public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget>
|
|||||||
}
|
}
|
||||||
mTaskEntity.requestType = AbsTaskEntity.D_FTP_DIR;
|
mTaskEntity.requestType = AbsTaskEntity.D_FTP_DIR;
|
||||||
mEntity = mTaskEntity.entity;
|
mEntity = mTaskEntity.entity;
|
||||||
|
if (mEntity != null) {
|
||||||
|
mDirPathTemp = mEntity.getDirPath();
|
||||||
|
}
|
||||||
mDelegate = new FtpDelegate<>(this, mTaskEntity);
|
mDelegate = new FtpDelegate<>(this, mTaskEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.arialyy.aria.core.download.downloader;
|
package com.arialyy.aria.core.download.downloader;
|
||||||
|
|
||||||
import android.location.Address;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
|
||||||
import com.arialyy.aria.core.AriaManager;
|
import com.arialyy.aria.core.AriaManager;
|
||||||
import com.arialyy.aria.core.common.CompleteInfo;
|
import com.arialyy.aria.core.common.CompleteInfo;
|
||||||
import com.arialyy.aria.core.common.OnFileInfoCallback;
|
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.CheckUtil;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -86,11 +81,11 @@ class HttpFileInfoThread implements Runnable {
|
|||||||
len = TextUtils.isEmpty(temp) ? -1 : Long.parseLong(temp);
|
len = TextUtils.isEmpty(temp) ? -1 : Long.parseLong(temp);
|
||||||
// 某些服务,如果设置了conn.setRequestProperty("Range", "bytes=" + 0 + "-");
|
// 某些服务,如果设置了conn.setRequestProperty("Range", "bytes=" + 0 + "-");
|
||||||
// 会返回 Content-Range: bytes 0-225427911/225427913
|
// 会返回 Content-Range: bytes 0-225427911/225427913
|
||||||
if (len < 0){
|
if (len < 0) {
|
||||||
temp = conn.getHeaderField("Content-Range");
|
temp = conn.getHeaderField("Content-Range");
|
||||||
if (TextUtils.isEmpty(temp)){
|
if (TextUtils.isEmpty(temp)) {
|
||||||
len = -1;
|
len = -1;
|
||||||
}else {
|
} else {
|
||||||
int start = temp.indexOf("/");
|
int start = temp.indexOf("/");
|
||||||
len = Long.parseLong(temp.substring(start + 1, temp.length()));
|
len = Long.parseLong(temp.substring(start + 1, temp.length()));
|
||||||
}
|
}
|
||||||
@@ -103,19 +98,11 @@ class HttpFileInfoThread implements Runnable {
|
|||||||
mEntity.setMd5Code(md5Code);
|
mEntity.setMd5Code(md5Code);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, List<String>> headers = conn.getHeaderFields();
|
//Map<String, List<String>> headers = conn.getHeaderFields();
|
||||||
boolean isChunked = false;
|
boolean isChunked = false;
|
||||||
//https://my.oschina.net/ososchina/blog/666761
|
|
||||||
final String str = conn.getHeaderField("Transfer-Encoding");
|
final String str = conn.getHeaderField("Transfer-Encoding");
|
||||||
if (!TextUtils.isEmpty(str) && str.equals("chunked")) {
|
if (!TextUtils.isEmpty(str) && str.equals("chunked")) {
|
||||||
isChunked = true;
|
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);
|
String disposition = conn.getHeaderField(mTaskEntity.dispositionKey);
|
||||||
if (!TextUtils.isEmpty(disposition)) {
|
if (!TextUtils.isEmpty(disposition)) {
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
if (STATE.isCancel || STATE.isStop) {
|
if (STATE.isCancel || STATE.isStop) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handleStop();
|
handleComplete();
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
fail(mChildCurrentLocation, "下载链接异常", e);
|
fail(mChildCurrentLocation, "下载链接异常", e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -116,10 +116,11 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取chunk模式的文件流
|
* 读取chunk模式的文件流
|
||||||
|
* @deprecated 暂时先这样处理,无chun
|
||||||
*/
|
*/
|
||||||
private void readChunk(InputStream is, RandomAccessFile file)
|
private void readChunk(InputStream is, RandomAccessFile file)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
|
readNormal(is, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,11 +143,11 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理暂停或完成配置文件的更新或事件回调
|
* 处理完成配置文件的更新或事件回调
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private void handleStop() throws IOException {
|
private void handleComplete() throws IOException {
|
||||||
//支持断点的处理
|
//支持断点的处理
|
||||||
if (mConfig.SUPPORT_BP) {
|
if (mConfig.SUPPORT_BP) {
|
||||||
if (mChildCurrentLocation == mConfig.END_LOCATION) {
|
if (mChildCurrentLocation == mConfig.END_LOCATION) {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public void unRegister(Object obj) {
|
@Override public void unRegister(Object obj) {
|
||||||
if (!mObservers.containsKey(obj.getClass().getName())) {
|
if (!mObservers.containsKey(getKey(obj))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (Iterator<Map.Entry<String, AbsSchedulerListener<TASK, AbsNormalEntity>>> iter =
|
for (Iterator<Map.Entry<String, AbsSchedulerListener<TASK, AbsNormalEntity>>> iter =
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
## 开发日志
|
## 开发日志
|
||||||
+ v_3.3.16
|
+ v_3.3.16
|
||||||
- 修复一个activity启动多次,无法进行回掉的bug https://github.com/AriaLyy/Aria/issues/200
|
- 修复一个activity启动多次,无法进行回掉的bug https://github.com/AriaLyy/Aria/issues/200
|
||||||
- 优化target代码结构
|
- 优化target代码结构,移除路径被占用的提示
|
||||||
|
- 添加支持chunked模式的下载
|
||||||
+ v_3.3.14
|
+ v_3.3.14
|
||||||
- 修复ftp上传和下载的兼容性问题
|
- 修复ftp上传和下载的兼容性问题
|
||||||
- 如果url中的path有"//"将替换为"/"
|
- 如果url中的path有"//"将替换为"/"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<download>
|
<download>
|
||||||
|
|
||||||
<!--设置下载线程,线程下载数改变后,新的下载任务才会生效,如果任务大小小于1m,该设置也不会生效-->
|
<!--设置下载线程,线程下载数改变后,新的下载任务才会生效,如果任务大小小于1m,该设置也不会生效-->
|
||||||
<threadNum value="1"/>
|
<threadNum value="3"/>
|
||||||
|
|
||||||
<!--设置下载队列最大任务数, 默认为2-->
|
<!--设置下载队列最大任务数, 默认为2-->
|
||||||
<maxTaskNum value="2"/>
|
<maxTaskNum value="2"/>
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
mStart.setText("恢复");
|
mStart.setText("恢复");
|
||||||
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
|
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
|
||||||
setBtState(true);
|
setBtState(true);
|
||||||
} else if (target.isDownloading()) {
|
} else if (target.isRunning()) {
|
||||||
setBtState(false);
|
setBtState(false);
|
||||||
}
|
}
|
||||||
getBinding().setFileSize(target.getConvertFileSize());
|
getBinding().setFileSize(target.getConvertFileSize());
|
||||||
@@ -212,12 +212,12 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
startD();
|
startD();
|
||||||
break;
|
break;
|
||||||
case R.id.stop:
|
case R.id.stop:
|
||||||
//Aria.download(this).load(DOWNLOAD_URL).stop();
|
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||||
startActivity(new Intent(this, SingleTaskActivity.class));
|
//startActivity(new Intent(this, SingleTaskActivity.class));
|
||||||
//Aria.download(this).load(DOWNLOAD_URL).removeRecord();
|
//Aria.download(this).load(DOWNLOAD_URL).removeRecord();
|
||||||
break;
|
break;
|
||||||
case R.id.cancel:
|
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();
|
Aria.download(this).load(DOWNLOAD_URL).removeRecord();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user