添加CheckResult注解进行检查
pull/330/head
laoyuyu 7 years ago
commit cb1f0e730b
  1. 4
      Aria/build.gradle
  2. 19
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java
  3. 72
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java
  4. 5
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  5. 1
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  6. 9
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  7. 1
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  8. 4
      Aria/src/main/java/com/arialyy/aria/core/download/BaseDListener.java
  9. 5
      Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java
  10. 9
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java
  11. 15
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  12. 17
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  13. 21
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  14. 7
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java
  15. 8
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java
  16. 32
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  17. 20
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java
  18. 9
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  19. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  20. 4
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  21. 5
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  22. 11
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java
  23. 5
      Aria/src/main/java/com/arialyy/aria/core/inf/IFtpTarget.java
  24. 4
      Aria/src/main/java/com/arialyy/aria/core/inf/IHttpHeaderTarget.java
  25. 7
      Aria/src/main/java/com/arialyy/aria/core/manager/DGTEFactory.java
  26. 7
      Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java
  27. 10
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  28. 5
      Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
  29. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/BaseNormalTarget.java
  30. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java
  31. 6
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  32. 7
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java
  33. 2
      Aria/src/main/java/com/arialyy/aria/orm/AbsDelegate.java
  34. 51
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  35. 9
      app/src/main/AndroidManifest.xml
  36. 2
      app/src/main/assets/aria_config.xml
  37. 5
      app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java
  38. 9
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  39. 4
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
  40. 6
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java
  41. 8
      app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java
  42. 2
      app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java
  43. 2
      build.gradle

@ -26,8 +26,8 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':AriaAnnotations')
// compile 'com.arialyy.aria:aria-ftp-plug:1.0.3'
compile 'com.arialyy.aria:aria-ftp-plug:1.0.3'
compile project(':AriaFtpPlug')
// compile project(':AriaFtpPlug')
}
apply from: 'bintray-release.gradle'

@ -90,10 +90,12 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
}
/**
* 删除所有任务
* 发送等待状态
*/
void removeAll() {
mQueue.removeAllTask();
void sendWaitState(AbsTask task) {
if (task != null) {
task.getOutHandler().obtainMessage(ISchedulers.WAIT, task).sendToTarget();
}
}
/**
@ -119,6 +121,17 @@ public abstract class AbsNormalCmd<T extends AbsTaskEntity> extends AbsCmd<T> {
mQueue.cancelTask(tempTask);
}
/**
* 删除任务
*/
void removeTask(AbsTaskEntity taskEntity) {
AbsTask tempTask = getTask(taskEntity.getEntity());
if (tempTask == null){
tempTask = createTask(taskEntity);
}
mQueue.cancelTask(tempTask);
}
/**
* 启动任务
*/

@ -16,7 +16,19 @@
package com.arialyy.aria.core.command.normal;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.orm.DbEntity;
import java.util.List;
/**
* Created by AriaL on 2017/6/27.
@ -37,6 +49,64 @@ public class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
}
@Override public void executeCmd() {
removeAll();
if (!canExeCmd) return;
if (isDownloadCmd) {
removeAllDTask();
removeAllDGTask();
} else {
removeUTask();
}
}
/**
* 删除所有普通下载任务
*/
private void removeAllDTask() {
List<DownloadEntity> entities =
DbEntity.findDatas(DownloadEntity.class, "isGroupChild=?", "false");
if (entities != null && !entities.isEmpty()) {
for (DownloadEntity entity : entities) {
remove(TEManager.getInstance().getTEntity(DownloadTaskEntity.class, entity.getKey()));
}
}
}
/**
* 删除所有下载任务组任务
*/
private void removeAllDGTask() {
List<DownloadGroupEntity> entities =
DbEntity.findDatas(DownloadGroupEntity.class, "state!=?", "-1");
if (entities != null && !entities.isEmpty()) {
for (DownloadGroupEntity entity : entities) {
remove(
TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, entity.getUrls()));
}
}
}
/**
* 删除所有普通上传任务
*/
private void removeUTask() {
List<UploadEntity> entities =
DbEntity.findDatas(UploadEntity.class, "isGroupChild=?", "false");
if (entities != null && !entities.isEmpty()) {
for (UploadEntity entity : entities) {
remove(TEManager.getInstance().getTEntity(UploadTaskEntity.class, entity.getKey()));
}
}
}
private void remove(AbsTaskEntity te) {
if (te instanceof DownloadTaskEntity) {
mQueue = DownloadTaskQueue.getInstance();
} else if (te instanceof UploadTaskEntity) {
mQueue = UploadTaskQueue.getInstance();
} else if (te instanceof DownloadGroupTaskEntity) {
mQueue = DownloadGroupTaskQueue.getInstance();
}
te.setRemoveFile(removeFile);
removeTask(te);
}
}

@ -5,6 +5,7 @@ import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.download.wrapper.DGTEWrapper;
import com.arialyy.aria.core.download.wrapper.DTEWrapper;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
@ -142,8 +143,8 @@ final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
startTask(createTask(te));
} else {
te.getEntity().setState(IEntity.STATE_WAIT);
createTask(te);
sendWaitState();
AbsTask task = createTask(te);
sendWaitState(task);
}
}
}

@ -117,7 +117,6 @@ class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
}
private List<AbsTaskEntity> findWaitData(int type) {
// TODO: 2018/4/20 需要测试
List<AbsTaskEntity> waitList = new ArrayList<>();
if (type == 1) {
List<DTEWrapper> wrappers = DbEntity.findRelationData(DTEWrapper.class,

@ -69,8 +69,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
private Map<Integer, AbsThreadTask> mTask = new HashMap<>();
private Timer mTimer;
@Deprecated
private File mConfigFile;
@Deprecated private File mConfigFile;
/**
* 进度刷新间隔
*/
@ -356,6 +355,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
* 保存任务记录
*/
private void saveRecord() {
mRecord.threadNum = mRecord.threadRecords.size();
mRecord.save();
for (ThreadRecord tr : mRecord.threadRecords) {
tr.save();
@ -465,6 +465,11 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
threadId[rl] = i;
rl++;
}
if (mConstance.CURRENT_LOCATION != 0
&& mConstance.CURRENT_LOCATION != mEntity.getCurrentProgress()) {
ALog.d(TAG, "进度修正");
mEntity.setCurrentProgress(mConstance.CURRENT_LOCATION);
}
saveRecord();
startThreadTask(threadId);
}

@ -131,7 +131,6 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
* @return {@code true} 中断{@code false} 不是中断
*/
protected boolean isBreak() {
ALog.d(TAG, "任务中断");
return STATE.isCancel || STATE.isStop || taskBreak;
}

@ -34,13 +34,13 @@ import java.lang.ref.WeakReference;
class BaseDListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>, TASK extends AbsTask<TASK_ENTITY>>
implements IDownloadListener {
private static final String TAG = "BaseDListener";
protected WeakReference<Handler> outHandler;
WeakReference<Handler> outHandler;
private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
private long mLastLen = 0; //上一次发送长度
private boolean isFirst = true;
protected ENTITY mEntity;
protected TASK_ENTITY mTaskEntity;
protected TASK mTask;
private TASK mTask;
private boolean isConvertSpeed = false;
boolean isWait = false;
private long mLastSaveTime;

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.download;
import android.support.annotation.CheckResult;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.manager.SubTaskManager;
@ -49,6 +50,7 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
*
* @return 子任务管理器
*/
@CheckResult
public SubTaskManager getSubTaskManager() {
if (mSubTaskManager == null) {
mSubTaskManager = new SubTaskManager(mTargetName, mTaskEntity);
@ -59,6 +61,7 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
/**
* 设置任务组别名
*/
@CheckResult
public TARGET setGroupAlias(String alias) {
if (TextUtils.isEmpty(alias)) return (TARGET) this;
mEntity.setAlias(alias);
@ -76,6 +79,7 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
* @deprecated {@link #setDirPath(String)} 请使用这个api
*/
@Deprecated
@CheckResult
public TARGET setDownloadDirPath(String groupDirPath) {
return setDirPath(groupDirPath);
}
@ -99,6 +103,7 @@ abstract class BaseGroupTarget<TARGET extends BaseGroupTarget>
*
* @param dirPath 任务组保存文件夹路径
*/
@CheckResult
public TARGET setDirPath(String dirPath) {
mDirPathTemp = dirPath;
return (TARGET) this;

@ -19,6 +19,7 @@ import android.os.Handler;
import com.arialyy.aria.core.download.downloader.IDownloadGroupListener;
import com.arialyy.aria.core.inf.GroupSendParams;
import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.util.ALog;
/**
* Created by Aria.Lao on 2017/7/20.
@ -85,11 +86,17 @@ class DownloadGroupListener
}
private void saveCurrentLocation() {
if (mEntity.getSubEntities() == null || mEntity.getSubEntities().isEmpty()) {
ALog.w(TAG, "保存进度失败,子任务为null");
return;
}
long location = 0;
for (DownloadEntity e : mEntity.getSubEntities()) {
location += e.getCurrentProgress();
}
if (location > mEntity.getFileSize()) {
location = mEntity.getFileSize();
}
mEntity.setCurrentProgress(location);
mEntity.update();
}

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.download;
import android.support.annotation.CheckResult;
import android.text.TextUtils;
import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.util.ALog;
@ -40,7 +41,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
*/
private List<String> mSubNameTemp = new ArrayList<>();
DownloadGroupTarget(DownloadGroupEntity groupEntity, String targetName) {
public DownloadGroupTarget(DownloadGroupEntity groupEntity, String targetName) {
this.mTargetName = targetName;
if (groupEntity.getUrls() != null && !groupEntity.getUrls().isEmpty()) {
this.mUrls.addAll(groupEntity.getUrls());
@ -72,6 +73,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
*
* @param fileSize 任务组总大小
*/
@CheckResult
public DownloadGroupTarget setFileSize(long fileSize) {
if (fileSize <= 0) {
ALog.e(TAG, "文件大小不能小于 0");
@ -86,6 +88,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
/**
* 如果你是使用{@link DownloadReceiver#load(DownloadGroupEntity)}进行下载操作那么你需要设置任务组的下载地址
*/
@CheckResult
public DownloadGroupTarget setGroupUrl(List<String> urls) {
mUrls.clear();
mUrls.addAll(urls);
@ -97,6 +100,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
*
* @deprecated {@link #setSubFileName(List)} 请使用该api
*/
@CheckResult
@Deprecated public DownloadGroupTarget setSubTaskFileName(List<String> subTaskFileName) {
return setSubFileName(subTaskFileName);
}
@ -104,6 +108,7 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
/**
* 设置子任务文件名该方法必须在{@link #setDirPath(String)}之后调用否则不生效
*/
@CheckResult
public DownloadGroupTarget setSubFileName(List<String> subTaskFileName) {
if (subTaskFileName == null || subTaskFileName.isEmpty()) {
ALog.e(TAG, "修改子任务的文件名失败:列表为null");
@ -143,13 +148,9 @@ public class DownloadGroupTarget extends BaseGroupTarget<DownloadGroupTarget> {
reChangeDirPath(mDirPathTemp);
}
if (mSubNameTemp.isEmpty()) {
for (String url : mUrls) {
int lastIndex = url.lastIndexOf(File.separator);
mSubNameTemp.add(url.substring(lastIndex + 1, url.length()));
}
if (!mSubNameTemp.isEmpty()) {
updateSingleSubFileName();
}
updateSingleSubFileName();
return true;
}
return false;

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.download;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
@ -59,6 +60,7 @@ public class DownloadReceiver extends AbsReceiver {
*
* @param entity 下载实体
*/
@CheckResult
public DownloadTarget load(DownloadEntity entity) {
return load(entity, false);
}
@ -78,6 +80,7 @@ public class DownloadReceiver extends AbsReceiver {
* </code>
* </pre>
*/
@CheckResult
@Deprecated public DownloadTarget load(DownloadEntity entity, boolean refreshInfo) {
CheckUtil.checkDownloadEntity(entity);
return new DownloadTarget(entity, targetName, refreshInfo);
@ -88,6 +91,7 @@ public class DownloadReceiver extends AbsReceiver {
*
* @param url 下载地址
*/
@CheckResult
public DownloadTarget load(@NonNull String url) {
return load(url, false);
}
@ -108,6 +112,7 @@ public class DownloadReceiver extends AbsReceiver {
* </code>
* </pre>
*/
@CheckResult
@Deprecated public DownloadTarget load(@NonNull String url, boolean refreshInfo) {
CheckUtil.checkUrlInvalidThrow(url);
return new DownloadTarget(url, targetName, refreshInfo);
@ -120,6 +125,7 @@ public class DownloadReceiver extends AbsReceiver {
* @deprecated {@link #loadGroup(DownloadGroupEntity)}
*/
@Deprecated
@CheckResult
public DownloadGroupTarget load(List<String> urls) {
return loadGroup(urls);
}
@ -127,6 +133,7 @@ public class DownloadReceiver extends AbsReceiver {
/**
* 加载下载地址如果任务组的中的下载地址改变了则任务从新的一个任务组
*/
@CheckResult
public DownloadGroupTarget loadGroup(List<String> urls) {
CheckUtil.checkDownloadUrls(urls);
return new DownloadGroupTarget(urls, targetName);
@ -137,6 +144,7 @@ public class DownloadReceiver extends AbsReceiver {
*
* @param entity 下载实体
*/
@CheckResult
public FtpDownloadTarget loadFtp(DownloadEntity entity) {
return loadFtp(entity, false);
}
@ -156,6 +164,7 @@ public class DownloadReceiver extends AbsReceiver {
* </code>
* </pre>
*/
@CheckResult
@Deprecated public FtpDownloadTarget loadFtp(DownloadEntity entity, boolean refreshInfo) {
CheckUtil.checkDownloadEntity(entity);
if (!entity.getUrl().startsWith("ftp")) {
@ -167,6 +176,7 @@ public class DownloadReceiver extends AbsReceiver {
/**
* 加载ftp单任务下载地址
*/
@CheckResult
public FtpDownloadTarget loadFtp(@NonNull String url) {
return loadFtp(url, false);
}
@ -176,6 +186,7 @@ public class DownloadReceiver extends AbsReceiver {
*
* @param refreshInfo 是否刷新下载信息
*/
@CheckResult
public FtpDownloadTarget loadFtp(@NonNull String url, boolean refreshInfo) {
CheckUtil.checkUrlInvalidThrow(url);
return new FtpDownloadTarget(url, targetName, refreshInfo);
@ -189,6 +200,7 @@ public class DownloadReceiver extends AbsReceiver {
* @deprecated 请使用 {@link #loadGroup(DownloadGroupEntity)}
*/
@Deprecated
@CheckResult
public DownloadGroupTarget load(DownloadGroupEntity groupEntity) {
return loadGroup(groupEntity);
}
@ -199,6 +211,7 @@ public class DownloadReceiver extends AbsReceiver {
* @param groupEntity 如果加载的任务实体没有子项的下载地址
* 那么你需要使用{@link DownloadGroupTarget#setGroupUrl(List)}设置子项的下载地址
*/
@CheckResult
public DownloadGroupTarget loadGroup(DownloadGroupEntity groupEntity) {
return new DownloadGroupTarget(groupEntity, targetName);
}
@ -206,6 +219,7 @@ public class DownloadReceiver extends AbsReceiver {
/**
* 加载ftp文件夹下载地址
*/
@CheckResult
public FtpDirDownloadTarget loadFtpDir(@NonNull String dirUrl) {
CheckUtil.checkUrlInvalidThrow(dirUrl);
return new FtpDirDownloadTarget(dirUrl, targetName);
@ -214,7 +228,7 @@ public class DownloadReceiver extends AbsReceiver {
/**
* 将当前类注册到Aria
*/
public DownloadReceiver register() {
public void register() {
String className = obj.getClass().getName();
Set<String> dCounter = ProxyHelper.getInstance().downloadCounter;
Set<String> dgCounter = ProxyHelper.getInstance().downloadGroupCounter;
@ -226,7 +240,6 @@ public class DownloadReceiver extends AbsReceiver {
&& dgsCounter.contains(className))) {
DownloadGroupSchedulers.getInstance().register(obj);
}
return this;
}
/**

@ -15,10 +15,12 @@
*/
package com.arialyy.aria.core.download;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.delegate.HttpHeaderDelegate;
import com.arialyy.aria.core.inf.IHttpHeaderTarget;
import java.net.Proxy;
import java.util.Map;
/**
@ -29,7 +31,7 @@ public class DownloadTarget extends BaseNormalTarget<DownloadTarget>
implements IHttpHeaderTarget<DownloadTarget> {
private HttpHeaderDelegate<DownloadTarget, DownloadEntity, DownloadTaskEntity> mDelegate;
DownloadTarget(DownloadEntity entity, String targetName) {
public DownloadTarget(DownloadEntity entity, String targetName) {
this(entity, targetName, false);
}
@ -52,11 +54,23 @@ public class DownloadTarget extends BaseNormalTarget<DownloadTarget>
*
* @param use {@code true} 使用
*/
@CheckResult
public DownloadTarget useServerFileName(boolean use) {
mTaskEntity.setUseServerFileName(use);
return this;
}
/**
* 设置URL的代理
*
* @param proxy {@link Proxy}
*/
@CheckResult
public DownloadTarget setUrlProxy(Proxy proxy) {
mTaskEntity.setProxy(proxy);
return this;
}
/**
* 设置文件存储路径
* 该api后续版本会删除
@ -64,6 +78,7 @@ public class DownloadTarget extends BaseNormalTarget<DownloadTarget>
* @param downloadPath 文件保存路径
* @deprecated {@link #setFilePath(String)} 请使用这个api
*/
@CheckResult
@Deprecated public DownloadTarget setDownloadPath(@NonNull String downloadPath) {
return setFilePath(downloadPath);
}
@ -75,6 +90,7 @@ public class DownloadTarget extends BaseNormalTarget<DownloadTarget>
*
* @param filePath 路径必须为文件路径不能为文件夹路径
*/
@CheckResult
public DownloadTarget setFilePath(@NonNull String filePath) {
mTempFilePath = filePath;
return this;
@ -91,14 +107,17 @@ public class DownloadTarget extends BaseNormalTarget<DownloadTarget>
return HTTP;
}
@CheckResult
@Override public DownloadTarget addHeader(@NonNull String key, @NonNull String value) {
return mDelegate.addHeader(key, value);
}
@CheckResult
@Override public DownloadTarget addHeaders(Map<String, String> headers) {
return mDelegate.addHeaders(headers);
}
@CheckResult
@Override public DownloadTarget setRequestMode(RequestEnum requestEnum) {
return mDelegate.setRequestMode(requestEnum);
}

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.download;
import android.support.annotation.CheckResult;
import android.text.TextUtils;
import com.arialyy.aria.core.delegate.FtpDelegate;
import com.arialyy.aria.core.inf.AbsTaskEntity;
@ -89,15 +90,15 @@ public class FtpDirDownloadTarget extends BaseGroupTarget<FtpDirDownloadTarget>
}
return true;
}
@CheckResult
@Override public FtpDirDownloadTarget charSet(String charSet) {
return mDelegate.charSet(charSet);
}
@CheckResult
@Override public FtpDirDownloadTarget login(String userName, String password) {
return mDelegate.login(userName, password);
}
@CheckResult
@Override public FtpDirDownloadTarget login(String userName, String password, String account) {
return mDelegate.login(userName, password, account);
}

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.download;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import com.arialyy.aria.core.delegate.FtpDelegate;
import com.arialyy.aria.core.inf.AbsTaskEntity;
@ -29,7 +30,7 @@ public class FtpDownloadTarget extends BaseNormalTarget<FtpDownloadTarget>
implements IFtpTarget<FtpDownloadTarget> {
private FtpDelegate<FtpDownloadTarget, DownloadEntity, DownloadTaskEntity> mDelegate;
FtpDownloadTarget(DownloadEntity entity, String targetName, boolean refreshInfo) {
public FtpDownloadTarget(DownloadEntity entity, String targetName, boolean refreshInfo) {
this(entity.getUrl(), targetName, refreshInfo);
}
@ -59,6 +60,7 @@ public class FtpDownloadTarget extends BaseNormalTarget<FtpDownloadTarget>
* @deprecated {@link #setFilePath(String)} 请使用这个api
*/
@Deprecated
@CheckResult
public FtpDownloadTarget setDownloadPath(@NonNull String filePath) {
return setFilePath(filePath);
}
@ -69,6 +71,7 @@ public class FtpDownloadTarget extends BaseNormalTarget<FtpDownloadTarget>
* 1如果保存路径是该文件的保存路径/mnt/sdcard/file.zip则使用路径中的文件名file.zip
* 2如果保存路径是文件夹路径/mnt/sdcard/则使用FTP服务器该文件的文件名
*/
@CheckResult
public FtpDownloadTarget setFilePath(@NonNull String filePath) {
mTempFilePath = filePath;
return this;
@ -78,14 +81,17 @@ public class FtpDownloadTarget extends BaseNormalTarget<FtpDownloadTarget>
return FTP;
}
@CheckResult
@Override public FtpDownloadTarget charSet(String charSet) {
return mDelegate.charSet(charSet);
}
@CheckResult
@Override public FtpDownloadTarget login(String userName, String password) {
return mDelegate.login(userName, password);
}
@CheckResult
@Override public FtpDownloadTarget login(String userName, String password, String account) {
return mDelegate.login(userName, password, account);
}

@ -44,11 +44,11 @@ public abstract class AbsGroupUtil implements IUtil {
/**
* FTP文件夹
*/
protected int FTP_DIR = 0xa1;
int FTP_DIR = 0xa1;
/**
* HTTP 任务组
*/
protected int HTTP_GROUP = 0xa2;
int HTTP_GROUP = 0xa2;
/**
* 任务组所有任务总长度
@ -57,7 +57,7 @@ public abstract class AbsGroupUtil implements IUtil {
long mCurrentLocation = 0;
private ExecutorService mExePool;
protected IDownloadGroupListener mListener;
protected DownloadGroupTaskEntity mGTEntity;
DownloadGroupTaskEntity mGTEntity;
private boolean isRunning = false;
private Timer mTimer;
/**
@ -266,7 +266,7 @@ public abstract class AbsGroupUtil implements IUtil {
}
/**
* 预处理操作由于属性的不同http任务组在构造函数中就可以完成了
* 预处理操作
* 而FTP文件夹的需要获取完成所有子任务信息才算预处理完成
*/
protected void onPre() {
@ -302,7 +302,6 @@ public abstract class AbsGroupUtil implements IUtil {
@Override public void resume() {
start();
mListener.onResume(mCurrentLocation);
}
@Override public void setMaxSpeed(double maxSpeed) {
@ -329,7 +328,11 @@ public abstract class AbsGroupUtil implements IUtil {
void startRunningFlow() {
closeTimer(true);
mListener.onPostPre(mTotalLen);
mListener.onStart(mCurrentLocation);
if (mCurrentLocation > 0) {
mListener.onResume(mCurrentLocation);
} else {
mListener.onStart(mCurrentLocation);
}
startTimer();
}
@ -340,7 +343,16 @@ public abstract class AbsGroupUtil implements IUtil {
if (!isRunning) {
closeTimer(false);
} else if (mCurrentLocation >= 0) {
mListener.onProgress(mCurrentLocation);
long t = 0;
for (DownloadTaskEntity te : mGTEntity.getSubTaskEntities()) {
if (te.getState() == IEntity.STATE_COMPLETE) {
t += te.getEntity().getFileSize();
} else {
t += te.getEntity().getCurrentProgress();
}
}
mCurrentLocation = t;
mListener.onProgress(t);
}
}
}, 0, mUpdateInterval);
@ -349,8 +361,8 @@ public abstract class AbsGroupUtil implements IUtil {
/**
* 创建子任务下载器默认创建完成自动启动
*/
Downloader createChildDownload(DownloadTaskEntity taskEntity) {
return createChildDownload(taskEntity, true);
void createChildDownload(DownloadTaskEntity taskEntity) {
createChildDownload(taskEntity, true);
}
/**
@ -415,7 +427,7 @@ public abstract class AbsGroupUtil implements IUtil {
@Override public void onProgress(long currentLocation) {
long speed = currentLocation - lastLen;
mCurrentLocation += speed;
//mCurrentLocation += speed;
subEntity.setCurrentProgress(currentLocation);
handleSpeed(speed);
mListener.onSubRunning(subEntity);

@ -16,7 +16,9 @@
package com.arialyy.aria.core.download.downloader;
import android.text.TextUtils;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.util.SSLContextUtil;
import java.io.IOException;
import java.io.InputStream;
@ -44,7 +46,7 @@ class ConnectionHelp {
* @throws IOException
*/
static InputStream convertInputStream(HttpURLConnection connection) throws IOException {
String encoding = connection.getContentEncoding();
String encoding = connection.getHeaderField("Content-Encoding");
if (TextUtils.isEmpty(encoding)) {
return connection.getInputStream();
}
@ -62,9 +64,14 @@ class ConnectionHelp {
*
* @throws IOException
*/
static HttpURLConnection handleConnection(URL url) throws IOException {
static HttpURLConnection handleConnection(URL url, AbsTaskEntity taskEntity) throws IOException {
HttpURLConnection conn;
URLConnection urlConn = url.openConnection();
URLConnection urlConn;
if (taskEntity.getProxy() != null) {
urlConn = url.openConnection(taskEntity.getProxy());
} else {
urlConn = url.openConnection();
}
if (urlConn instanceof HttpsURLConnection) {
conn = (HttpsURLConnection) urlConn;
SSLContext sslContext =
@ -86,9 +93,10 @@ class ConnectionHelp {
*
* @throws ProtocolException
*/
static HttpURLConnection setConnectParam(DownloadTaskEntity entity, HttpURLConnection conn)
throws ProtocolException {
conn.setRequestMethod(entity.getRequestEnum().name);
static HttpURLConnection setConnectParam(DownloadTaskEntity entity, HttpURLConnection conn) {
if (entity.getRequestEnum() == RequestEnum.POST) {
conn.setDoInput(true);
}
Set<String> keys = null;
if (entity.getHeaders() != null && entity.getHeaders().size() > 0) {
keys = entity.getHeaders().keySet();

@ -43,6 +43,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
*/
private int mInitFailNum;
private boolean isStop = false;
private boolean isStart = false;
/**
* 文件信息回调组
@ -52,7 +53,6 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
public DownloadGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity taskEntity) {
super(listener, taskEntity);
mInfoPool = Executors.newCachedThreadPool();
onPre();
}
@Override int getTaskType() {
@ -76,7 +76,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
}
@Override protected void onStart() {
super.onStart();
onPre();
isStop = false;
if (mCompleteNum == mGroupSize) {
mListener.onComplete();
@ -161,13 +161,14 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
*/
private void checkStartFlow() {
synchronized (DownloadGroupUtil.class) {
if (mInitFailNum == mGroupSize){
if (mInitFailNum == mExeMap.size()) {
closeTimer(false);
mListener.onFail(true);
}
if (mInitCompleteNum + mInitFailNum == mGroupSize || !isNeedLoadFileSize) {
if (!isStart && mInitCompleteNum + mInitFailNum == mExeMap.size() || !isNeedLoadFileSize) {
startRunningFlow();
updateFileSize();
isStart = true;
}
}
}

@ -54,7 +54,7 @@ class HttpFileInfoThread implements Runnable {
HttpURLConnection conn = null;
try {
URL url = new URL(CommonUtil.convertUrl(mEntity.getUrl()));
conn = ConnectionHelp.handleConnection(url);
conn = ConnectionHelp.handleConnection(url, mTaskEntity);
conn = ConnectionHelp.setConnectParam(mTaskEntity, conn);
conn.setRequestProperty("Range", "bytes=" + 0 + "-");
conn.setConnectTimeout(mConnectTimeOut);

@ -65,7 +65,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
mChildCurrentLocation = mConfig.START_LOCATION;
try {
URL url = new URL(CommonUtil.convertUrl(mConfig.URL));
conn = ConnectionHelp.handleConnection(url);
conn = ConnectionHelp.handleConnection(url, mTaskEntity);
if (mConfig.SUPPORT_BP) {
ALog.d(TAG,
String.format("任务【%s】线程__%s__开始下载【开始位置 : %s,结束位置:%s】", mConfig.TEMP_FILE.getName(),
@ -79,7 +79,7 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
conn = ConnectionHelp.setConnectParam(mConfig.TASK_ENTITY, conn);
conn.setConnectTimeout(mConnectTimeOut);
conn.setReadTimeout(mReadTimeOut); //设置读取流的等待时间,必须设置该参数
conn.connect();
is = new BufferedInputStream(ConnectionHelp.convertInputStream(conn));
if (isOpenDynamicFile) {
readDynamicFile(is);

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.inf;
import android.support.annotation.CheckResult;
import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.ICmd;
@ -34,7 +35,7 @@ import java.util.List;
*/
public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity>
implements ITarget<TARGET> {
protected String TAG = "";
protected String TAG ;
protected ENTITY mEntity;
protected TASK_ENTITY mTaskEntity;
protected String mTargetName;
@ -48,6 +49,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
* 注意如果在后续方法调用链中没有调用 {@link #start()}{@link #stop()}{@link #cancel()}{@link #resume()}
* 等操作任务的方法那么你需要调用{@link #save()}才能将修改保存到数据库
*/
@CheckResult(suggest = "after use #start()、#stop()、#cancel()、#resume()、#save()?")
public TARGET resetState() {
mTaskEntity.getEntity().setState(IEntity.STATE_WAIT);
mTaskEntity.setRefreshInfo(true);
@ -102,6 +104,7 @@ public abstract class AbsTarget<TARGET extends AbsTarget, ENTITY extends AbsEnti
*
* @param str 扩展数据
*/
@CheckResult(suggest = "after use #start()、#stop()、#cancel()、#resume()、#save()?")
public TARGET setExtendField(String str) {
if (TextUtils.isEmpty(str)) return (TARGET) this;
if (TextUtils.isEmpty(mEntity.getStr()) || !mEntity.getStr().equals(str)) {

@ -19,6 +19,7 @@ import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.annotation.Ignore;
import java.net.Proxy;
import java.util.HashMap;
import java.util.Map;
@ -124,6 +125,8 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
*/
private int code;
@Ignore private Proxy proxy;
public abstract ENTITY getEntity();
/**
@ -135,6 +138,14 @@ public abstract class AbsTaskEntity<ENTITY extends AbsEntity> extends DbEntity {
return getEntity().getState();
}
public Proxy getProxy() {
return proxy;
}
public void setProxy(Proxy proxy) {
this.proxy = proxy;
}
public abstract String getKey();
public abstract void setKey(String key);

@ -15,6 +15,8 @@
*/
package com.arialyy.aria.core.inf;
import android.support.annotation.CheckResult;
/**
* Created by laoyuyu on 2018/3/9.
*/
@ -22,6 +24,7 @@ public interface IFtpTarget<TARGET extends ITarget> {
/**
* 设置字符编码
*/
@CheckResult
TARGET charSet(String charSet);
/**
@ -30,6 +33,7 @@ public interface IFtpTarget<TARGET extends ITarget> {
* @param userName ftp用户名
* @param password ftp用户密码
*/
@CheckResult
TARGET login(String userName, String password);
/**
@ -39,5 +43,6 @@ public interface IFtpTarget<TARGET extends ITarget> {
* @param password ftp用户密码
* @param account ftp账号
*/
@CheckResult
TARGET login(String userName, String password, String account);
}

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.inf;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.download.DownloadEntity;
@ -33,6 +34,7 @@ public interface IHttpHeaderTarget<TARGET extends ITarget> {
* @param key header对应的key
* @param value header对应的value
*/
@CheckResult
TARGET addHeader(@NonNull String key, @NonNull String value);
/**
@ -41,6 +43,7 @@ public interface IHttpHeaderTarget<TARGET extends ITarget> {
*
* @param headers 一组http header数据
*/
@CheckResult
TARGET addHeaders(Map<String, String> headers);
/**
@ -48,5 +51,6 @@ public interface IHttpHeaderTarget<TARGET extends ITarget> {
*
* @param requestEnum {@link RequestEnum}
*/
@CheckResult
TARGET setRequestMode(RequestEnum requestEnum);
}

@ -23,6 +23,7 @@ import com.arialyy.aria.core.download.wrapper.DGEWrapper;
import com.arialyy.aria.core.download.wrapper.DGTEWrapper;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -156,10 +157,12 @@ class DGTEFactory implements IGTEFactory<DownloadGroupEntity, DownloadGroupTaskE
private List<DownloadEntity> createSubTask(String groupName, List<String> urls) {
List<DownloadEntity> list = new ArrayList<>();
for (int i = 0, len = urls.size(); i < len; i++) {
String url = urls.get(i);
DownloadEntity entity = new DownloadEntity();
entity.setUrl(urls.get(i));
entity.setUrl(url);
entity.setDownloadPath(groupName + "_" + i);
entity.setFileName(groupName + "_" + i);
int lastIndex = url.lastIndexOf(File.separator);
entity.setFileName(url.substring(lastIndex + 1, url.length()));
entity.setGroupName(groupName);
entity.setGroupChild(true);
list.add(entity);

@ -165,7 +165,7 @@ public class TEManager {
/**
* 从缓存中获取单任务实体如果任务实体不存在则创建任务实体
*
* @return 创建失败返回null
* @return 创建失败返回null成功返回{@link DownloadTaskEntity}或者{@link UploadTaskEntity}
*/
public <TE extends AbsTaskEntity> TE getTEntity(Class<TE> clazz, String key) {
final Lock lock = this.lock;
@ -185,7 +185,7 @@ public class TEManager {
/**
* 从缓存中获取FTP文件夹任务实体如果任务实体不存在则创建任务实体
*
* @return 创建失败返回null
* @return 创建失败返回null成功返回{@link DownloadTaskEntity}
*/
public <TE extends AbsTaskEntity> TE getFDTEntity(Class<TE> clazz, String key) {
final Lock lock = this.lock;
@ -204,9 +204,10 @@ public class TEManager {
/**
* 从缓存中获取HTTP任务组的任务实体如果任务实体不存在则创建任务实体
* 获取{}
*
* @param urls HTTP任务组的子任务下载地址列表
* @return 地址列表为null或创建实体失败返回null
* @return 地址列表为null或创建实体失败返回null成功返回{@link DownloadGroupTaskEntity}
*/
public <TE extends AbsTaskEntity> TE getGTEntity(Class<TE> clazz, List<String> urls) {
if (urls == null || urls.isEmpty()) {

@ -46,16 +46,6 @@ abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
return mExecutePool.getTask(key) != null;
}
@Override public void removeAllTask() {
for (String key : mExecutePool.getAllTask().keySet()) {
TASK task = mExecutePool.getAllTask().get(key);
if (task != null) task.cancel();
}
for (String key : mCachePool.getAllTask().keySet()) {
mCachePool.removeTask(key);
}
}
/**
* 恢复任务
* 如果执行队列任务未满则直接启动任务

@ -52,11 +52,6 @@ public interface ITaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEnt
*/
void stopAllTask();
/**
* 删除所有任务
*/
void removeAllTask();
/**
* 开始任务
*

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.upload;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.arialyy.aria.core.manager.TEManager;
@ -44,6 +45,7 @@ abstract class BaseNormalTarget<TARGET extends AbsUploadTarget>
*
* @param uploadUrl 上传路径
*/
@CheckResult
public TARGET setUploadUrl(@NonNull String uploadUrl) {
mTempUrl = uploadUrl;
return (TARGET) this;

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.upload;
import android.support.annotation.CheckResult;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.delegate.FtpDelegate;
@ -69,6 +70,7 @@ public class FtpUploadTarget extends BaseNormalTarget<FtpUploadTarget>
return true;
}
@CheckResult
@Override public FtpUploadTarget charSet(String charSet) {
return mDelegate.charSet(charSet);
}

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.upload;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.ICmd;
@ -41,6 +42,7 @@ public class UploadReceiver extends AbsReceiver<UploadEntity> {
*
* @param filePath 文件路径
*/
@CheckResult
public UploadTarget load(@NonNull String filePath) {
CheckUtil.checkUploadPath(filePath);
return new UploadTarget(filePath, targetName);
@ -51,6 +53,7 @@ public class UploadReceiver extends AbsReceiver<UploadEntity> {
*
* @param filePath 文件路径
*/
@CheckResult
public FtpUploadTarget loadFtp(@NonNull String filePath) {
CheckUtil.checkUploadPath(filePath);
return new FtpUploadTarget(filePath, targetName);
@ -129,13 +132,12 @@ public class UploadReceiver extends AbsReceiver<UploadEntity> {
/**
* 将当前类注册到Aria
*/
public UploadReceiver register() {
public void register() {
String className = obj.getClass().getName();
Set<String> cCounter = ProxyHelper.getInstance().uploadCounter;
if (cCounter != null && cCounter.contains(className)) {
UploadSchedulers.getInstance().register(obj);
}
return this;
}
/**

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.core.upload;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.delegate.HttpHeaderDelegate;
@ -47,6 +48,7 @@ public class UploadTarget extends BaseNormalTarget<UploadTarget>
/**
* 设置userAgent
*/
@CheckResult
public UploadTarget setUserAngent(@NonNull String userAgent) {
mTaskEntity.setUserAgent(userAgent);
return this;
@ -57,6 +59,7 @@ public class UploadTarget extends BaseNormalTarget<UploadTarget>
*
* @param attachment 附件key
*/
@CheckResult
public UploadTarget setAttachment(@NonNull String attachment) {
mTaskEntity.setAttachment(attachment);
return this;
@ -67,19 +70,23 @@ public class UploadTarget extends BaseNormalTarget<UploadTarget>
*
* @param contentType tipmultipart/form-data
*/
@CheckResult
public UploadTarget setContentType(String contentType) {
mTaskEntity.setContentType(contentType);
return this;
}
@CheckResult
@Override public UploadTarget addHeader(@NonNull String key, @NonNull String value) {
return mDelegate.addHeader(key, value);
}
@CheckResult
@Override public UploadTarget addHeaders(Map<String, String> headers) {
return mDelegate.addHeaders(headers);
}
@CheckResult
@Override public UploadTarget setRequestMode(RequestEnum requestEnum) {
return mDelegate.setRequestMode(requestEnum);
}

@ -48,7 +48,7 @@ abstract class AbsDelegate {
* @param type {@link DelegateWrapper}
*/
static void print(int type, String sql) {
if (!ALog.DEBUG) {
if (ALog.DEBUG) {
return;
}
String str = "";

@ -23,6 +23,7 @@ import android.net.Uri;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.command.ICmd;
@ -33,7 +34,6 @@ import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.common.TaskRecord;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.AbsGroupEntity;
import com.arialyy.aria.core.inf.AbsGroupTaskEntity;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity;
@ -53,17 +53,14 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -378,14 +375,13 @@ public class CommonUtil {
* @param removeFile {@code true} 不仅删除任务数据库记录还会删除已经删除完成的文件
* {@code false}如果任务已经完成只删除任务数据库记录
*/
public static void delGroupTaskRecord(boolean removeFile, AbsGroupEntity groupEntity) {
public static void delGroupTaskRecord(boolean removeFile, DownloadGroupEntity groupEntity) {
if (groupEntity == null) {
ALog.e(TAG, "删除下载任务组记录失败,任务组实体为null");
return;
}
List<TaskRecord> records = DbEntity.findDatas(TaskRecord.class,
groupEntity instanceof DownloadGroupEntity ? "dGroupName=?" : "uGroupName=?",
groupEntity.getGroupName());
List<TaskRecord> records =
DbEntity.findDatas(TaskRecord.class, "dGroupName=?", groupEntity.getGroupName());
if (records == null || records.isEmpty()) {
ALog.w(TAG, "组任务记录删除失败,记录为null");
@ -395,16 +391,20 @@ public class CommonUtil {
}
}
File dir = new File(groupEntity.getDirPath());
if (removeFile) {
if (dir.exists()) {
dir.delete();
}
} else {
if (!groupEntity.isComplete()) {
dir.delete();
List<DownloadEntity> subs = groupEntity.getSubEntities();
if (subs != null) {
for (DownloadEntity sub : subs) {
File file = new File(sub.getDownloadPath());
Log.d(TAG, "exist == " + file.exists() + ", rf == " + removeFile + ", complete = " + sub.isComplete());
if (file.exists() && (removeFile || !sub.isComplete())) {
file.delete();
}
}
}
File dir = new File(groupEntity.getDirPath());
if (dir.exists() && (removeFile || !groupEntity.isComplete())) {
dir.delete();
}
groupEntity.deleteData();
}
@ -414,8 +414,7 @@ public class CommonUtil {
* @param removeFile {@code true} 不仅删除任务数据库记录还会删除已经完成的文件
* {@code false}如果任务已经完成只删除任务数据库记录
*/
public static void delTaskRecord(TaskRecord record, boolean removeFile,
AbsNormalEntity dEntity) {
public static void delTaskRecord(TaskRecord record, boolean removeFile, AbsNormalEntity dEntity) {
if (dEntity == null) return;
File file;
if (dEntity instanceof DownloadEntity) {
@ -426,16 +425,8 @@ public class CommonUtil {
ALog.w(TAG, "删除记录失败,未知类型");
return;
}
if (removeFile) {
if (file.exists()) {
file.delete();
}
} else {
if (!dEntity.isComplete()) {
if (file.exists()) {
file.delete();
}
}
if (file.exists() && (removeFile || !dEntity.isComplete())) {
file.delete();
}
if (record != null) {
@ -869,7 +860,9 @@ public class CommonUtil {
}
TaskRecord record = DbHelper.getTaskRecord(oldPath);
if (record == null) {
ALog.w(TAG, "修改任务记录失败,文件【" + oldPath + "】对应的任务记录不存在");
if (new File(oldPath).exists()) {
ALog.w(TAG, "修改任务记录失败,文件【" + oldPath + "】对应的任务记录不存在");
}
return;
}
record.filePath = newPath;

@ -13,12 +13,13 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<!--android:name=".test.TestGroupActivity"-->
<!--android:name=".MainActivity"-->
<!--android:name=".test.TestActivity"-->
<!--android:name=".test.AnyRunActivity"-->
<!--android:name=".test.AnyRunActivity"-->
<!--android:name=".test.TestGroupActivity"-->
<!--android:name=".MainActivity"-->
<!--android:name=".download.group.DownloadGroupActivity"-->
<activity
android:name=".download.group.DownloadGroupActivity"
android:name=".test.AnyRunActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

@ -25,7 +25,7 @@
<threadNum value="1"/>
<!--设置下载队列最大任务数, 默认为2-->
<maxTaskNum value="2"/>
<maxTaskNum value="1"/>
<!--设置下载失败,重试次数,默认为10-->
<reTryNum value="2"/>

@ -62,10 +62,11 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
Aria.download(this).loadFtp(URL, true)
//.login("sxf", "B34VdGsJ")
.login("lao", "123456")
.setFilePath("/mnt/sdcard/").start();
.setFilePath("");
//.setFilePath("/mnt/sdcard/").start();
break;
case R.id.stop:
Aria.download(this).loadFtp(URL).stop();
Aria.download(this).loadFtp(URL);
break;
case R.id.cancel:
Aria.download(this).loadFtp(URL).cancel();

@ -49,8 +49,9 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
//"https://static.donguo.me//video/ip/course/pfys_1.mp4";
//"https://www.baidu.com/link?url=_LFCuTPtnzFxVJByJ504QymRywIA1Z_T5xUxe9ZLuxcGM0C_RcdpWyB1eGjbJC-e5wv5wAKM4WmLMAS5KeF6EZJHB8Va3YqZUiaErqK_pxm&wd=&eqid=e8583fe70002d126000000065a99f864";
"https://d.pcs.baidu.com/file/a02c89a2d479d4fd2756f3313d42491d?fid=4232431903-250528-1114369760340736&dstime=1525491372&rt=sh&sign=FDtAERVY-DCb740ccc5511e5e8fedcff06b081203-3C13vkOkuk4TqXvVYW05zj1K0ao%3D&expires=8h&chkv=1&chkbd=0&chkpc=et&dp-logid=8651730921842106225&dp-callid=0&r=165533013";
//"https://d.pcs.baidu.com/file/a02c89a2d479d4fd2756f3313d42491d?fid=4232431903-250528-1114369760340736&dstime=1525491372&rt=sh&sign=FDtAERVY-DCb740ccc5511e5e8fedcff06b081203-3C13vkOkuk4TqXvVYW05zj1K0ao%3D&expires=8h&chkv=1&chkbd=0&chkpc=et&dp-logid=8651730921842106225&dp-callid=0&r=165533013";
//"http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1";
"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
@Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop;
@Bind(R.id.cancel) Button mCancel;
@ -238,8 +239,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//.addHeader("Accept-Encoding", "gzip, deflate")
//.addHeader("DNT", "1")
//.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0")
.useServerFileName(true)
.setRequestMode(RequestEnum.GET)
//.useServerFileName(true)
//.setRequestMode(RequestEnum.GET)
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg3.apk")
//.resetState()
.start();

@ -297,7 +297,7 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
Aria.download(getContext()).load((DownloadEntity) entity).start();
break;
case AbsTaskEntity.DG_HTTP:
Aria.download(getContext()).load((DownloadGroupEntity) entity).start();
Aria.download(getContext()).loadGroup((DownloadGroupEntity) entity).start();
break;
}
}
@ -314,7 +314,7 @@ public class DownloadAdapter extends AbsRVAdapter<AbsEntity, DownloadAdapter.Sim
Aria.download(getContext()).load((DownloadEntity) entity).stop();
break;
case AbsTaskEntity.DG_HTTP:
Aria.download(getContext()).load((DownloadGroupEntity) entity).stop();
Aria.download(getContext()).loadGroup((DownloadGroupEntity) entity).stop();
break;
}
}

@ -29,6 +29,7 @@ import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMultiDownloadBinding;
@ -115,6 +116,11 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
mAdapter.updateState(task.getEntity());
}
@DownloadGroup.onWait void groupTaskWait(DownloadGroupTask task) {
ALog.d(TAG, String.format("group【%s】wait", task.getTaskName()));
mAdapter.updateState(task.getEntity());
}
@DownloadGroup.onTaskResume void groupTaskResume(DownloadGroupTask task) {
mAdapter.updateState(task.getEntity());
}

@ -21,11 +21,11 @@ public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
//String URL = "http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk";
//String URL = "http://58.213.157.242:8081/sims_file/rest/v1/file/mshd_touchscreen_ms/guideFile/41c33556-dc4a-4d78-bb76-b9f627f94448.mp4/%E5%85%AB%E5%8D%A6%E6%B4%B2%E5%8D%97%E4%BA%AC%E5%86%9C%E4%B8%9A%E5%98%89%E5%B9%B4%E5%8D%8E0511.mp4";
//String URL = "http://d1.showself.com/download/showself_android-s236279_release.apk";
//String URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
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://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]猩球崛起3:终极之战BD国英双语中英双字.mkv";
//String URL = "ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]猩球崛起3:终极之战BD国英双语中英双字.mkv";
@Override protected int setLayoutId() {
return R.layout.activity_test;
@ -51,8 +51,8 @@ public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
//}
//for (int i = 0; i < 10; i++) {
module.startFtp(URL);
//module.start(URL);
//module.startFtp(URL);
module.start(URL);
//}
//List<AbsEntity> list = Aria.download(this).getTotalTaskList();
//ALog.d(TAG, "size ==> " + list.size());

@ -10,6 +10,7 @@ import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.L;
import java.io.File;
import java.net.Proxy;
/**
* Created by laoyuyu on 2018/4/13.
@ -68,6 +69,7 @@ public class AnyRunnModule {
.load(url)
//.addHeader("Accept-Encoding", "gzip")
.setRequestMode(RequestEnum.GET)
.setUrlProxy(Proxy.NO_PROXY)
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/abcds.exe")
//.resetState()
.start();

@ -39,7 +39,7 @@ task clean(type: Delete) {
ext {
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
publishVersion = '3.4.1'
publishVersion = '3.4.2_dev1'
// publishVersion = '1.0.3' //FTP插件
repoName='maven'
desc = 'android 下载框架'

Loading…
Cancel
Save