添加chunled 支持

pull/330/head
laoyuyu 7 years ago
parent 402086d7dd
commit f2e566ba7e
  1. 6
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  2. 2
      Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java
  3. 12
      Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java
  4. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  5. 8
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java
  6. 21
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  7. 9
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  8. 2
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  9. 3
      DEV_LOG.md
  10. 2
      app/src/main/assets/aria_config.xml
  11. 8
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java

@ -129,11 +129,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
final int num =
mEntity.getFileSize() <= SUB_LEN || mTaskEntity.requestType == AbsTaskEntity.D_FTP_DIR ? 1
: AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum();
if (mTaskEntity instanceof DownloadTaskEntity && ((DownloadTaskEntity) mTaskEntity).isChunked) {
mStartThreadNum = 1;
} else {
mStartThreadNum = num;
}
mStartThreadNum = num;
return num;
}

@ -38,7 +38,7 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
/**
* 文件夹临时路径
*/
private String mDirPathTemp;
protected String mDirPathTemp;
private SubTaskManager mSubTaskManager;

@ -47,6 +47,9 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
}
mEntity = mTaskEntity.entity;
mTaskEntity.refreshInfo = refreshInfo;
if (mEntity != null) {
mTempFilePath = mEntity.getDownloadPath();
}
}
/**
@ -61,6 +64,9 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
}
mEntity = mTaskEntity.entity;
mTaskEntity.refreshInfo = refreshInfo;
if (mEntity != null) {
mTempFilePath = mEntity.getDownloadPath();
}
}
/**
@ -97,8 +103,7 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
*
* @deprecated {@link #isRunning()}
*/
@Deprecated
public boolean isDownloading() {
@Deprecated public boolean isDownloading() {
return isRunning();
}
@ -121,8 +126,7 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
*
* @return {@code true}合法
*/
@Override
protected boolean checkEntity() {
@Override protected boolean checkEntity() {
return getTargetType() < GROUP_HTTP && checkUrl() && checkFilePath();
}

@ -56,6 +56,10 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
TEManager.getInstance().createTEntity(DownloadGroupTaskEntity.class, groupEntity);
}
mEntity = mTaskEntity.entity;
if (mEntity != null) {
mDirPathTemp = mEntity.getDirPath();
}
}
DownloadGroupTarget(List<String> urls, String targetName) {

@ -26,8 +26,8 @@ import com.arialyy.aria.util.ALog;
* Created by Aria.Lao on 2017/7/26.
* ftp文件夹下载
*/
public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget> implements
IFtpTarget<FtpDirDownloadTarget> {
public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget>
implements IFtpTarget<FtpDirDownloadTarget> {
private final String TAG = "FtpDirDownloadTarget";
private FtpDelegate<FtpDirDownloadTarget, DownloadGroupEntity, DownloadGroupTaskEntity> mDelegate;
@ -44,7 +44,9 @@ public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget>
}
mTaskEntity.requestType = AbsTaskEntity.D_FTP_DIR;
mEntity = mTaskEntity.entity;
if (mEntity != null) {
mDirPathTemp = mEntity.getDirPath();
}
mDelegate = new FtpDelegate<>(this, mTaskEntity);
}

@ -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<String, List<String>> headers = conn.getHeaderFields();
//Map<String, List<String>> 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)) {

@ -90,7 +90,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
if (STATE.isCancel || STATE.isStop) {
return;
}
handleStop();
handleComplete();
} catch (MalformedURLException e) {
fail(mChildCurrentLocation, "下载链接异常", e);
} catch (IOException e) {
@ -116,10 +116,11 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
/**
* 读取chunk模式的文件流
* @deprecated 暂时先这样处理无chun
*/
private void readChunk(InputStream is, RandomAccessFile file)
throws IOException, InterruptedException {
readNormal(is, file);
}
/**
@ -142,11 +143,11 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
}
/**
* 处理暂停或完成配置文件的更新或事件回调
* 处理完成配置文件的更新或事件回调
*
* @throws IOException
*/
private void handleStop() throws IOException {
private void handleComplete() throws IOException {
//支持断点的处理
if (mConfig.SUPPORT_BP) {
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) {
if (!mObservers.containsKey(obj.getClass().getName())) {
if (!mObservers.containsKey(getKey(obj))) {
return;
}
for (Iterator<Map.Entry<String, AbsSchedulerListener<TASK, AbsNormalEntity>>> iter =

@ -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有"//"将替换为"/"

@ -5,7 +5,7 @@
<download>
<!--设置下载线程,线程下载数改变后,新的下载任务才会生效,如果任务大小小于1m,该设置也不会生效-->
<threadNum value="1"/>
<threadNum value="3"/>
<!--设置下载队列最大任务数, 默认为2-->
<maxTaskNum value="2"/>

@ -200,7 +200,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
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<ActivitySingleBinding> {
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;
}

Loading…
Cancel
Save