From 7f52271ee5d1361415a5363f7e27e23f95a1ed68 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Wed, 16 Jan 2019 22:09:21 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=BB=E5=8A=A1=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=EF=BC=8C=E7=A7=BB=E9=99=A4=E4=BB=BB=E5=8A=A1=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E4=BF=9D=E5=AD=98=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/arialyy/aria/core/AriaManager.java | 8 +- .../com/arialyy/aria/core/FtpUrlEntity.java | 2 - .../com/arialyy/aria/core/command/AbsCmd.java | 6 +- .../aria/core/command/AbsCmdFactory.java | 4 +- .../aria/core/command/group/AbsGroupCmd.java | 14 +- .../core/command/group/GroupCancelCmd.java | 4 +- .../core/command/group/GroupCmdFactory.java | 16 +- .../core/command/group/GroupStartCmd.java | 11 +- .../aria/core/command/group/GroupStopCmd.java | 4 +- .../core/command/normal/AbsNormalCmd.java | 31 +- .../aria/core/command/normal/AddCmd.java | 6 +- .../core/command/normal/CancelAllCmd.java | 24 +- .../aria/core/command/normal/CancelCmd.java | 6 +- .../command/normal/HighestPriorityCmd.java | 5 +- .../core/command/normal/NormalCmdFactory.java | 6 +- .../core/command/normal/ResumeAllCmd.java | 43 ++- .../aria/core/command/normal/StartCmd.java | 36 +-- .../aria/core/command/normal/StopAllCmd.java | 4 +- .../aria/core/command/normal/StopCmd.java | 6 +- .../arialyy/aria/core/common/AbsFileer.java | 10 +- .../aria/core/common/AbsThreadTask.java | 14 +- .../aria/core/common/BaseListener.java | 8 +- .../aria/core/common/SubThreadConfig.java | 4 +- .../core/common/ftp/AbsFtpInfoThread.java | 44 +-- .../core/common/ftp/AbsFtpThreadTask.java | 14 +- .../aria/core/common/ftp/FTPSConfig.java | 2 +- .../aria/core/common/ftp/FtpDelegate.java | 6 +- .../aria/core/common/ftp/FtpTaskDelegate.java | 62 ++++ .../aria/core/common/http/BaseTarget.java | 80 +++++ .../aria/core/common/http/GetDelegate.java | 62 +--- .../core/common/http/HttpHeaderDelegate.java | 36 +-- .../core/common/http/HttpTaskDelegate.java | 187 ++++++++++++ .../aria/core/common/http/PostDelegate.java | 62 +--- .../aria/core/download/AbsDownloadTarget.java | 8 +- .../aria/core/download/BaseDListener.java | 5 +- .../aria/core/download/BaseGroupTarget.java | 17 +- .../aria/core/download/BaseNormalTarget.java | 16 +- ...roupTaskEntity.java => DGTaskWrapper.java} | 29 +- ...nloadTaskEntity.java => DTaskWrapper.java} | 37 +-- .../aria/core/download/DownloadEntity.java | 4 +- .../core/download/DownloadGroupEntity.java | 4 +- .../core/download/DownloadGroupListener.java | 3 +- .../core/download/DownloadGroupTarget.java | 25 +- .../aria/core/download/DownloadGroupTask.java | 26 +- .../aria/core/download/DownloadReceiver.java | 20 +- .../aria/core/download/DownloadTarget.java | 3 +- .../aria/core/download/DownloadTask.java | 13 +- .../core/download/FtpDirDownloadTarget.java | 25 +- .../aria/core/download/FtpDownloadTarget.java | 17 +- .../download/downloader/AbsGroupUtil.java | 45 ++- .../download/downloader/ConnectionHelp.java | 30 +- .../downloader/DownloadGroupUtil.java | 20 +- .../core/download/downloader/Downloader.java | 20 +- .../downloader/FtpDirDownloadUtil.java | 16 +- .../download/downloader/FtpDirInfoThread.java | 31 +- .../downloader/FtpFileInfoThread.java | 12 +- .../download/downloader/FtpThreadTask.java | 8 +- .../downloader/HttpFileInfoThread.java | 53 ++-- .../download/downloader/HttpThreadTask.java | 21 +- .../downloader/SimpleDownloadUtil.java | 15 +- .../core/download/wrapper/DGSTEWrapper.java | 10 +- .../core/download/wrapper/DGTEWrapper.java | 20 +- .../core/download/wrapper/DTEWrapper.java | 6 +- .../com/arialyy/aria/core/inf/AbsEntity.java | 5 +- .../arialyy/aria/core/inf/AbsGroupTask.java | 4 +- .../aria/core/inf/AbsGroupTaskEntity.java | 26 -- ...Delegate.java => AbsGroupTaskWrapper.java} | 15 +- .../arialyy/aria/core/inf/AbsNormalTask.java | 4 +- .../com/arialyy/aria/core/inf/AbsTarget.java | 45 ++- .../com/arialyy/aria/core/inf/AbsTask.java | 39 ++- .../arialyy/aria/core/inf/AbsTaskEntity.java | 286 ------------------ .../arialyy/aria/core/inf/AbsTaskWrapper.java | 151 +++++++++ .../java/com/arialyy/aria/core/inf/ITask.java | 4 +- ...rmalTaskEntity.java => ITaskDelegate.java} | 6 +- .../arialyy/aria/core/inf/ITaskWrapper.java | 53 ++++ .../aria/core/manager/DGTEFactory.java | 40 +-- .../arialyy/aria/core/manager/DTEFactory.java | 16 +- .../aria/core/manager/IGTEFactory.java | 4 +- .../aria/core/manager/INormalTEFactory.java | 4 +- .../aria/core/manager/SubTaskManager.java | 6 +- .../arialyy/aria/core/manager/TEManager.java | 56 ++-- .../aria/core/manager/ThreadTaskManager.java | 8 +- .../arialyy/aria/core/manager/UTEFactory.java | 16 +- .../arialyy/aria/core/queue/AbsTaskQueue.java | 8 +- .../core/queue/DownloadGroupTaskQueue.java | 12 +- .../aria/core/queue/DownloadTaskQueue.java | 12 +- .../arialyy/aria/core/queue/ITaskQueue.java | 12 +- .../arialyy/aria/core/queue/TaskFactory.java | 36 +-- .../aria/core/queue/UploadTaskQueue.java | 12 +- .../aria/core/scheduler/AbsSchedulers.java | 14 +- .../scheduler/DownloadGroupSchedulers.java | 5 +- .../core/scheduler/DownloadSchedulers.java | 5 +- .../aria/core/scheduler/UploadSchedulers.java | 4 +- .../aria/core/upload/AbsUploadTarget.java | 4 +- .../aria/core/upload/BaseNormalTarget.java | 15 +- .../aria/core/upload/BaseUListener.java | 5 +- .../aria/core/upload/FtpUploadTarget.java | 24 +- .../aria/core/upload/UTaskWrapper.java | 57 ++++ .../aria/core/upload/UploadEntity.java | 4 +- .../aria/core/upload/UploadReceiver.java | 6 +- .../aria/core/upload/UploadTarget.java | 12 +- .../upload/uploader/FtpFileInfoThread.java | 14 +- .../core/upload/uploader/FtpThreadTask.java | 14 +- .../core/upload/uploader/HttpThreadTask.java | 34 ++- .../upload/uploader/SimpleUploadUtil.java | 13 +- .../aria/core/upload/uploader/Uploader.java | 15 +- .../aria/core/upload/wrapper/UTEWrapper.java | 6 +- .../java/com/arialyy/aria/orm/DBConfig.java | 12 +- .../java/com/arialyy/aria/orm/SqlHelper.java | 73 +++-- .../java/com/arialyy/aria/util/CheckUtil.java | 27 +- .../com/arialyy/aria/util/CommonUtil.java | 13 +- .../com/arialyy/simple/DbTestActivity.java | 6 +- .../download/group/DownloadGroupActivity.java | 6 +- .../group/FTPDirDownloadActivity.java | 4 +- .../multi_download/DownloadAdapter.java | 26 +- .../arialyy/simple/test/AnyRunActivity.java | 8 +- .../arialyy/aria/core/upload/UploadTask.java | 16 +- .../aria/core/upload/UploadTaskEntity.java | 107 ------- 118 files changed, 1397 insertions(+), 1418 deletions(-) create mode 100644 Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskDelegate.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/common/http/BaseTarget.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/common/http/HttpTaskDelegate.java rename Aria/src/main/java/com/arialyy/aria/core/download/{DownloadGroupTaskEntity.java => DGTaskWrapper.java} (58%) rename Aria/src/main/java/com/arialyy/aria/core/download/{DownloadTaskEntity.java => DTaskWrapper.java} (59%) delete mode 100644 Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTaskEntity.java rename Aria/src/main/java/com/arialyy/aria/core/inf/{IPostDelegate.java => AbsGroupTaskWrapper.java} (59%) delete mode 100644 Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java rename Aria/src/main/java/com/arialyy/aria/core/inf/{AbsNormalTaskEntity.java => ITaskDelegate.java} (81%) create mode 100644 Aria/src/main/java/com/arialyy/aria/core/inf/ITaskWrapper.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java delete mode 100644 aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index 4dc826e0..f151c382 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -30,15 +30,15 @@ import com.arialyy.aria.core.command.ICmd; import com.arialyy.aria.core.common.QueueMod; 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.DGTaskWrapper; import com.arialyy.aria.core.download.DownloadReceiver; -import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.inf.AbsReceiver; import com.arialyy.aria.core.inf.IReceiver; import com.arialyy.aria.core.inf.ReceiverType; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadReceiver; -import com.arialyy.aria.core.upload.UploadTaskEntity; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DelegateWrapper; import com.arialyy.aria.util.ALog; @@ -128,7 +128,7 @@ import org.xml.sax.SAXException; private void amendTaskState() { Class[] clazzs = new Class[] { DownloadEntity.class, UploadEntity.class, DownloadGroupEntity.class, - DownloadTaskEntity.class, UploadTaskEntity.class, DownloadGroupTaskEntity.class + DTaskWrapper.class, UTaskWrapper.class, DGTaskWrapper.class }; String sql = "UPDATE %s SET state=2 WHERE state IN (3,4,5,6)"; for (Class clazz : clazzs) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java b/Aria/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java index 8d4df9e5..7e88d5df 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java @@ -18,7 +18,6 @@ package com.arialyy.aria.core; import com.arialyy.aria.core.common.ProtocolType; -import com.arialyy.aria.orm.annotation.Ignore; import java.net.InetAddress; /** @@ -58,7 +57,6 @@ public class FtpUrlEntity implements Cloneable { /** * 密码 */ - @Ignore public String password; /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java index 5e0f9ec3..609714f2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java @@ -16,15 +16,15 @@ package com.arialyy.aria.core.command; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.queue.ITaskQueue; /** * Created by AriaL on 2017/6/29. */ -public abstract class AbsCmd implements ICmd { +public abstract class AbsCmd implements ICmd { protected ITaskQueue mQueue; - protected T mTaskEntity; + protected T mTaskWrapper; protected String TAG; /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java index 4783fd91..14caef9a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java @@ -15,13 +15,13 @@ */ package com.arialyy.aria.core.command; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; /** * Created by AriaL on 2017/6/29. * 抽象命令工厂 */ -public abstract class AbsCmdFactory { +public abstract class AbsCmdFactory { /** * @param entity 下载实体 diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java index 6f0cd071..e4fc6f06 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java @@ -16,10 +16,10 @@ package com.arialyy.aria.core.command.group; import com.arialyy.aria.core.command.AbsCmd; -import com.arialyy.aria.core.download.DownloadGroupTaskEntity; +import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.core.inf.AbsGroupTask; -import com.arialyy.aria.core.inf.AbsGroupTaskEntity; import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.core.inf.AbsGroupTaskWrapper; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; @@ -28,7 +28,7 @@ import com.arialyy.aria.util.CommonUtil; * Created by AriaL on 2017/6/29. * 任务组命令 */ -public abstract class AbsGroupCmd extends AbsCmd { +public abstract class AbsGroupCmd extends AbsCmd { /** * 需要控制的子任务url */ @@ -37,9 +37,9 @@ public abstract class AbsGroupCmd extends AbsCmd extends AbsCmd extends AbsGroupCmd { +class GroupCancelCmd extends AbsGroupCmd { GroupCancelCmd(T entity) { super(entity); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java index e96a9437..c931eb5a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java @@ -16,11 +16,11 @@ package com.arialyy.aria.core.command.group; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.inf.AbsGroupTaskEntity; +import com.arialyy.aria.core.download.DGTaskWrapper; +import com.arialyy.aria.core.inf.AbsGroupTaskWrapper; /** - * Created by AriaL on 2017/6/29. - * 任务组子任务控制命令 + * Created by AriaL on 2017/6/29. 任务组子任务控制命令 */ public class GroupCmdFactory { /** @@ -53,22 +53,22 @@ public class GroupCmdFactory { /** * @param target 创建任务的对象 - * @param entity 下载实体 + * @param wrapper 参数信息 * @param type 命令类型{@link #SUB_TASK_START}、{@link #SUB_TASK_STOP}、{@link #SUB_TASK_CANCEL} * @param childUrl 需要控制的子任务url */ - public AbsGroupCmd createCmd(String target, AbsGroupTaskEntity entity, int type, + public AbsGroupCmd createCmd(String target, AbsGroupTaskWrapper wrapper, int type, String childUrl) { AbsGroupCmd cmd = null; switch (type) { case SUB_TASK_START: - cmd = new GroupStartCmd<>(entity); + cmd = new GroupStartCmd<>(wrapper); break; case SUB_TASK_STOP: - cmd = new GroupStopCmd<>(entity); + cmd = new GroupStopCmd<>(wrapper); break; case SUB_TASK_CANCEL: - cmd = new GroupCancelCmd<>(entity); + cmd = new GroupCancelCmd<>(wrapper); } if (cmd != null) { cmd.childUrl = childUrl; diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStartCmd.java index be661ebc..d64b9a0b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStartCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStartCmd.java @@ -15,15 +15,14 @@ */ package com.arialyy.aria.core.command.group; -import com.arialyy.aria.core.inf.AbsGroupTaskEntity; +import com.arialyy.aria.core.inf.AbsGroupTaskWrapper; /** - * Created by AriaL on 2017/6/29. - * 任务组开始命令,该命令负责处理任务组子任务的开始\恢复等工作 + * Created by AriaL on 2017/6/29. 任务组开始命令,该命令负责处理任务组子任务的开始\恢复等工作 */ -class GroupStartCmd extends AbsGroupCmd { - GroupStartCmd( T entity) { - super( entity); +class GroupStartCmd extends AbsGroupCmd { + GroupStartCmd(T wrapper) { + super(wrapper); } @Override public void executeCmd() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStopCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStopCmd.java index 009a8e90..527e4fc2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStopCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStopCmd.java @@ -15,13 +15,13 @@ */ package com.arialyy.aria.core.command.group; -import com.arialyy.aria.core.inf.AbsGroupTaskEntity; +import com.arialyy.aria.core.inf.AbsGroupTaskWrapper; /** * Created by AriaL on 2017/6/29. * 停止任务组的命令 */ -class GroupStopCmd extends AbsGroupCmd { +class GroupStopCmd extends AbsGroupCmd { GroupStopCmd(T entity) { super(entity); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java index 80024b6d..7099146f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java @@ -18,25 +18,25 @@ package com.arialyy.aria.core.command.normal; import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.command.ICmd; -import com.arialyy.aria.core.download.DownloadGroupTaskEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.download.DGTaskWrapper; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsTask; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IEntity; 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.scheduler.ISchedulers; -import com.arialyy.aria.core.upload.UploadTaskEntity; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; /** * Created by lyy on 2016/8/22. 下载命令 */ -public abstract class AbsNormalCmd extends AbsCmd { +public abstract class AbsNormalCmd extends AbsCmd { /** * 能否执行命令 */ @@ -51,22 +51,22 @@ public abstract class AbsNormalCmd extends AbsCmd { */ AbsNormalCmd(T entity, int taskType) { this.taskType = taskType; - mTaskEntity = entity; + mTaskWrapper = entity; TAG = CommonUtil.getClassName(this); if (taskType == ICmd.TASK_TYPE_DOWNLOAD) { - if (!(entity instanceof DownloadTaskEntity)) { + if (!(entity instanceof DTaskWrapper)) { ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD"); return; } mQueue = DownloadTaskQueue.getInstance(); } else if (taskType == ICmd.TASK_TYPE_DOWNLOAD_GROUP) { - if (!(entity instanceof DownloadGroupTaskEntity)) { + if (!(entity instanceof DGTaskWrapper)) { ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD_GROUP"); return; } mQueue = DownloadGroupTaskQueue.getInstance(); } else if (taskType == ICmd.TASK_TYPE_UPLOAD) { - if (!(entity instanceof UploadTaskEntity)) { + if (!(entity instanceof UTaskWrapper)) { ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_UPLOAD"); return; } @@ -92,9 +92,8 @@ public abstract class AbsNormalCmd extends AbsCmd { */ void sendWaitState(AbsTask task) { if (task != null) { - task.getTaskEntity().getEntity().setState(IEntity.STATE_WAIT); - task.getTaskEntity().setState(IEntity.STATE_WAIT); - task.getTaskEntity().update(); + task.getTaskWrapper().getEntity().setState(IEntity.STATE_WAIT); + task.getTaskWrapper().setState(IEntity.STATE_WAIT); task.getOutHandler().obtainMessage(ISchedulers.WAIT, task).sendToTarget(); } } @@ -125,7 +124,7 @@ public abstract class AbsNormalCmd extends AbsCmd { /** * 删除任务 */ - void removeTask(AbsTaskEntity taskEntity) { + void removeTask(AbsTaskWrapper taskEntity) { AbsTask tempTask = getTask(taskEntity.getEntity()); if (tempTask == null) { tempTask = createTask(taskEntity); @@ -162,7 +161,7 @@ public abstract class AbsNormalCmd extends AbsCmd { * @return 执行任务 */ AbsTask getTask() { - tempTask = mQueue.getTask(mTaskEntity.getEntity().getKey()); + tempTask = mQueue.getTask(mTaskWrapper.getEntity().getKey()); return tempTask; } @@ -182,7 +181,7 @@ public abstract class AbsNormalCmd extends AbsCmd { * @return 创建的任务 */ AbsTask createTask() { - tempTask = mQueue.createTask(mTaskEntity); + tempTask = mQueue.createTask(mTaskWrapper); return tempTask; } @@ -192,7 +191,7 @@ public abstract class AbsNormalCmd extends AbsCmd { * @param taskEntity 特定的任务实体 * @return 创建的任务 */ - AbsTask createTask(AbsTaskEntity taskEntity) { + AbsTask createTask(AbsTaskWrapper taskEntity) { TEManager.getInstance().addTEntity(taskEntity); return mQueue.createTask(taskEntity); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java index a34d385f..be001a88 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java @@ -17,7 +17,7 @@ package com.arialyy.aria.core.command.normal; import com.arialyy.aria.core.inf.AbsTask; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.util.ALog; @@ -25,7 +25,7 @@ import com.arialyy.aria.util.ALog; * Created by lyy on 2016/8/22. * 添加任务的命令 */ -class AddCmd extends AbsNormalCmd { +class AddCmd extends AbsNormalCmd { AddCmd(T entity, int taskType) { super(entity, taskType); @@ -35,7 +35,7 @@ class AddCmd extends AbsNormalCmd { if (!canExeCmd) return; AbsTask task = getTask(); if (task == null) { - mTaskEntity.getEntity().setState(IEntity.STATE_WAIT); + mTaskWrapper.getEntity().setState(IEntity.STATE_WAIT); createTask(); sendWaitState(); } else { diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java index e8e0f16e..bd845482 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java @@ -16,17 +16,17 @@ package com.arialyy.aria.core.command.normal; +import com.arialyy.aria.core.download.DGTaskWrapper; +import com.arialyy.aria.core.download.DTaskWrapper; 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.inf.AbsTaskWrapper; 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.UTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; import java.util.List; @@ -35,7 +35,7 @@ import java.util.List; * Created by AriaL on 2017/6/27. * 删除所有任务,并且删除所有回掉 */ -public class CancelAllCmd extends AbsNormalCmd { +public class CancelAllCmd extends AbsNormalCmd { /** * removeFile {@code true} 删除已经下载完成的任务,不仅删除下载记录,还会删除已经下载完成的文件,{@code false} * 如果文件已经下载完成,只删除下载记录 @@ -64,7 +64,7 @@ public class CancelAllCmd extends AbsNormalCmd { DbEntity.findDatas(DownloadEntity.class, "isGroupChild=?", "false"); if (entities != null && !entities.isEmpty()) { for (DownloadEntity entity : entities) { - remove(TEManager.getInstance().getTEntity(DownloadTaskEntity.class, entity.getKey())); + remove(TEManager.getInstance().getTEntity(DTaskWrapper.class, entity.getKey())); } } } @@ -78,7 +78,7 @@ public class CancelAllCmd extends AbsNormalCmd { if (entities != null && !entities.isEmpty()) { for (DownloadGroupEntity entity : entities) { remove( - TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, entity.getUrls())); + TEManager.getInstance().getGTEntity(DGTaskWrapper.class, entity.getUrls())); } } } @@ -91,21 +91,21 @@ public class CancelAllCmd extends AbsNormalCmd { DbEntity.findDatas(UploadEntity.class, "isGroupChild=?", "false"); if (entities != null && !entities.isEmpty()) { for (UploadEntity entity : entities) { - remove(TEManager.getInstance().getTEntity(UploadTaskEntity.class, entity.getKey())); + remove(TEManager.getInstance().getTEntity(UTaskWrapper.class, entity.getKey())); } } } - private void remove(AbsTaskEntity te) { + private void remove(AbsTaskWrapper te) { if (te == null){ ALog.w(TAG, "取消任务失败,任务为空"); return; } - if (te instanceof DownloadTaskEntity) { + if (te instanceof DTaskWrapper) { mQueue = DownloadTaskQueue.getInstance(); - } else if (te instanceof UploadTaskEntity) { + } else if (te instanceof UTaskWrapper) { mQueue = UploadTaskQueue.getInstance(); - } else if (te instanceof DownloadGroupTaskEntity) { + } else if (te instanceof DGTaskWrapper) { mQueue = DownloadGroupTaskQueue.getInstance(); } te.setRemoveFile(removeFile); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java index f0a80cdf..815dc628 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java @@ -17,13 +17,13 @@ package com.arialyy.aria.core.command.normal; import com.arialyy.aria.core.inf.AbsTask; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; /** * Created by lyy on 2016/9/20. * 取消命令 */ -public class CancelCmd extends AbsNormalCmd { +public class CancelCmd extends AbsNormalCmd { /** * removeFile {@code true} 删除已经下载完成的任务,不仅删除下载记录,还会删除已经下载完成的文件,{@code false} * 如果文件已经下载完成,只删除下载记录 @@ -41,7 +41,7 @@ public class CancelCmd extends AbsNormalCmd { task = createTask(); } if (task != null) { - mTaskEntity.setRemoveFile(removeFile); + mTaskWrapper.setRemoveFile(removeFile); removeTask(); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java index a033a145..c701a1e9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java @@ -15,10 +15,9 @@ */ package com.arialyy.aria.core.command.normal; -import android.text.TextUtils; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.DownloadTask; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.NetUtils; @@ -35,7 +34,7 @@ import com.arialyy.aria.util.NetUtils; * * 目前只只支持单下载任务的最高优先级任务 */ -final class HighestPriorityCmd extends AbsNormalCmd { +final class HighestPriorityCmd extends AbsNormalCmd { HighestPriorityCmd(T entity, int taskType) { super(entity, taskType); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/NormalCmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/NormalCmdFactory.java index 837d01a3..8cb11b25 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/NormalCmdFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/NormalCmdFactory.java @@ -19,13 +19,13 @@ package com.arialyy.aria.core.command.normal; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.command.AbsCmdFactory; import com.arialyy.aria.core.command.ICmd; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; /** * Created by Lyy on 2016/9/23. * 命令工厂 */ -public class NormalCmdFactory extends AbsCmdFactory { +public class NormalCmdFactory extends AbsCmdFactory { /** * 创建任务 */ @@ -84,7 +84,7 @@ public class NormalCmdFactory extends AbsCmdFactory * @param taskType {@link ICmd#TASK_TYPE_DOWNLOAD}、{@link ICmd#TASK_TYPE_DOWNLOAD_GROUP}、{@link * ICmd#TASK_TYPE_UPLOAD} */ - public AbsNormalCmd createCmd(AbsTaskEntity entity, int type, int taskType) { + public AbsNormalCmd createCmd(AbsTaskWrapper entity, int type, int taskType) { switch (type) { case TASK_CREATE: return new AddCmd<>(entity, taskType); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java index cb4c0eba..15d4770d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java @@ -1,20 +1,19 @@ package com.arialyy.aria.core.command.normal; -import android.text.TextUtils; import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.download.DGTaskWrapper; +import com.arialyy.aria.core.download.DTaskWrapper; 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.AbsTask; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IEntity; 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.UTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; @@ -30,8 +29,8 @@ import java.util.List; * 3.如果队列中只有等待状态的任务,如果执行队列没有满,则会启动等待状态的任务,如果执行队列已经满了,则会将所有等待状态的任务加载到缓存队列中 * 4.恢复下载的任务规则是,停止时间越晚的任务启动越早,按照DESC来进行排序 */ -final class ResumeAllCmd extends AbsNormalCmd { - private List mWaitList = new ArrayList<>(); +final class ResumeAllCmd extends AbsNormalCmd { + private List mWaitList = new ArrayList<>(); ResumeAllCmd(T entity, int taskType) { super(entity, taskType); @@ -66,7 +65,7 @@ final class ResumeAllCmd extends AbsNormalCmd { //if (TextUtils.isEmpty(entity.getDownloadPath())){ // continue; //} - resumeTask(TEManager.getInstance().getTEntity(DownloadTaskEntity.class, entity.getKey())); + resumeTask(TEManager.getInstance().getTEntity(DTaskWrapper.class, entity.getKey())); } } } else if (type == 2) { @@ -75,7 +74,7 @@ final class ResumeAllCmd extends AbsNormalCmd { if (entities != null && !entities.isEmpty()) { for (DownloadGroupEntity entity : entities) { resumeTask( - TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, entity.getUrls())); + TEManager.getInstance().getGTEntity(DGTaskWrapper.class, entity.getUrls())); } } } else if (type == 3) { @@ -83,7 +82,7 @@ final class ResumeAllCmd extends AbsNormalCmd { DbEntity.findDatas(UploadEntity.class, "state!=? ORDER BY stopTime DESC", "1"); if (entities != null && !entities.isEmpty()) { for (UploadEntity entity : entities) { - resumeTask(TEManager.getInstance().getTEntity(UploadTaskEntity.class, entity.getKey())); + resumeTask(TEManager.getInstance().getTEntity(UTaskWrapper.class, entity.getKey())); } } } @@ -92,7 +91,7 @@ final class ResumeAllCmd extends AbsNormalCmd { /** * 恢复任务 */ - private void resumeTask(AbsTaskEntity te) { + private void resumeTask(AbsTaskWrapper te) { if (te == null || te.getEntity() == null) return; int state = te.getState(); if (state == IEntity.STATE_STOP || state == IEntity.STATE_OTHER) { @@ -112,12 +111,12 @@ final class ResumeAllCmd extends AbsNormalCmd { private void resumeWaitTask() { int maxTaskNum = mQueue.getMaxTaskNum(); if (mWaitList == null || mWaitList.isEmpty()) return; - for (AbsTaskEntity te : mWaitList) { - if (te instanceof DownloadTaskEntity) { + for (AbsTaskWrapper te : mWaitList) { + if (te instanceof DTaskWrapper) { mQueue = DownloadTaskQueue.getInstance(); - } else if (te instanceof UploadTaskEntity) { + } else if (te instanceof UTaskWrapper) { mQueue = UploadTaskQueue.getInstance(); - } else if (te instanceof DownloadGroupTaskEntity) { + } else if (te instanceof DGTaskWrapper) { mQueue = DownloadGroupTaskQueue.getInstance(); } if (mQueue.getCurrentExePoolNum() < maxTaskNum) { @@ -135,16 +134,16 @@ final class ResumeAllCmd extends AbsNormalCmd { * * @param te 任务实体 */ - private void resumeEntity(AbsTaskEntity te) { - if (te instanceof DownloadTaskEntity) { - if (te.getRequestType() == AbsTaskEntity.D_FTP - || te.getRequestType() == AbsTaskEntity.U_FTP) { - te.setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey())); + private void resumeEntity(AbsTaskWrapper te) { + if (te instanceof DTaskWrapper) { + if (te.getRequestType() == AbsTaskWrapper.D_FTP + || te.getRequestType() == AbsTaskWrapper.U_FTP) { + te.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey())); } mQueue = DownloadTaskQueue.getInstance(); - } else if (te instanceof UploadTaskEntity) { + } else if (te instanceof UTaskWrapper) { mQueue = UploadTaskQueue.getInstance(); - } else if (te instanceof DownloadGroupTaskEntity) { + } else if (te instanceof DGTaskWrapper) { mQueue = DownloadGroupTaskQueue.getInstance(); } int exeNum = mQueue.getCurrentExePoolNum(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java index 1e6b0484..8969ed1a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java @@ -18,17 +18,17 @@ package com.arialyy.aria.core.command.normal; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.QueueMod; -import com.arialyy.aria.core.download.DownloadGroupTaskEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.download.DGTaskWrapper; +import com.arialyy.aria.core.download.DTaskWrapper; 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.AbsTaskWrapper; import com.arialyy.aria.core.inf.IEntity; 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.UploadTaskEntity; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.wrapper.UTEWrapper; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; @@ -40,7 +40,7 @@ import java.util.List; /** * Created by lyy on 2016/8/22. 开始命令 队列模型{@link QueueMod#NOW}、{@link QueueMod#WAIT} */ -class StartCmd extends AbsNormalCmd { +class StartCmd extends AbsNormalCmd { StartCmd(T entity, int taskType) { super(entity, taskType); @@ -115,11 +115,11 @@ class StartCmd extends AbsNormalCmd { } } - private List findWaitData(int type) { - List waitList = new ArrayList<>(); + private List findWaitData(int type) { + List waitList = new ArrayList<>(); if (type == 1) { List wrappers = DbEntity.findRelationData(DTEWrapper.class, - "DownloadTaskEntity.isGroupTask=? and DownloadTaskEntity.state=?", "false", "3"); + "DTaskWrapper.isGroupTask=? and DTaskWrapper.state=?", "false", "3"); if (wrappers != null && !wrappers.isEmpty()) { for (DTEWrapper w : wrappers) { waitList.add(w.taskEntity); @@ -127,7 +127,7 @@ class StartCmd extends AbsNormalCmd { } } else if (type == 2) { List wrappers = - DbEntity.findRelationData(DGTEWrapper.class, "DownloadGroupTaskEntity.state=?", "3"); + DbEntity.findRelationData(DGTEWrapper.class, "DGTaskWrapper.state=?", "3"); if (wrappers != null && !wrappers.isEmpty()) { for (DGTEWrapper w : wrappers) { waitList.add(w.taskEntity); @@ -135,7 +135,7 @@ class StartCmd extends AbsNormalCmd { } } else if (type == 3) { List wrappers = DbEntity.findRelationData(UTEWrapper.class, - "UploadTaskEntity.state=?", "3"); + "UTaskWrapper.state=?", "3"); if (wrappers != null && !wrappers.isEmpty()) { for (UTEWrapper w : wrappers) { waitList.add(w.taskEntity); @@ -145,20 +145,20 @@ class StartCmd extends AbsNormalCmd { return waitList; } - private void handleTask(List waitList) { - for (AbsTaskEntity te : waitList) { + private void handleTask(List waitList) { + for (AbsTaskWrapper te : waitList) { if (te.getEntity() == null) continue; AbsTask task = getTask(te.getEntity()); if (task != null) continue; - if (te instanceof DownloadTaskEntity) { - if (te.getRequestType() == AbsTaskEntity.D_FTP - || te.getRequestType() == AbsTaskEntity.U_FTP) { - te.setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey())); + if (te instanceof DTaskWrapper) { + if (te.getRequestType() == AbsTaskWrapper.D_FTP + || te.getRequestType() == AbsTaskWrapper.U_FTP) { + te.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey())); } mQueue = DownloadTaskQueue.getInstance(); - } else if (te instanceof UploadTaskEntity) { + } else if (te instanceof UTaskWrapper) { mQueue = UploadTaskQueue.getInstance(); - } else if (te instanceof DownloadGroupTaskEntity) { + } else if (te instanceof DGTaskWrapper) { mQueue = DownloadGroupTaskQueue.getInstance(); } createTask(te); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopAllCmd.java index ff15dc92..498be815 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopAllCmd.java @@ -1,12 +1,12 @@ package com.arialyy.aria.core.command.normal; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; /** * Created by AriaL on 2017/6/13. * 停止所有任务的命令,并清空所有等待队列 */ -final class StopAllCmd extends AbsNormalCmd { +final class StopAllCmd extends AbsNormalCmd { StopAllCmd(T entity, int taskType) { super(entity, taskType); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java index 396cd389..39658751 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java @@ -17,7 +17,7 @@ package com.arialyy.aria.core.command.normal; import com.arialyy.aria.core.inf.AbsTask; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.util.ALog; @@ -25,7 +25,7 @@ import com.arialyy.aria.util.ALog; * Created by lyy on 2016/9/20. * 停止命令 */ -class StopCmd extends AbsNormalCmd { +class StopCmd extends AbsNormalCmd { StopCmd(T entity, int taskType) { super(entity, taskType); @@ -35,7 +35,7 @@ class StopCmd extends AbsNormalCmd { if (!canExeCmd) return; AbsTask task = getTask(); if (task == null) { - if (mTaskEntity.getEntity().getState() == IEntity.STATE_RUNNING) { + if (mTaskWrapper.getEntity().getState() == IEntity.STATE_RUNNING) { stopTask(); } else { ALog.w(TAG, "停止命令执行失败,【调度器中没有该任务】"); 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 3e479e71..75fa6613 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 @@ -20,9 +20,9 @@ import android.util.SparseArray; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.BaseDListener; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.inf.AbsNormalEntity; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IEventListener; import com.arialyy.aria.core.manager.ThreadTaskManager; import com.arialyy.aria.orm.DbEntity; @@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit; /** * Created by AriaL on 2017/7/1. 任务处理器 */ -public abstract class AbsFileer> +public abstract class AbsFileer> implements Runnable { private static final String STATE = "_state_"; private static final String RECORD = "_record_"; @@ -140,7 +140,7 @@ public abstract class AbsFileer 1 && manager.getDownloadConfig().isUseBlock(); // 线程数不等1并且没有使用块下载,则认为没有使用动态文件 @@ -148,7 +148,7 @@ public abstract class AbsFileer> +public abstract class AbsThreadTask> implements Callable { /** * 线程重试次数 @@ -55,9 +55,9 @@ public abstract class AbsThreadTask mConfig; + protected SubThreadConfig mConfig; protected ENTITY mEntity; - protected TASK_ENTITY mTaskEntity; + protected TASK_WRAPPER mTaskWrapper; private int mFailTimes = 0; private long mLastSaveTime; private ExecutorService mConfigThreadPool; @@ -82,12 +82,12 @@ public abstract class AbsThreadTask config) { + SubThreadConfig config) { STATE = constance; mListener = listener; mConfig = config; - mTaskEntity = mConfig.TASK_ENTITY; - mEntity = mTaskEntity.getEntity(); + mTaskWrapper = mConfig.TASK_ENTITY; + mEntity = mTaskWrapper.getEntity(); mLastSaveTime = System.currentTimeMillis(); mConfigThreadPool = Executors.newCachedThreadPool(); mThreadNum = STATE.TASK_RECORD.threadRecords.size(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java b/Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java index 67a0e039..1b9c8c39 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java @@ -19,7 +19,7 @@ import android.os.Handler; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsTask; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEventListener; import com.arialyy.aria.core.inf.TaskSchedulerType; @@ -30,7 +30,7 @@ import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.ErrorHelp; import java.lang.ref.WeakReference; -public abstract class BaseListener, TASK extends AbsTask> +public abstract class BaseListener, TASK extends AbsTask> implements IEventListener { private static final String TAG = "BaseListener"; protected WeakReference outHandler; @@ -48,8 +48,8 @@ public abstract class BaseListener(outHandler); this.mTask = new WeakReference<>(task).get(); - this.mEntity = mTask.getTaskEntity().getEntity(); - this.mTaskEntity = mTask.getTaskEntity(); + this.mEntity = mTask.getTaskWrapper().getEntity(); + this.mTaskEntity = mTask.getTaskWrapper(); manager = AriaManager.getInstance(AriaManager.APP); mLastLen = mEntity.getCurrentProgress(); mLastSaveTime = System.currentTimeMillis(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/SubThreadConfig.java b/Aria/src/main/java/com/arialyy/aria/core/common/SubThreadConfig.java index 02859b08..46482792 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/SubThreadConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/SubThreadConfig.java @@ -1,12 +1,12 @@ package com.arialyy.aria.core.common; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import java.io.File; /** * 子线程下载信息类 */ -public class SubThreadConfig { +public class SubThreadConfig { //线程Id public int THREAD_ID; //文件总长度 diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java index 3f2b001c..0be165bf 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java @@ -17,7 +17,6 @@ package com.arialyy.aria.core.common.ftp; import android.os.Process; import android.text.TextUtils; -import android.util.Log; import aria.apache.commons.net.ftp.FTP; import aria.apache.commons.net.ftp.FTPClient; import aria.apache.commons.net.ftp.FTPFile; @@ -28,7 +27,7 @@ import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.common.ProtocolType; import com.arialyy.aria.core.inf.AbsEntity; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.exception.AriaIOException; import com.arialyy.aria.exception.BaseException; @@ -48,21 +47,23 @@ import javax.net.ssl.SSLContext; /** * Created by Aria.Lao on 2017/7/25. 获取ftp文件夹信息 */ -public abstract class AbsFtpInfoThread> +public abstract class AbsFtpInfoThread> implements Runnable { private final String TAG = "AbsFtpInfoThread"; protected ENTITY mEntity; - protected TASK_ENTITY mTaskEntity; + protected TASK_WRAPPER mTaskWrapper; + private FtpTaskDelegate mTaskDelegate; private int mConnectTimeOut; protected OnFileInfoCallback mCallback; protected long mSize = 0; protected String charSet = "UTF-8"; private boolean isUpload = false; - public AbsFtpInfoThread(TASK_ENTITY taskEntity, OnFileInfoCallback callback) { - mTaskEntity = taskEntity; - mEntity = taskEntity.getEntity(); + public AbsFtpInfoThread(TASK_WRAPPER taskWrapper, OnFileInfoCallback callback) { + mTaskWrapper = taskWrapper; + mEntity = taskWrapper.getEntity(); + mTaskDelegate = taskWrapper.asFtp(); mConnectTimeOut = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getConnectTimeOut(); mCallback = callback; @@ -84,12 +85,12 @@ public abstract class AbsFtpInfoThread> +public abstract class AbsFtpThreadTask> extends AbsThreadTask { private final String TAG = "AbsFtpThreadTask"; protected String charSet; @@ -58,7 +58,7 @@ public abstract class AbsFtpThreadTask implements ITarget { public FTPSConfig(TARGET target) { mTarget = target; - mUrlEntity = mTarget.getTaskEntity().getUrlEntity(); + mUrlEntity = mTarget.getTaskWrapper().asFtp().getUrlEntity(); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java index 04f2792d..1d6ce711 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java @@ -33,14 +33,14 @@ public class FtpDelegate implements IFtpTarget public FtpDelegate(TARGET target) { mTarget = target; - mUrlEntity = target.getTaskEntity().getUrlEntity(); + mUrlEntity = target.getTaskWrapper().asFtp().getUrlEntity(); } @Override public TARGET charSet(String charSet) { if (TextUtils.isEmpty(charSet)) { throw new NullPointerException("字符编码为空"); } - mTarget.getTaskEntity().setCharSet(charSet); + mTarget.getTaskWrapper().asFtp().setCharSet(charSet); return mTarget; } @@ -64,7 +64,7 @@ public class FtpDelegate implements IFtpTarget } @Override public TARGET setProxy(Proxy proxy) { - mTarget.getTaskEntity().setProxy(proxy); + mTarget.getTaskWrapper().asFtp().setProxy(proxy); return mTarget; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskDelegate.java new file mode 100644 index 00000000..581b609a --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskDelegate.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.common.ftp; + +import com.arialyy.aria.core.FtpUrlEntity; +import com.arialyy.aria.core.inf.ITaskDelegate; +import java.net.Proxy; + +/** + * fTP任务设置的信息,如:用户名、密码、端口等信息 + */ +public class FtpTaskDelegate implements ITaskDelegate { + + /** + * 账号和密码 + */ + private FtpUrlEntity urlEntity; + + private Proxy proxy; + + /** + * 字符编码,默认为"utf-8" + */ + private String charSet = "utf-8"; + + public FtpUrlEntity getUrlEntity() { + return urlEntity; + } + + public void setUrlEntity(FtpUrlEntity urlEntity) { + this.urlEntity = urlEntity; + } + + public void setProxy(Proxy proxy) { + this.proxy = proxy; + } + + public Proxy getProxy() { + return proxy; + } + + public String getCharSet() { + return charSet; + } + + public void setCharSet(String charSet) { + this.charSet = charSet; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/http/BaseTarget.java b/Aria/src/main/java/com/arialyy/aria/core/common/http/BaseTarget.java new file mode 100644 index 00000000..422e7f4d --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/common/http/BaseTarget.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.common.http; + +import android.text.TextUtils; +import com.arialyy.aria.core.download.DGTaskWrapper; +import com.arialyy.aria.core.download.DTaskWrapper; +import com.arialyy.aria.core.download.DownloadGroupTarget; +import com.arialyy.aria.core.inf.AbsTarget; +import com.arialyy.aria.core.inf.ITarget; +import com.arialyy.aria.util.ALog; +import java.util.HashMap; +import java.util.Map; + +class BaseTarget implements ITarget { + private static final String TAG = "PostDelegate"; + TARGET mTarget; + + public BaseTarget(TARGET target){ + mTarget = target; + } + + public TARGET setParams(Map params) { + mTarget.getTaskWrapper().asHttp().setParams(params); + if (mTarget instanceof DownloadGroupTarget) { + for (DTaskWrapper subTask : ((DGTaskWrapper) mTarget.getTaskWrapper()).getSubTaskWrapper()) { + subTask.asHttp().setParams(params); + } + } + return mTarget; + } + + public TARGET setParam(String key, String value) { + if (TextUtils.isEmpty(key) || TextUtils.isEmpty(value)) { + ALog.d(TAG, "key 或value 为空"); + return mTarget; + } + Map params = mTarget.getTaskWrapper().asHttp().getParams(); + if (params == null) { + params = new HashMap<>(); + mTarget.getTaskWrapper().asHttp().setParams(params); + } + params.put(key, value); + if (mTarget instanceof DownloadGroupTarget) { + for (DTaskWrapper subTask : ((DGTaskWrapper) mTarget.getTaskWrapper()).getSubTaskWrapper()) { + subTask.asHttp().setParams(params); + } + } + return mTarget; + } + + @Override public void start() { + + } + + @Override public void stop() { + + } + + @Override public void resume() { + + } + + @Override public void cancel() { + + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/http/GetDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/http/GetDelegate.java index 7138f837..e1ed87e4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/http/GetDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/http/GetDelegate.java @@ -15,72 +15,16 @@ */ package com.arialyy.aria.core.common.http; -import android.text.TextUtils; import com.arialyy.aria.core.common.RequestEnum; -import com.arialyy.aria.core.download.DownloadGroupTarget; -import com.arialyy.aria.core.download.DownloadGroupTaskEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsTarget; -import com.arialyy.aria.core.inf.IPostDelegate; -import com.arialyy.aria.core.inf.ITarget; -import com.arialyy.aria.util.ALog; -import java.util.HashMap; -import java.util.Map; /** * get处理委托类 */ -public class GetDelegate implements IPostDelegate, ITarget { - private static final String TAG = "PostDelegate"; - private TARGET mTarget; +public class GetDelegate extends BaseTarget { public GetDelegate(TARGET target) { - mTarget = target; - mTarget.getTaskEntity().setRequestEnum(RequestEnum.GET); - } - - @Override public TARGET setParams(Map params) { - mTarget.getTaskEntity().setParams(params); - if (mTarget instanceof DownloadGroupTarget) { - for (DownloadTaskEntity subTask : ((DownloadGroupTaskEntity) mTarget.getTaskEntity()).getSubTaskEntities()) { - subTask.setParams(params); - } - } - return mTarget; - } - - @Override public TARGET setParam(String key, String value) { - if (TextUtils.isEmpty(key) || TextUtils.isEmpty(value)) { - ALog.d(TAG, "key 或value 为空"); - return mTarget; - } - Map params = mTarget.getTaskEntity().getParams(); - if (params == null) { - params = new HashMap<>(); - mTarget.getTaskEntity().setParams(params); - } - params.put(key, value); - if (mTarget instanceof DownloadGroupTarget) { - for (DownloadTaskEntity subTask : ((DownloadGroupTaskEntity) mTarget.getTaskEntity()).getSubTaskEntities()) { - subTask.setParams(params); - } - } - return mTarget; - } - - @Override public void start() { - mTarget.start(); - } - - @Override public void stop() { - mTarget.stop(); - } - - @Override public void resume() { - mTarget.resume(); - } - - @Override public void cancel() { - mTarget.cancel(); + super(target); + mTarget.getTaskWrapper().asHttp().setRequestEnum(RequestEnum.GET); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/http/HttpHeaderDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/http/HttpHeaderDelegate.java index 9982cdfa..09bc976b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/http/HttpHeaderDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/http/HttpHeaderDelegate.java @@ -18,7 +18,7 @@ package com.arialyy.aria.core.common.http; import android.support.annotation.NonNull; import android.text.TextUtils; import com.arialyy.aria.core.inf.AbsTarget; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IHttpHeaderDelegate; import com.arialyy.aria.util.ALog; import java.net.Proxy; @@ -55,7 +55,7 @@ public class HttpHeaderDelegate ALog.w(TAG, "设置header失败,header对应的value不能为null"); return mTarget; } - addHeader(mTarget.getTaskEntity(), key, value); + addHeader(mTarget.getTaskWrapper(), key, value); return mTarget; } @@ -71,24 +71,26 @@ public class HttpHeaderDelegate ALog.w(TAG, "设置header失败,map没有header数据"); return mTarget; } - addHeaders(mTarget.getTaskEntity(), headers); + addHeaders(mTarget.getTaskWrapper(), headers); return mTarget; } @Override public TARGET setUrlProxy(Proxy proxy) { - mTarget.getTaskEntity().setProxy(proxy); + mTarget.getTaskWrapper().asHttp().setProxy(proxy); return mTarget; } - public void addHeader(AbsTaskEntity taskEntity, String key, String value) { - if (taskEntity.getHeaders().get(key) == null) { - taskEntity.getHeaders().put(key, value); - } else if (!taskEntity.getHeaders().get(key).equals(value)) { - taskEntity.getHeaders().put(key, value); + public void addHeader(AbsTaskWrapper taskWrapper, String key, String value) { + HttpTaskDelegate taskDelegate = taskWrapper.asHttp(); + if (taskDelegate.getHeaders().get(key) == null) { + taskDelegate.getHeaders().put(key, value); + } else if (!taskDelegate.getHeaders().get(key).equals(value)) { + taskDelegate.getHeaders().put(key, value); } } - public void addHeaders(AbsTaskEntity taskEntity, Map headers) { + public void addHeaders(AbsTaskWrapper taskWrapper, Map headers) { + HttpTaskDelegate taskDelegate = taskWrapper.asHttp(); /* 两个map比较逻辑 1、比对key是否相同 @@ -96,9 +98,9 @@ public class HttpHeaderDelegate 3、只有当上面两个步骤中key 和 value都相同时才能任务两个map数据一致 */ boolean mapEquals = false; - if (taskEntity.getHeaders().size() == headers.size()) { + if (taskDelegate.getHeaders().size() == headers.size()) { int i = 0; - Set keys = taskEntity.getHeaders().keySet(); + Set keys = taskDelegate.getHeaders().keySet(); for (String key : keys) { if (headers.containsKey(key)) { i++; @@ -106,9 +108,9 @@ public class HttpHeaderDelegate break; } } - if (i == taskEntity.getHeaders().size()) { + if (i == taskDelegate.getHeaders().size()) { int j = 0; - Collection values = taskEntity.getHeaders().values(); + Collection values = taskDelegate.getHeaders().values(); for (String value : values) { if (headers.containsValue(value)) { j++; @@ -116,17 +118,17 @@ public class HttpHeaderDelegate break; } } - if (j == taskEntity.getHeaders().size()) { + if (j == taskDelegate.getHeaders().size()) { mapEquals = true; } } } if (!mapEquals) { - taskEntity.getHeaders().clear(); + taskDelegate.getHeaders().clear(); Set keys = headers.keySet(); for (String key : keys) { - taskEntity.getHeaders().put(key, headers.get(key)); + taskDelegate.getHeaders().put(key, headers.get(key)); } } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/http/HttpTaskDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/http/HttpTaskDelegate.java new file mode 100644 index 00000000..58b217ac --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/common/http/HttpTaskDelegate.java @@ -0,0 +1,187 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.arialyy.aria.core.common.http; + +import com.arialyy.aria.core.common.RequestEnum; +import com.arialyy.aria.core.inf.ITaskDelegate; +import java.net.CookieManager; +import java.net.Proxy; +import java.util.HashMap; +import java.util.Map; + +/** + * Http任务设置的信息,如:cookie、请求参数 + */ +public class HttpTaskDelegate implements ITaskDelegate { + + private CookieManager cookieManager; + + /** + * 请求参数 + */ + private Map params; + + /** + * http 请求头 + */ + private Map headers = new HashMap<>(); + + /** + * 字符编码,默认为"utf-8" + */ + private String charSet = "utf-8"; + + /** + * 网络请求类型 + */ + private RequestEnum requestEnum = RequestEnum.GET; + + /** + * 是否使用服务器通过content-disposition传递的文件名,内容格式{@code attachment; filename="filename.jpg"} {@code true} + * 使用 + */ + private boolean useServerFileName = false; + + /** + * 重定向链接 + */ + private String redirectUrl = ""; + + /** + * 是否是chunk模式 + */ + private boolean isChunked = false; + /** + * 文件上传需要的key + */ + private String attachment; + /** + * 上传的文件类型 + */ + private String contentType = "multipart/form-data"; + private String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)"; + + private Proxy proxy; + /** + * 文件上传表单 + */ + private Map formFields = new HashMap<>(); + + public Map getFormFields() { + return formFields; + } + + public void setFormFields(Map formFields) { + this.formFields = formFields; + } + + public String getAttachment() { + return attachment; + } + + public void setAttachment(String attachment) { + this.attachment = attachment; + } + + public String getContentType() { + return contentType; + } + + public void setContentType(String contentType) { + this.contentType = contentType; + } + + public String getUserAgent() { + return userAgent; + } + + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } + + public boolean isChunked() { + return isChunked; + } + + public void setChunked(boolean chunked) { + isChunked = chunked; + } + + public CookieManager getCookieManager() { + return cookieManager; + } + + public void setCookieManager(CookieManager cookieManager) { + this.cookieManager = cookieManager; + } + + public Proxy getProxy() { + return proxy; + } + + public void setProxy(Proxy proxy) { + this.proxy = proxy; + } + + public Map getHeaders() { + return headers; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } + + public String getCharSet() { + return charSet; + } + + public void setCharSet(String charSet) { + this.charSet = charSet; + } + + public RequestEnum getRequestEnum() { + return requestEnum; + } + + public void setRequestEnum(RequestEnum requestEnum) { + this.requestEnum = requestEnum; + } + + public boolean isUseServerFileName() { + return useServerFileName; + } + + public void setUseServerFileName(boolean useServerFileName) { + this.useServerFileName = useServerFileName; + } + + public String getRedirectUrl() { + return redirectUrl; + } + + public void setRedirectUrl(String redirectUrl) { + this.redirectUrl = redirectUrl; + } + + public Map getParams() { + return params; + } + + public void setParams(Map params) { + this.params = params; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/http/PostDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/http/PostDelegate.java index f06f3ae9..97f1e63f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/http/PostDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/http/PostDelegate.java @@ -15,72 +15,16 @@ */ package com.arialyy.aria.core.common.http; -import android.text.TextUtils; import com.arialyy.aria.core.common.RequestEnum; -import com.arialyy.aria.core.download.DownloadGroupTarget; -import com.arialyy.aria.core.download.DownloadGroupTaskEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsTarget; -import com.arialyy.aria.core.inf.IPostDelegate; -import com.arialyy.aria.core.inf.ITarget; -import com.arialyy.aria.util.ALog; -import java.util.HashMap; -import java.util.Map; /** * post处理委托类 */ -public class PostDelegate implements IPostDelegate, ITarget { - private static final String TAG = "PostDelegate"; - private TARGET mTarget; +public class PostDelegate extends BaseTarget { public PostDelegate(TARGET target) { - mTarget = target; - mTarget.getTaskEntity().setRequestEnum(RequestEnum.POST); - } - - @Override public TARGET setParams(Map params) { - mTarget.getTaskEntity().setParams(params); - if (mTarget instanceof DownloadGroupTarget) { - for (DownloadTaskEntity subTask : ((DownloadGroupTaskEntity) mTarget.getTaskEntity()).getSubTaskEntities()) { - subTask.setParams(params); - } - } - return mTarget; - } - - @Override public TARGET setParam(String key, String value) { - if (TextUtils.isEmpty(key) || TextUtils.isEmpty(value)) { - ALog.d(TAG, "key 或value 为空"); - return mTarget; - } - Map params = mTarget.getTaskEntity().getParams(); - if (params == null) { - params = new HashMap<>(); - mTarget.getTaskEntity().setParams(params); - } - params.put(key, value); - if (mTarget instanceof DownloadGroupTarget) { - for (DownloadTaskEntity subTask : ((DownloadGroupTaskEntity) mTarget.getTaskEntity()).getSubTaskEntities()) { - subTask.setParams(params); - } - } - return mTarget; - } - - @Override public void start() { - mTarget.start(); - } - - @Override public void stop() { - mTarget.stop(); - } - - @Override public void resume() { - mTarget.resume(); - } - - @Override public void cancel() { - mTarget.cancel(); + super(target); + mTarget.getTaskWrapper().asHttp().setRequestEnum(RequestEnum.POST); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/AbsDownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/AbsDownloadTarget.java index 4662be8d..ab19a525 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/AbsDownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/AbsDownloadTarget.java @@ -19,13 +19,13 @@ import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsTarget; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.util.CommonUtil; /** * Created by lyy on 2017/2/28. */ -abstract class AbsDownloadTarget +abstract class AbsDownloadTarget extends AbsTarget { static final int HTTP = 1; @@ -57,7 +57,7 @@ abstract class AbsDownloadTarget +public class BaseDListener extends BaseListener implements IDownloadListener { private static final String TAG = "BaseDListener"; @@ -68,6 +66,5 @@ public class BaseDListener extends BaseListener 0) { mEntity.setCurrentProgress(location); } - mTaskEntity.update(); } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java index b362aea1..867f8f50 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseGroupTarget.java @@ -17,7 +17,6 @@ package com.arialyy.aria.core.download; import android.support.annotation.CheckResult; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; @@ -31,7 +30,7 @@ import java.util.List; * Created by lyy on 2017/7/26. */ abstract class BaseGroupTarget - extends AbsDownloadTarget { + extends AbsDownloadTarget { /** * 组任务名 @@ -56,7 +55,7 @@ abstract class BaseGroupTarget @CheckResult public SubTaskManager getSubTaskManager() { if (mSubTaskManager == null) { - mSubTaskManager = new SubTaskManager(mTargetName, mTaskEntity); + mSubTaskManager = new SubTaskManager(mTargetName, mTaskWrapper); } return mSubTaskManager; } @@ -123,12 +122,10 @@ abstract class BaseGroupTarget * @param newDirPath 新的文件夹路径 */ void reChangeDirPath(String newDirPath) { - List subTasks = mTaskEntity.getSubTaskEntities(); + List subTasks = mTaskWrapper.getSubTaskWrapper(); if (subTasks != null && !subTasks.isEmpty()) { - //List des = new ArrayList<>(); - //List dtes = new ArrayList<>(); List des = new ArrayList<>(); - for (DownloadTaskEntity dte : subTasks) { + for (DTaskWrapper dte : subTasks) { DownloadEntity de = dte.getEntity(); String oldPath = de.getDownloadPath(); String newPath = newDirPath + "/" + de.getFileName(); @@ -138,13 +135,7 @@ abstract class BaseGroupTarget } de.setDownloadPath(newPath); dte.setKey(newPath); - - //des.add(de); - //dtes.add(dte); - //de.save(); - //dte.save(); des.add(de); - des.add(dte); } AbsEntity.saveAll(des); } 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 89235766..07b76437 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 @@ -16,7 +16,6 @@ package com.arialyy.aria.core.download; import android.text.TextUtils; -import com.arialyy.aria.core.common.TaskRecord; import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.orm.DbEntity; @@ -28,7 +27,7 @@ import java.io.File; * Created by Aria.Lao on 2017/7/26. */ abstract class BaseNormalTarget - extends AbsDownloadTarget { + extends AbsDownloadTarget { /** * 资源地址 @@ -41,8 +40,8 @@ abstract class BaseNormalTarget void initTarget(String url, String targetName) { this.url = url; mTargetName = targetName; - mTaskEntity = TEManager.getInstance().getTEntity(DownloadTaskEntity.class, url); - mEntity = mTaskEntity.getEntity(); + mTaskWrapper = TEManager.getInstance().getTEntity(DTaskWrapper.class, url); + mEntity = mTaskWrapper.getEntity(); if (mEntity != null) { mTempFilePath = mEntity.getDownloadPath(); @@ -64,7 +63,7 @@ abstract class BaseNormalTarget return (TARGET) this; } this.newUrl = newUrl; - mTaskEntity.setRefreshInfo(true); + mTaskWrapper.setRefreshInfo(true); return (TARGET) this; } @@ -122,7 +121,6 @@ abstract class BaseNormalTarget boolean b = getTargetType() < GROUP_HTTP && checkUrl() && checkFilePath(); if (b) { mEntity.save(); - mTaskEntity.save(); } return b; } @@ -166,14 +164,14 @@ abstract class BaseNormalTarget } else { ALog.w(TAG, "保存路径【" + filePath + "】已经被其它任务占用,当前任务将覆盖该路径的文件"); CommonUtil.delTaskRecord(filePath, 1); - mTaskEntity = TEManager.getInstance().getTEntity(DownloadTaskEntity.class, url); + mTaskWrapper = TEManager.getInstance().getTEntity(DTaskWrapper.class, url); } } File oldFile = new File(mEntity.getDownloadPath()); File newFile = new File(filePath); mEntity.setDownloadPath(filePath); mEntity.setFileName(newFile.getName()); - mTaskEntity.setKey(filePath); + mTaskWrapper.setKey(filePath); if (oldFile.exists()) { oldFile.renameTo(newFile); CommonUtil.modifyTaskRecord(oldFile.getPath(), newFile.getPath()); @@ -203,7 +201,7 @@ abstract class BaseNormalTarget } if (!TextUtils.isEmpty(newUrl)) { mEntity.setUrl(newUrl); - mTaskEntity.setUrl(newUrl); + mTaskWrapper.setUrl(newUrl); } return true; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DGTaskWrapper.java similarity index 58% rename from Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTaskEntity.java rename to Aria/src/main/java/com/arialyy/aria/core/download/DGTaskWrapper.java index 0fff9682..5a996c1f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DGTaskWrapper.java @@ -15,26 +15,18 @@ */ package com.arialyy.aria.core.download; -import com.arialyy.aria.core.inf.AbsGroupTaskEntity; -import com.arialyy.aria.orm.ActionPolicy; -import com.arialyy.aria.orm.annotation.Foreign; -import com.arialyy.aria.orm.annotation.Ignore; -import com.arialyy.aria.orm.annotation.Primary; +import com.arialyy.aria.core.inf.AbsGroupTaskWrapper; import java.util.List; /** - * Created by AriaL on 2017/7/1. - * 任务组的任务实体 + * Created by AriaL on 2017/7/1. 任务组的任务实体 */ -public class DownloadGroupTaskEntity extends AbsGroupTaskEntity { +public class DGTaskWrapper extends AbsGroupTaskWrapper { - @Ignore private DownloadGroupEntity entity; + private DownloadGroupEntity entity; - @Ignore private List subTaskEntities; + private List subTaskEntities; - @Primary - @Foreign(parent = DownloadGroupEntity.class, column = "groupName", - onUpdate = ActionPolicy.CASCADE, onDelete = ActionPolicy.CASCADE) private String key; @Override public DownloadGroupEntity getEntity() { @@ -45,11 +37,8 @@ public class DownloadGroupTaskEntity extends AbsGroupTaskEntity getSubTaskEntities() { - return subTaskEntities; - } - - public void setSubTaskEntities(List subTaskEntities) { + @Override + public void setSubTaskWrapper(List subTaskEntities) { this.subTaskEntities = subTaskEntities; } @@ -60,4 +49,8 @@ public class DownloadGroupTaskEntity extends AbsGroupTaskEntity getSubTaskWrapper() { + return subTaskEntities; + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java similarity index 59% rename from Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java rename to Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java index f23f5f30..e5bbf65c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java @@ -15,39 +15,25 @@ */ package com.arialyy.aria.core.download; -import com.arialyy.aria.core.inf.AbsNormalTaskEntity; -import com.arialyy.aria.orm.ActionPolicy; -import com.arialyy.aria.orm.annotation.Foreign; -import com.arialyy.aria.orm.annotation.Ignore; -import com.arialyy.aria.orm.annotation.NoNull; -import com.arialyy.aria.orm.annotation.Primary; -import java.util.Map; +import com.arialyy.aria.core.inf.AbsTaskWrapper; /** - * Created by lyy on 2017/1/23. - * 下载任务实体和下载实体为一对一关系,下载实体删除,任务实体自动删除 + * Created by lyy on 2017/1/23. 下载任务实体和下载实体为一对一关系,下载实体删除,任务实体自动删除 */ -public class DownloadTaskEntity extends AbsNormalTaskEntity { +public class DTaskWrapper extends AbsTaskWrapper { - @Ignore private DownloadEntity entity; + private DownloadEntity entity; /** * 任务的url */ - @NoNull private String url; + private String url; /** * 所属的任务组组名,如果不属于任务组,则为null */ - @Foreign(parent = DownloadGroupTaskEntity.class, column = "key", - onUpdate = ActionPolicy.CASCADE, onDelete = ActionPolicy.CASCADE) private String groupName; - /** - * 是否是chunk模式 - */ - private boolean isChunked = false; - /** * 该任务是否属于任务组 */ @@ -56,12 +42,9 @@ public class DownloadTaskEntity extends AbsNormalTaskEntity { /** * Task实体对应的key */ - @Primary - @Foreign(parent = DownloadEntity.class, column = "downloadPath", - onUpdate = ActionPolicy.CASCADE, onDelete = ActionPolicy.CASCADE) private String key; - public DownloadTaskEntity() { + public DTaskWrapper() { } @Override public DownloadEntity getEntity() { @@ -84,10 +67,6 @@ public class DownloadTaskEntity extends AbsNormalTaskEntity { return groupName; } - public boolean isChunked() { - return isChunked; - } - public boolean isGroupTask() { return isGroupTask; } @@ -104,10 +83,6 @@ public class DownloadTaskEntity extends AbsNormalTaskEntity { this.groupName = groupName; } - public void setChunked(boolean chunked) { - isChunked = chunked; - } - public void setGroupTask(boolean groupTask) { isGroupTask = groupTask; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java index b22ae995..3186f389 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java @@ -20,7 +20,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; import com.arialyy.aria.core.inf.AbsNormalEntity; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.orm.ActionPolicy; import com.arialyy.aria.orm.annotation.Foreign; import com.arialyy.aria.orm.annotation.Primary; @@ -61,7 +61,7 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable { } @Override public int getTaskType() { - return getUrl().startsWith("ftp") ? AbsTaskEntity.D_FTP : AbsTaskEntity.D_HTTP; + return getUrl().startsWith("ftp") ? AbsTaskWrapper.D_FTP : AbsTaskWrapper.D_HTTP; } public DownloadEntity() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java index 96f52012..e2845454 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java @@ -17,7 +17,7 @@ package com.arialyy.aria.core.download; import android.os.Parcel; import com.arialyy.aria.core.inf.AbsGroupEntity; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.orm.annotation.Ignore; import java.util.List; @@ -47,7 +47,7 @@ public class DownloadGroupEntity extends AbsGroupEntity { } @Override public int getTaskType() { - return getKey().startsWith("ftp") ? AbsTaskEntity.D_FTP_DIR : AbsTaskEntity.DG_HTTP; + return getKey().startsWith("ftp") ? AbsTaskWrapper.D_FTP_DIR : AbsTaskWrapper.DG_HTTP; } public DownloadGroupEntity() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java index 3357f652..866d2732 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java @@ -30,7 +30,7 @@ import com.arialyy.aria.util.ErrorHelp; * Created by Aria.Lao on 2017/7/20. 任务组下载事件 */ class DownloadGroupListener - extends BaseListener + extends BaseListener implements IDownloadGroupListener { private final String TAG = "DownloadGroupListener"; private GroupSendParams mSeedEntity; @@ -136,6 +136,5 @@ class DownloadGroupListener if (location > 0) { mEntity.setCurrentProgress(location); } - mTaskEntity.update(); } } 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 2380f54f..bd1f2cc4 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 @@ -67,8 +67,8 @@ public class DownloadGroupTarget extends BaseGroupTarget im private void init() { mGroupName = CommonUtil.getMd5Code(mUrls); - mTaskEntity = TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, mUrls); - mEntity = mTaskEntity.getEntity(); + mTaskWrapper = TEManager.getInstance().getGTEntity(DGTaskWrapper.class, mUrls); + mEntity = mTaskWrapper.getEntity(); if (mEntity != null) { mDirPathTemp = mEntity.getDirPath(); } @@ -99,7 +99,7 @@ public class DownloadGroupTarget extends BaseGroupTarget im mUrls.addAll(urls); mGroupName = CommonUtil.getMd5Code(urls); mEntity.setGroupName(mGroupName); - mTaskEntity.setKey(mGroupName); + mTaskWrapper.setKey(mGroupName); mEntity.update(); if (mEntity.getSubEntities() != null && !mEntity.getSubEntities().isEmpty()) { for (DownloadEntity de : mEntity.getSubEntities()) { @@ -159,7 +159,7 @@ public class DownloadGroupTarget extends BaseGroupTarget im ALog.e(TAG, "修改子任务的文件名失败:列表为null"); return this; } - if (subTaskFileName.size() != mTaskEntity.getSubTaskEntities().size()) { + if (subTaskFileName.size() != mTaskWrapper.getSubTaskWrapper().size()) { ALog.e(TAG, "修改子任务的文件名失败:子任务文件名列表数量和子任务的数量不匹配"); return this; } @@ -186,14 +186,13 @@ public class DownloadGroupTarget extends BaseGroupTarget im return false; } - if (mTaskEntity.getRequestEnum() == RequestEnum.POST) { - for (DownloadTaskEntity subTask : mTaskEntity.getSubTaskEntities()) { - subTask.setRequestEnum(RequestEnum.POST); + if (mTaskWrapper.asHttp().getRequestEnum() == RequestEnum.POST) { + for (DTaskWrapper subTask : mTaskWrapper.getSubTaskWrapper()) { + subTask.asHttp().setRequestEnum(RequestEnum.POST); } } mEntity.save(); - mTaskEntity.save(); if (needModifyPath) { reChangeDirPath(mDirPathTemp); @@ -211,9 +210,9 @@ public class DownloadGroupTarget extends BaseGroupTarget im * 更新所有改动的子任务文件名 */ private void updateSingleSubFileName() { - List entities = mTaskEntity.getSubTaskEntities(); + List entities = mTaskWrapper.getSubTaskWrapper(); int i = 0; - for (DownloadTaskEntity entity : entities) { + for (DTaskWrapper entity : entities) { if (i < mSubNameTemp.size()) { String newName = mSubNameTemp.get(i); updateSingleSubFileName(entity, newName); @@ -271,7 +270,7 @@ public class DownloadGroupTarget extends BaseGroupTarget im /** * 更新单个子任务文件名 */ - private void updateSingleSubFileName(DownloadTaskEntity taskEntity, String newName) { + private void updateSingleSubFileName(DTaskWrapper taskEntity, String newName) { DownloadEntity entity = taskEntity.getEntity(); if (!newName.equals(entity.getFileName())) { String oldPath = mEntity.getDirPath() + "/" + entity.getFileName(); @@ -314,7 +313,7 @@ public class DownloadGroupTarget extends BaseGroupTarget im @CheckResult @Override public DownloadGroupTarget addHeader(@NonNull String key, @NonNull String value) { - for (DownloadTaskEntity subTask : mTaskEntity.getSubTaskEntities()) { + for (DTaskWrapper subTask : mTaskWrapper.getSubTaskWrapper()) { mDelegate.addHeader(subTask, key, value); } return mDelegate.addHeader(key, value); @@ -322,7 +321,7 @@ public class DownloadGroupTarget extends BaseGroupTarget im @CheckResult @Override public DownloadGroupTarget addHeaders(Map headers) { - for (DownloadTaskEntity subTask : mTaskEntity.getSubTaskEntities()) { + for (DTaskWrapper subTask : mTaskWrapper.getSubTaskWrapper()) { mDelegate.addHeaders(subTask, headers); } return mDelegate.addHeaders(headers); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java index 927342ce..a0df1a07 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java @@ -23,7 +23,7 @@ import com.arialyy.aria.core.download.downloader.DownloadGroupUtil; import com.arialyy.aria.core.download.downloader.FtpDirDownloadUtil; import com.arialyy.aria.core.download.downloader.IDownloadGroupListener; import com.arialyy.aria.core.inf.AbsGroupTask; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.util.CheckUtil; @@ -31,30 +31,30 @@ import com.arialyy.aria.util.CheckUtil; * Created by AriaL on 2017/6/27. * 任务组任务 */ -public class DownloadGroupTask extends AbsGroupTask { +public class DownloadGroupTask extends AbsGroupTask { - private DownloadGroupTask(DownloadGroupTaskEntity taskEntity, Handler outHandler) { - mTaskEntity = taskEntity; + private DownloadGroupTask(DGTaskWrapper taskEntity, Handler outHandler) { + mTaskWrapper = taskEntity; mOutHandler = outHandler; mContext = AriaManager.APP; mListener = new DownloadGroupListener(this, mOutHandler); switch (taskEntity.getRequestType()) { - case AbsTaskEntity.D_HTTP: - mUtil = new DownloadGroupUtil((IDownloadGroupListener) mListener, mTaskEntity); + case AbsTaskWrapper.D_HTTP: + mUtil = new DownloadGroupUtil((IDownloadGroupListener) mListener, mTaskWrapper); break; - case AbsTaskEntity.D_FTP_DIR: - mUtil = new FtpDirDownloadUtil((IDownloadGroupListener) mListener, mTaskEntity); + case AbsTaskWrapper.D_FTP_DIR: + mUtil = new FtpDirDownloadUtil((IDownloadGroupListener) mListener, mTaskWrapper); break; } } public DownloadGroupEntity getEntity() { - return mTaskEntity.getEntity(); + return mTaskWrapper.getEntity(); } @Override public String getTaskName() { - return "任务组->" + (TextUtils.isEmpty(mTaskEntity.getEntity().getAlias()) - ? mTaskEntity.getEntity().getGroupName() : mTaskEntity.getEntity().getAlias()); + return "任务组->" + (TextUtils.isEmpty(mTaskWrapper.getEntity().getAlias()) + ? mTaskWrapper.getEntity().getGroupName() : mTaskWrapper.getEntity().getAlias()); } @Override public int getTaskType() { @@ -62,10 +62,10 @@ public class DownloadGroupTask extends AbsGroupTask urls) { + public DGTaskWrapper getGroupTask(List urls) { if (urls == null || urls.isEmpty()) { ALog.e(TAG, "获取任务组实体失败:任务组子任务下载地址列表为null"); return null; @@ -260,7 +260,7 @@ public class DownloadReceiver extends AbsReceiver { if (!taskExists(urls)) { return null; } - return TEManager.getInstance().getGTEntity(DownloadGroupTaskEntity.class, urls); + return TEManager.getInstance().getGTEntity(DGTaskWrapper.class, urls); } /** @@ -269,7 +269,7 @@ public class DownloadReceiver extends AbsReceiver { * @param dirUrl FTP文件夹本地下载路径 * @return 返回对应的任务组实体;如果查找不到对应的数据或路径为null,返回null */ - public DownloadGroupTaskEntity getFtpDirTask(String dirUrl) { + public DGTaskWrapper getFtpDirTask(String dirUrl) { if (TextUtils.isEmpty(dirUrl)) { ALog.e(TAG, "获取FTP文件夹实体失败:下载路径为null"); return null; @@ -279,7 +279,7 @@ public class DownloadReceiver extends AbsReceiver { if (!b) { return null; } - return TEManager.getInstance().getFDTEntity(DownloadGroupTaskEntity.class, dirUrl); + return TEManager.getInstance().getFDTEntity(DGTaskWrapper.class, dirUrl); } /** @@ -288,7 +288,7 @@ public class DownloadReceiver extends AbsReceiver { * @return {@code true}存在,{@code false} 不存在 */ public boolean taskExists(String downloadUrl) { - return DbEntity.checkDataExist(DownloadTaskEntity.class, "url=?", downloadUrl); + return DbEntity.checkDataExist(DTaskWrapper.class, "url=?", downloadUrl); } /** @@ -369,7 +369,7 @@ public class DownloadReceiver extends AbsReceiver { public void stopAllTask() { AriaManager.getInstance(AriaManager.APP) .setCmd(NormalCmdFactory.getInstance() - .createCmd(new DownloadTaskEntity(), NormalCmdFactory.TASK_STOP_ALL, + .createCmd(new DTaskWrapper(), NormalCmdFactory.TASK_STOP_ALL, ICmd.TASK_TYPE_DOWNLOAD)) .exe(); } @@ -382,7 +382,7 @@ public class DownloadReceiver extends AbsReceiver { public void resumeAllTask() { AriaManager.getInstance(AriaManager.APP) .setCmd(NormalCmdFactory.getInstance() - .createCmd(new DownloadTaskEntity(), NormalCmdFactory.TASK_RESUME_ALL, + .createCmd(new DTaskWrapper(), NormalCmdFactory.TASK_RESUME_ALL, ICmd.TASK_TYPE_DOWNLOAD)) .exe(); } @@ -396,7 +396,7 @@ public class DownloadReceiver extends AbsReceiver { public void removeAllTask(boolean removeFile) { final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP); CancelAllCmd cancelCmd = - (CancelAllCmd) CommonUtil.createNormalCmd(new DownloadTaskEntity(), + (CancelAllCmd) CommonUtil.createNormalCmd(new DTaskWrapper(), NormalCmdFactory.TASK_CANCEL_ALL, ICmd.TASK_TYPE_DOWNLOAD); cancelCmd.removeFile = removeFile; ariaManager.setCmd(cancelCmd).exe(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java index f9ccfd26..0e6b8c7d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java @@ -17,7 +17,6 @@ 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.common.http.GetDelegate; import com.arialyy.aria.core.common.http.HttpHeaderDelegate; import com.arialyy.aria.core.common.http.PostDelegate; @@ -64,7 +63,7 @@ public class DownloadTarget extends BaseNormalTarget */ @CheckResult public DownloadTarget useServerFileName(boolean use) { - mTaskEntity.setUseServerFileName(use); + mTaskWrapper.asHttp().setUseServerFileName(use); return this; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java index f61e8b9d..a999e121 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java @@ -23,18 +23,17 @@ import com.arialyy.aria.core.download.downloader.SimpleDownloadUtil; import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.scheduler.ISchedulers; -import com.arialyy.aria.util.ALog; import java.io.File; /** * Created by lyy on 2016/8/11. * 下载任务类 */ -public class DownloadTask extends AbsNormalTask { +public class DownloadTask extends AbsNormalTask { public static final String TAG = "DownloadTask"; - private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) { - mTaskEntity = taskEntity; + private DownloadTask(DTaskWrapper taskEntity, Handler outHandler) { + mTaskWrapper = taskEntity; mOutHandler = outHandler; mContext = AriaManager.APP; mListener = new BaseDListener(this, mOutHandler); @@ -56,7 +55,7 @@ public class DownloadTask extends AbsNormalTask private void init(String key) { mGroupName = key; - mTaskEntity = TEManager.getInstance().getFDTEntity(DownloadGroupTaskEntity.class, key); - mTaskEntity.setRequestType(AbsTaskEntity.D_FTP_DIR); - mEntity = mTaskEntity.getEntity(); + mTaskWrapper = TEManager.getInstance().getFDTEntity(DGTaskWrapper.class, key); + mTaskWrapper.setRequestType(AbsTaskWrapper.D_FTP_DIR); + mEntity = mTaskWrapper.getEntity(); if (mEntity != null) { mDirPathTemp = mEntity.getDirPath(); } @@ -58,12 +58,11 @@ public class FtpDirDownloadTarget extends BaseGroupTarget boolean b = getTargetType() == GROUP_FTP_DIR && checkDirPath() && checkUrl(); if (b) { mEntity.save(); - mTaskEntity.save(); - if (mTaskEntity.getSubTaskEntities() != null) { + if (mTaskWrapper.getSubTaskWrapper() != null) { //初始化子项的登录信息 - FtpUrlEntity tUrlEntity = mTaskEntity.getUrlEntity(); - for (DownloadTaskEntity entity : mTaskEntity.getSubTaskEntities()) { - FtpUrlEntity urlEntity = entity.getUrlEntity(); + FtpUrlEntity tUrlEntity = mTaskWrapper.asFtp().getUrlEntity(); + for (DTaskWrapper wrapper : mTaskWrapper.getSubTaskWrapper()) { + FtpUrlEntity urlEntity = wrapper.asFtp().getUrlEntity(); urlEntity.needLogin = tUrlEntity.needLogin; urlEntity.account = tUrlEntity.account; urlEntity.user = tUrlEntity.user; @@ -79,12 +78,12 @@ public class FtpDirDownloadTarget extends BaseGroupTarget } } } - if (mTaskEntity.getUrlEntity().isFtps) { - if (TextUtils.isEmpty(mTaskEntity.getUrlEntity().storePath)) { + if (mTaskWrapper.asFtp().getUrlEntity().isFtps) { + if (TextUtils.isEmpty(mTaskWrapper.asFtp().getUrlEntity().storePath)) { ALog.e(TAG, "证书路径为空"); return false; } - if (TextUtils.isEmpty(mTaskEntity.getUrlEntity().keyAlias)) { + if (TextUtils.isEmpty(mTaskWrapper.asFtp().getUrlEntity().keyAlias)) { ALog.e(TAG, "证书别名为空"); return false; } @@ -121,7 +120,7 @@ public class FtpDirDownloadTarget extends BaseGroupTarget */ @CheckResult public FTPSConfig asFtps() { - mTaskEntity.getUrlEntity().isFtps = true; + mTaskWrapper.asFtp().getUrlEntity().isFtps = true; return new FTPSConfig<>(this); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java index 1c19c66c..b7d339b0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java @@ -20,7 +20,8 @@ import android.support.annotation.NonNull; import android.text.TextUtils; import com.arialyy.aria.core.common.ftp.FTPSConfig; import com.arialyy.aria.core.common.ftp.FtpDelegate; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.common.ftp.FtpTaskDelegate; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IFtpTarget; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; @@ -45,9 +46,9 @@ public class FtpDownloadTarget extends BaseNormalTarget private void init() { int lastIndex = url.lastIndexOf("/"); - mEntity.setFileName(url.substring(lastIndex + 1, url.length())); - mTaskEntity.setUrlEntity(CommonUtil.getFtpUrlInfo(url)); - mTaskEntity.setRequestType(AbsTaskEntity.D_FTP); + mEntity.setFileName(url.substring(lastIndex + 1)); + mTaskWrapper.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(url)); + mTaskWrapper.setRequestType(AbsTaskWrapper.D_FTP); mDelegate = new FtpDelegate<>(this); } @@ -59,17 +60,17 @@ public class FtpDownloadTarget extends BaseNormalTarget */ @CheckResult public FTPSConfig asFtps() { - mTaskEntity.getUrlEntity().isFtps = true; + mTaskWrapper.asFtp().getUrlEntity().isFtps = true; return new FTPSConfig<>(this); } @Override protected boolean checkEntity() { - if (mTaskEntity.getUrlEntity().isFtps){ - if (TextUtils.isEmpty(mTaskEntity.getUrlEntity().storePath)){ + if (mTaskWrapper.asFtp().getUrlEntity().isFtps){ + if (TextUtils.isEmpty(mTaskWrapper.asFtp().getUrlEntity().storePath)){ ALog.e(TAG, "证书路径为空"); return false; } - if (TextUtils.isEmpty(mTaskEntity.getUrlEntity().keyAlias)){ + if (TextUtils.isEmpty(mTaskWrapper.asFtp().getUrlEntity().keyAlias)){ ALog.e(TAG, "证书别名为空"); return false; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java index 45e50fb5..efa7339e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java @@ -17,9 +17,9 @@ package com.arialyy.aria.core.download.downloader; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.IUtil; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.download.DownloadGroupTaskEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.exception.BaseException; @@ -56,23 +56,23 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { long mTotalLen = 0; long mCurrentLocation = 0; protected IDownloadGroupListener mListener; - DownloadGroupTaskEntity mGTEntity; + DGTaskWrapper mGTWrapper; private boolean isRunning = false; private ScheduledThreadPoolExecutor mTimer; /** * 保存所有没有下载完成的任务,key为下载地址 */ - Map mExeMap = new ConcurrentHashMap<>(); + Map mExeMap = new ConcurrentHashMap<>(); /** * 下载失败的映射表,key为下载地址 */ - Map mFailMap = new ConcurrentHashMap<>(); + Map mFailMap = new ConcurrentHashMap<>(); /** * 该任务组对应的所有任务 */ - private Map mTasksMap = new ConcurrentHashMap<>(); + private Map mTasksMap = new ConcurrentHashMap<>(); /** * 下载器映射表,key为下载地址 @@ -92,9 +92,9 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { private long mUpdateInterval = 1000; private boolean isStop = false, isCancel = false; - AbsGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity groupEntity) { + AbsGroupUtil(IDownloadGroupListener listener, DGTaskWrapper groupEntity) { mListener = listener; - mGTEntity = groupEntity; + mGTWrapper = groupEntity; mUpdateInterval = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getUpdateInterval(); } @@ -111,8 +111,8 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { */ void updateFileSize() { if (isNeedLoadFileSize) { - mGTEntity.getEntity().setFileSize(mTotalLen); - mGTEntity.getEntity().update(); + mGTWrapper.getEntity().setFileSize(mTotalLen); + mGTWrapper.getEntity().update(); } } @@ -154,7 +154,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { public void cancelSubTask(String url) { Set urls = mTasksMap.keySet(); if (!urls.isEmpty() && urls.contains(url)) { - DownloadTaskEntity det = mTasksMap.get(url); + DTaskWrapper det = mTasksMap.get(url); if (det != null) { mTotalLen -= det.getEntity().getFileSize(); mCurrentLocation -= det.getEntity().getCurrentProgress(); @@ -166,7 +166,6 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { mListener.onCancel(); } } - mGTEntity.update(); } Downloader d = getDownloader(url, false); if (d != null) { @@ -182,7 +181,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { * @return {@code true} 任务可以下载 */ private boolean checkSubTask(String url, String type) { - DownloadTaskEntity entity = mTasksMap.get(url); + DTaskWrapper entity = mTasksMap.get(url); if (entity != null) { if (entity.getState() == IEntity.STATE_COMPLETE) { ALog.w(TAG, "任务【" + url + "】已完成," + type + "失败"); @@ -267,10 +266,10 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { protected void onPre() { mListener.onPre(); isRunning = true; - mGroupSize = mGTEntity.getSubTaskEntities().size(); - mTotalLen = mGTEntity.getEntity().getFileSize(); + mGroupSize = mGTWrapper.getSubTaskWrapper().size(); + mTotalLen = mGTWrapper.getEntity().getFileSize(); isNeedLoadFileSize = mTotalLen <= 10; - for (DownloadTaskEntity te : mGTEntity.getSubTaskEntities()) { + for (DTaskWrapper te : mGTWrapper.getSubTaskWrapper()) { File file = new File(te.getKey()); if (te.getState() == IEntity.STATE_COMPLETE && file.exists()) { mCompleteNum++; @@ -351,7 +350,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { closeTimer(); } else if (mCurrentLocation >= 0) { long t = 0; - for (DownloadTaskEntity te : mGTEntity.getSubTaskEntities()) { + for (DTaskWrapper te : mGTWrapper.getSubTaskWrapper()) { if (te.getState() == IEntity.STATE_COMPLETE) { t += te.getEntity().getFileSize(); } else { @@ -368,7 +367,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { /** * 创建子任务下载器,默认创建完成自动启动 */ - void createChildDownload(DownloadTaskEntity taskEntity) { + void createChildDownload(DTaskWrapper taskEntity) { createChildDownload(taskEntity, true); } @@ -377,7 +376,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { * * @param start 是否启动下载 */ - private Downloader createChildDownload(DownloadTaskEntity taskEntity, boolean start) { + private Downloader createChildDownload(DTaskWrapper taskEntity, boolean start) { ChildDownloadListener listener = new ChildDownloadListener(taskEntity); Downloader dt = new Downloader(listener, taskEntity); mDownloaderMap.put(taskEntity.getEntity().getUrl(), dt); @@ -391,7 +390,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { * 子任务事件监听 */ private class ChildDownloadListener implements IDownloadListener { - private DownloadTaskEntity subTaskEntity; + private DTaskWrapper subTaskEntity; private DownloadEntity subEntity; private int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度 private long lastSaveTime; @@ -399,7 +398,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { private ScheduledThreadPoolExecutor timer; private boolean isNotNetRetry; - ChildDownloadListener(DownloadTaskEntity entity) { + ChildDownloadListener(DTaskWrapper entity) { subTaskEntity = entity; subEntity = subTaskEntity.getEntity(); subEntity.setFailNum(0); @@ -514,7 +513,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { } if (mFailMap.size() == mGroupSize) { mListener.onFail(true, new TaskException(TAG, - String.format("任务组【%s】下载失败", mGTEntity.getEntity().getGroupName()))); + String.format("任务组【%s】下载失败", mGTWrapper.getEntity().getGroupName()))); } else if (mFailMap.size() + mCompleteNum >= mExeMap.size()) { mListener.onStop(mCurrentLocation); } @@ -549,7 +548,6 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { subEntity.setComplete(state == IEntity.STATE_COMPLETE); if (state == IEntity.STATE_CANCEL) { subEntity.deleteData(); - return; } else if (state == IEntity.STATE_STOP) { subEntity.setStopTime(System.currentTimeMillis()); } else if (subEntity.isComplete()) { @@ -558,7 +556,6 @@ public abstract class AbsGroupUtil implements IUtil, Runnable { } else if (location > 0) { subEntity.setCurrentProgress(location); } - subTaskEntity.update(); } @Override public void supportBreakpoint(boolean support) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java index 0f0c30f2..eff27ff4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java @@ -19,17 +19,14 @@ import android.text.TextUtils; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.ProtocolType; 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.core.common.http.HttpTaskDelegate; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.SSLContextUtil; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStreamWriter; import java.net.CookieManager; import java.net.CookieStore; -import java.net.HttpCookie; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; @@ -55,9 +52,9 @@ class ConnectionHelp { * * @throws MalformedURLException */ - static URL handleUrl(String url, AbsTaskEntity taskEntity) throws MalformedURLException { - Map params = taskEntity.getParams(); - if (params != null && taskEntity.getRequestEnum() == RequestEnum.GET) { + static URL handleUrl(String url, HttpTaskDelegate taskDelegate) throws MalformedURLException { + Map params = taskDelegate.getParams(); + if (params != null && taskDelegate.getRequestEnum() == RequestEnum.GET) { if (url.contains("?")) { ALog.e(TAG, String.format("设置参数失败,url中已经有?,url: %s", url)); return new URL(CommonUtil.convertUrl(url)); @@ -101,11 +98,12 @@ class ConnectionHelp { * * @throws IOException */ - static HttpURLConnection handleConnection(URL url, AbsTaskEntity taskEntity) throws IOException { + static HttpURLConnection handleConnection(URL url, HttpTaskDelegate taskDelegate) + throws IOException { HttpURLConnection conn; URLConnection urlConn; - if (taskEntity.getProxy() != null) { - urlConn = url.openConnection(taskEntity.getProxy()); + if (taskDelegate.getProxy() != null) { + urlConn = url.openConnection(taskDelegate.getProxy()); } else { urlConn = url.openConnection(); } @@ -132,17 +130,17 @@ class ConnectionHelp { * * @throws ProtocolException */ - static HttpURLConnection setConnectParam(DownloadTaskEntity entity, HttpURLConnection conn) { - if (entity.getRequestEnum() == RequestEnum.POST) { + static HttpURLConnection setConnectParam(HttpTaskDelegate delegate, HttpURLConnection conn) { + if (delegate.getRequestEnum() == RequestEnum.POST) { conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); } Set keys = null; - if (entity.getHeaders() != null && entity.getHeaders().size() > 0) { - keys = entity.getHeaders().keySet(); + if (delegate.getHeaders() != null && delegate.getHeaders().size() > 0) { + keys = delegate.getHeaders().keySet(); for (String key : keys) { - conn.setRequestProperty(key, entity.getHeaders().get(key)); + conn.setRequestProperty(key, delegate.getHeaders().get(key)); } } if (conn.getRequestProperty("Accept-Language") == null) { @@ -190,7 +188,7 @@ class ConnectionHelp { //302获取重定向地址 conn.setInstanceFollowRedirects(false); - CookieManager manager = entity.getCookieManager(); + CookieManager manager = delegate.getCookieManager(); if (manager != null) { CookieStore store = manager.getCookieStore(); if (store != null && store.getCookies().size() > 0) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java index fd9a8ccc..cd435aa3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java @@ -19,8 +19,8 @@ import android.util.SparseArray; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.IUtil; import com.arialyy.aria.core.common.OnFileInfoCallback; -import com.arialyy.aria.core.download.DownloadGroupTaskEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.download.DGTaskWrapper; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.TaskException; @@ -53,8 +53,8 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { */ private SparseArray mFileInfoCallbacks = new SparseArray<>(); - public DownloadGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity taskEntity) { - super(listener, taskEntity); + public DownloadGroupUtil(IDownloadGroupListener listener, DGTaskWrapper taskWrapper) { + super(listener, taskWrapper); mInfoPool = Executors.newCachedThreadPool(); } @@ -88,13 +88,13 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { if (mExeMap.size() == 0) { mListener.onFail(false, new TaskException(TAG, - String.format("任务组【%s】无可执行任务", mGTEntity.getEntity().getGroupName()))); + String.format("任务组【%s】无可执行任务", mGTWrapper.getEntity().getGroupName()))); return; } Set keys = mExeMap.keySet(); mExeNum = mExeMap.size(); for (String key : keys) { - DownloadTaskEntity taskEntity = mExeMap.get(key); + DTaskWrapper taskEntity = mExeMap.get(key); if (taskEntity != null) { if (taskEntity.getState() != IEntity.STATE_FAIL && taskEntity.getState() != IEntity.STATE_WAIT) { @@ -114,7 +114,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { /** * 创建文件信息获取线程 */ - private HttpFileInfoThread createFileInfoThread(DownloadTaskEntity taskEntity) { + private HttpFileInfoThread createFileInfoThread(DTaskWrapper taskEntity) { OnFileInfoCallback callback = mFileInfoCallbacks.get(taskEntity.hashCode()); if (callback == null) { @@ -123,7 +123,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { @Override public void onComplete(String url, CompleteInfo info) { if (isStop) return; - DownloadTaskEntity te = mExeMap.get(url); + DTaskWrapper te = mExeMap.get(url); if (te != null) { if (isNeedLoadFileSize) { mTotalLen += te.getEntity().getFileSize(); @@ -138,7 +138,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { @Override public void onFail(String url, BaseException e, boolean needRetry) { if (isStop) return; ALog.e(TAG, String.format("任务【%s】初始化失败", url)); - DownloadTaskEntity te = mExeMap.get(url); + DTaskWrapper te = mExeMap.get(url); if (te != null) { mFailMap.put(url, te); mFileInfoCallbacks.put(te.hashCode(), this); @@ -172,7 +172,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { if (mInitFailNum == mExeNum) { closeTimer(); mListener.onFail(true, new TaskException(TAG, - String.format("任务组【%s】初始化失败", mGTEntity.getEntity().getGroupName()))); + String.format("任务组【%s】初始化失败", mGTWrapper.getEntity().getGroupName()))); } if (!isStart && mInitCompleteNum + mInitFailNum == mExeNum || !isNeedLoadFileSize) { startRunningFlow(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java index 4590213b..3e1ac795 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java @@ -20,8 +20,8 @@ import com.arialyy.aria.core.common.AbsFileer; import com.arialyy.aria.core.common.AbsThreadTask; import com.arialyy.aria.core.common.SubThreadConfig; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.download.DTaskWrapper; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.TaskException; @@ -33,10 +33,10 @@ import java.io.IOException; * Created by AriaL on 2017/7/1. * 文件下载器 */ -class Downloader extends AbsFileer { +class Downloader extends AbsFileer { private String TAG = "Downloader"; - Downloader(IDownloadListener listener, DownloadTaskEntity taskEntity) { + Downloader(IDownloadListener listener, DTaskWrapper taskEntity) { super(listener, taskEntity); mTempFile = new File(mEntity.getDownloadPath()); AriaManager manager = AriaManager.getInstance(AriaManager.APP); @@ -48,8 +48,8 @@ class Downloader extends AbsFileer { return // 小于1m的文件或是任务组的子任务、使用虚拟文件,线程数都是1 mEntity.getFileSize() <= SUB_LEN - || mTaskEntity.getRequestType() == AbsTaskEntity.D_FTP_DIR - || mTaskEntity.getRequestType() == AbsTaskEntity.DG_HTTP + || mTaskEntity.getRequestType() == AbsTaskWrapper.D_FTP_DIR + || mTaskEntity.getRequestType() == AbsTaskWrapper.DG_HTTP || threadNum == 1 ? 1 : threadNum; @@ -95,12 +95,12 @@ class Downloader extends AbsFileer { } } - @Override protected AbsThreadTask selectThreadTask(SubThreadConfig config) { + @Override protected AbsThreadTask selectThreadTask(SubThreadConfig config) { switch (mTaskEntity.getRequestType()) { - case AbsTaskEntity.D_FTP: - case AbsTaskEntity.D_FTP_DIR: + case AbsTaskWrapper.D_FTP: + case AbsTaskWrapper.D_FTP_DIR: return new FtpThreadTask(mConstance, (IDownloadListener) mListener, config); - case AbsTaskEntity.D_HTTP: + case AbsTaskWrapper.D_HTTP: return new HttpThreadTask(mConstance, (IDownloadListener) mListener, config); } return null; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirDownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirDownloadUtil.java index 1cd0715c..f41d0f23 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirDownloadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirDownloadUtil.java @@ -17,11 +17,9 @@ package com.arialyy.aria.core.download.downloader; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.OnFileInfoCallback; -import com.arialyy.aria.core.download.DownloadGroupTaskEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.download.DGTaskWrapper; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.exception.BaseException; -import com.arialyy.aria.exception.TaskException; -import com.arialyy.aria.util.ErrorHelp; import java.util.Set; /** @@ -31,7 +29,7 @@ import java.util.Set; public class FtpDirDownloadUtil extends AbsGroupUtil { private String TAG = "FtpDirDownloadUtil"; - public FtpDirDownloadUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity taskEntity) { + public FtpDirDownloadUtil(IDownloadGroupListener listener, DGTaskWrapper taskEntity) { super(listener, taskEntity); } @@ -41,11 +39,11 @@ public class FtpDirDownloadUtil extends AbsGroupUtil { @Override protected void onStart() { super.onStart(); - if (mGTEntity.getEntity().getFileSize() > 1) { + if (mGTWrapper.getEntity().getFileSize() > 1) { onPre(); startDownload(); } else { - new FtpDirInfoThread(mGTEntity, new OnFileInfoCallback() { + new FtpDirInfoThread(mGTWrapper, new OnFileInfoCallback() { @Override public void onComplete(String url, CompleteInfo info) { if (info.code >= 200 && info.code < 300) { onPre(); @@ -54,7 +52,7 @@ public class FtpDirDownloadUtil extends AbsGroupUtil { } @Override public void onFail(String url, BaseException e, boolean needRetry) { - DownloadTaskEntity te = mExeMap.get(url); + DTaskWrapper te = mExeMap.get(url); if (te != null) { mFailMap.put(url, te); mExeMap.remove(url); @@ -73,7 +71,7 @@ public class FtpDirDownloadUtil extends AbsGroupUtil { int i = 0; Set keys = mExeMap.keySet(); for (String key : keys) { - DownloadTaskEntity taskEntity = mExeMap.get(key); + DTaskWrapper taskEntity = mExeMap.get(key); if (taskEntity != null) { createChildDownload(taskEntity); i++; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java index 7cdddfef..f9ffae7c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java @@ -20,27 +20,26 @@ import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.common.ftp.AbsFtpInfoThread; +import com.arialyy.aria.core.download.DGTaskWrapper; 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.download.DTaskWrapper; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.util.CommonUtil; import java.nio.charset.Charset; import java.util.ArrayList; /** - * Created by Aria.Lao on 2017/7/25. - * 获取ftp文件夹信息 + * Created by Aria.Lao on 2017/7/25. 获取ftp文件夹信息 */ -class FtpDirInfoThread extends AbsFtpInfoThread { +class FtpDirInfoThread extends AbsFtpInfoThread { - FtpDirInfoThread(DownloadGroupTaskEntity taskEntity, OnFileInfoCallback callback) { + FtpDirInfoThread(DGTaskWrapper taskEntity, OnFileInfoCallback callback) { super(taskEntity, callback); } @Override protected String setRemotePath() { - return mTaskEntity.getUrlEntity().remotePath; + return mTaskWrapper.asFtp().getUrlEntity().remotePath; } @Override protected void handleFile(String remotePath, FTPFile ftpFile) { @@ -58,36 +57,36 @@ class FtpDirInfoThread extends AbsFtpInfoThread()); } mEntity.getSubEntities().add(entity); - mTaskEntity.getSubTaskEntities().add(taskEntity); + mTaskWrapper.getSubTaskWrapper().add(taskEntity); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java index 96555e02..205d9109 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java @@ -19,8 +19,8 @@ import aria.apache.commons.net.ftp.FTPFile; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.common.ftp.AbsFtpInfoThread; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.exception.AriaIOException; import com.arialyy.aria.util.CommonUtil; @@ -28,10 +28,10 @@ import com.arialyy.aria.util.CommonUtil; * Created by Aria.Lao on 2017/7/25. * 获取ftp文件信息 */ -class FtpFileInfoThread extends AbsFtpInfoThread { +class FtpFileInfoThread extends AbsFtpInfoThread { private final String TAG = "FtpFileInfoThread"; - FtpFileInfoThread(DownloadTaskEntity taskEntity, OnFileInfoCallback callback) { + FtpFileInfoThread(DTaskWrapper taskEntity, OnFileInfoCallback callback) { super(taskEntity, callback); } @@ -46,13 +46,13 @@ class FtpFileInfoThread extends AbsFtpInfoThread { +class FtpThreadTask extends AbsFtpThreadTask { private final String TAG = "FtpThreadTask"; private boolean isOpenDynamicFile; private boolean isBlock; FtpThreadTask(StateConstance constance, IDownloadListener listener, - SubThreadConfig downloadInfo) { + SubThreadConfig downloadInfo) { super(constance, listener, downloadInfo); mConnectTimeOut = mAridManager.getDownloadConfig().getConnectTimeOut(); mReadTimeOut = mAridManager.getDownloadConfig().getIOTimeOut(); @@ -87,7 +87,7 @@ class FtpThreadTask extends AbsFtpThreadTask return this; } String remotePath = - new String(mTaskEntity.getUrlEntity().remotePath.getBytes(charSet), SERVER_CHARSET); + new String(mTaskWrapper.asFtp().getUrlEntity().remotePath.getBytes(charSet), SERVER_CHARSET); ALog.i(TAG, String.format("remotePath【%s】", remotePath)); is = client.retrieveFileStream(remotePath); reply = client.getReplyCode(); 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 14a5a9d1..5b498a1c 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 @@ -17,13 +17,13 @@ package com.arialyy.aria.core.download.downloader; import android.os.Process; 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; import com.arialyy.aria.core.common.RequestEnum; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.common.http.HttpTaskDelegate; import com.arialyy.aria.exception.AriaIOException; import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.TaskException; @@ -35,14 +35,12 @@ import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; -import java.net.CookieHandler; import java.net.CookieManager; import java.net.HttpCookie; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLDecoder; import java.net.URLEncoder; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; @@ -53,25 +51,27 @@ import java.util.Set; class HttpFileInfoThread implements Runnable { private final String TAG = "HttpFileInfoThread"; private DownloadEntity mEntity; - private DownloadTaskEntity mTaskEntity; + private DTaskWrapper mTaskWrapper; private int mConnectTimeOut; private OnFileInfoCallback onFileInfoCallback; + private HttpTaskDelegate mTaskDelegate; - HttpFileInfoThread(DownloadTaskEntity taskEntity, OnFileInfoCallback callback) { - this.mTaskEntity = taskEntity; - mEntity = taskEntity.getEntity(); + HttpFileInfoThread(DTaskWrapper taskWrapper, OnFileInfoCallback callback) { + this.mTaskWrapper = taskWrapper; + mEntity = taskWrapper.getEntity(); mConnectTimeOut = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getConnectTimeOut(); onFileInfoCallback = callback; + mTaskDelegate = taskWrapper.asHttp(); } @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); HttpURLConnection conn = null; try { - URL url = ConnectionHelp.handleUrl(mEntity.getUrl(), mTaskEntity); - conn = ConnectionHelp.handleConnection(url, mTaskEntity); - conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); + URL url = ConnectionHelp.handleUrl(mEntity.getUrl(), mTaskDelegate); + conn = ConnectionHelp.handleConnection(url, mTaskDelegate); + ConnectionHelp.setConnectParam(mTaskDelegate, conn); conn.setRequestProperty("Range", "bytes=" + 0 + "-"); conn.setConnectTimeout(mConnectTimeOut); //conn.setChunkedStreamingMode(0); @@ -89,8 +89,8 @@ class HttpFileInfoThread implements Runnable { } private void handleConnect(HttpURLConnection conn) throws IOException { - if (mTaskEntity.getRequestEnum() == RequestEnum.POST) { - Map params = mTaskEntity.getParams(); + if (mTaskDelegate.getRequestEnum() == RequestEnum.POST) { + Map params = mTaskDelegate.getParams(); if (params != null) { OutputStreamWriter dos = new OutputStreamWriter(conn.getOutputStream()); Set keys = params.keySet(); @@ -144,7 +144,7 @@ class HttpFileInfoThread implements Runnable { } Map> headers = conn.getHeaderFields(); String disposition = conn.getHeaderField("Content-Disposition"); - if (mTaskEntity.isUseServerFileName() && !TextUtils.isEmpty(disposition)) { + if (mTaskDelegate.isUseServerFileName() && !TextUtils.isEmpty(disposition)) { mEntity.setDisposition(CommonUtil.encryptBASE64(disposition)); if (disposition.contains(";")) { String[] infos = disposition.split(";"); @@ -168,10 +168,10 @@ class HttpFileInfoThread implements Runnable { for (String cookie : cookiesHeader) { msCookieManager.getCookieStore().add(null, HttpCookie.parse(cookie).get(0)); } - mTaskEntity.setCookieManager(msCookieManager); + mTaskDelegate.setCookieManager(msCookieManager); } - mTaskEntity.setCode(code); + mTaskWrapper.setCode(code); if (code == HttpURLConnection.HTTP_PARTIAL) { if (!checkLen(len) && !isChunked) { if (len < 0) { @@ -182,7 +182,7 @@ class HttpFileInfoThread implements Runnable { return; } mEntity.setFileSize(len); - mTaskEntity.setSupportBP(true); + mTaskWrapper.setSupportBP(true); end = true; } else if (code == HttpURLConnection.HTTP_OK) { String contentType = conn.getHeaderField("Content-Type"); @@ -210,8 +210,8 @@ class HttpFileInfoThread implements Runnable { return; } mEntity.setFileSize(len); - mTaskEntity.setNewTask(true); - mTaskEntity.setSupportBP(false); + mTaskWrapper.setNewTask(true); + mTaskWrapper.setSupportBP(false); end = true; } else if (code == HttpURLConnection.HTTP_NOT_FOUND) { failDownload(new AriaIOException(TAG, @@ -228,8 +228,7 @@ class HttpFileInfoThread implements Runnable { conn.getResponseMessage(), mEntity.getUrl())), true); } if (end) { - mTaskEntity.setChunked(isChunked); - mTaskEntity.update(); + mTaskDelegate.setChunked(isChunked); if (onFileInfoCallback != null) { CompleteInfo info = new CompleteInfo(code); onFileInfoCallback.onComplete(mEntity.getUrl(), info); @@ -252,7 +251,7 @@ class HttpFileInfoThread implements Runnable { } mEntity.setFileName(newName); mEntity.setDownloadPath(newPath); - mTaskEntity.setKey(newPath); + mTaskWrapper.setKey(newPath); } /** @@ -271,13 +270,13 @@ class HttpFileInfoThread implements Runnable { failDownload(new TaskException(TAG, "下载失败,重定向url错误"), false); return; } - mTaskEntity.setRedirectUrl(newUrl); + mTaskDelegate.setRedirectUrl(newUrl); mEntity.setRedirect(true); mEntity.setRedirectUrl(newUrl); String cookies = conn.getHeaderField("Set-Cookie"); - URL url = ConnectionHelp.handleUrl(newUrl, mTaskEntity); - conn = ConnectionHelp.handleConnection(url, mTaskEntity); - conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); + URL url = ConnectionHelp.handleUrl(newUrl, mTaskDelegate); + conn = ConnectionHelp.handleConnection(url, mTaskDelegate); + ConnectionHelp.setConnectParam(mTaskDelegate, conn); conn.setRequestProperty("Cookie", cookies); conn.setRequestProperty("Range", "bytes=" + 0 + "-"); conn.setConnectTimeout(mConnectTimeOut); @@ -294,7 +293,7 @@ class HttpFileInfoThread implements Runnable { */ private boolean checkLen(long len) { if (len != mEntity.getFileSize()) { - mTaskEntity.setNewTask(true); + mTaskWrapper.setNewTask(true); } return true; } 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 44c23d79..6229e906 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 @@ -19,14 +19,14 @@ import com.arialyy.aria.core.common.AbsThreadTask; import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.common.StateConstance; import com.arialyy.aria.core.common.SubThreadConfig; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.common.http.HttpTaskDelegate; import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.exception.AriaIOException; import com.arialyy.aria.exception.TaskException; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.BufferedRandomAccessFile; -import com.arialyy.aria.util.CommonUtil; import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -47,13 +47,13 @@ import java.util.Set; * Created by lyy on 2017/1/18. * 下载线程 */ -final class HttpThreadTask extends AbsThreadTask { +final class HttpThreadTask extends AbsThreadTask { private final String TAG = "HttpThreadTask"; private boolean isOpenDynamicFile; private boolean isBlock; HttpThreadTask(StateConstance constance, IDownloadListener listener, - SubThreadConfig downloadInfo) { + SubThreadConfig downloadInfo) { super(constance, listener, downloadInfo); mConnectTimeOut = mAridManager.getDownloadConfig().getConnectTimeOut(); mReadTimeOut = mAridManager.getDownloadConfig().getIOTimeOut(); @@ -75,8 +75,9 @@ final class HttpThreadTask extends AbsThreadTask params = mTaskEntity.getParams(); + if (taskDelegate.getRequestEnum() == RequestEnum.POST) { + Map params = taskDelegate.getParams(); if (params != null) { OutputStreamWriter dos = new OutputStreamWriter(conn.getOutputStream()); Set keys = params.keySet(); @@ -115,7 +116,7 @@ final class HttpThreadTask extends AbsThreadTask subTaskEntity; + public List subTaskEntity; @Override protected void handleConvert() { if (subTaskEntity != null && !subTaskEntity.isEmpty()) { - dgTaskEntity.setSubTaskEntities(subTaskEntity); + dgTaskEntity.setSubTaskWrapper(subTaskEntity); } } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/wrapper/DGTEWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/download/wrapper/DGTEWrapper.java index 680585ac..d0497e7b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/wrapper/DGTEWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/wrapper/DGTEWrapper.java @@ -15,10 +15,10 @@ */ package com.arialyy.aria.core.download.wrapper; +import com.arialyy.aria.core.download.DGTaskWrapper; 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.download.DTaskWrapper; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.orm.AbsWrapper; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.annotation.Many; @@ -39,26 +39,26 @@ public class DGTEWrapper extends AbsWrapper { public DownloadGroupEntity entity; @Many(parentColumn = "groupName", entityColumn = "key") - private List taskEntitys; + private List taskEntitys; - public DownloadGroupTaskEntity taskEntity; + public DGTaskWrapper taskEntity; @Override protected void handleConvert() { taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0); if (taskEntity != null) { taskEntity.setEntity(entity); List subWrappers = - DbEntity.findRelationData(DTEWrapper.class, "DownloadTaskEntity.groupName=?", + DbEntity.findRelationData(DTEWrapper.class, "DTaskWrapper.groupName=?", taskEntity.getKey()); if (subWrappers != null && !subWrappers.isEmpty()) { - List temp = new ArrayList<>(); + List temp = new ArrayList<>(); for (DTEWrapper dw : subWrappers) { - if (dw.taskEntity.getRequestType() == AbsTaskEntity.D_FTP) { - dw.taskEntity.setUrlEntity(CommonUtil.getFtpUrlInfo(dw.taskEntity.getUrl())); + if (dw.taskEntity.getRequestType() == AbsTaskWrapper.D_FTP) { + dw.taskEntity.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(dw.taskEntity.getUrl())); } temp.add(dw.taskEntity); } - taskEntity.setSubTaskEntities(temp); + taskEntity.setSubTaskWrapper(temp); } } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/wrapper/DTEWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/download/wrapper/DTEWrapper.java index d2062f98..74782405 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/wrapper/DTEWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/wrapper/DTEWrapper.java @@ -16,7 +16,7 @@ package com.arialyy.aria.core.download.wrapper; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.orm.AbsWrapper; import com.arialyy.aria.orm.annotation.Many; import com.arialyy.aria.orm.annotation.One; @@ -33,9 +33,9 @@ public class DTEWrapper extends AbsWrapper { public DownloadEntity entity; @Many(parentColumn = "downloadPath", entityColumn = "key") - private List taskEntitys = null; + private List taskEntitys = null; - public DownloadTaskEntity taskEntity; + public DTaskWrapper taskEntity; @Override public void handleConvert() { taskEntity = (taskEntitys == null || taskEntitys.isEmpty()) ? null : taskEntitys.get(0); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java index d0c78240..abf828fe 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java @@ -20,7 +20,6 @@ import android.os.Parcelable; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.annotation.Ignore; import java.io.Serializable; - /** * Created by AriaL on 2017/6/29. */ @@ -180,8 +179,8 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable, /** * 实体驱动的下载任务类型 * - * @return {@link AbsTaskEntity#D_FTP}、{@link AbsTaskEntity#D_FTP_DIR}、{@link - * AbsTaskEntity#U_HTTP}... + * @return {@link AbsTaskWrapper#D_FTP}、{@link AbsTaskWrapper#D_FTP_DIR}、{@link + * AbsTaskWrapper#U_HTTP}... */ public abstract int getTaskType(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java index ce2e5f8c..43d3f4dd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java @@ -21,11 +21,11 @@ import com.arialyy.aria.core.download.downloader.AbsGroupUtil; * Created by AriaL on 2017/6/29. * 任务组任务抽象类 */ -public abstract class AbsGroupTask +public abstract class AbsGroupTask extends AbsTask { @Override public String getKey() { - return mTaskEntity.getEntity().getKey(); + return mTaskWrapper.getEntity().getKey(); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTaskEntity.java deleted file mode 100644 index 066c8fe9..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTaskEntity.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.arialyy.aria.core.inf; - -/** - * Created by lyy on 2017/9/5. - */ -public abstract class AbsGroupTaskEntity extends AbsTaskEntity{ - @Override public ENTITY getEntity() { - return null; - } -} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/IPostDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTaskWrapper.java similarity index 59% rename from Aria/src/main/java/com/arialyy/aria/core/inf/IPostDelegate.java rename to Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTaskWrapper.java index b5ace80a..0bc856f3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/IPostDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTaskWrapper.java @@ -15,17 +15,16 @@ */ package com.arialyy.aria.core.inf; -import java.util.Map; +import com.arialyy.aria.core.download.DownloadGroupEntity; +import java.util.List; /** - * post 通用处理接口 + * 组合任务实体包裹器,用于加载和任务相关的参数,如:组合任务实体{@link DownloadGroupEntity} */ -public interface IPostDelegate { +public abstract class AbsGroupTaskWrapper + extends AbsTaskWrapper { - /** - * 设置Post请求参数 - */ - TARGET setParams(Map params); + public abstract List getSubTaskWrapper(); - TARGET setParam(String key, String value); + public abstract void setSubTaskWrapper(List subTaskWrapper); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java index 3fd15067..71db595d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java @@ -18,8 +18,8 @@ package com.arialyy.aria.core.inf; /** * Created by lyy on 2017/6/3. */ -public abstract class AbsNormalTask - extends AbsTask { +public abstract class AbsNormalTask + extends AbsTask { /** * 最高优先级命令,最高优先级命令有以下属性 diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java index 3eb6a485..a100a1fc 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java @@ -22,12 +22,11 @@ import com.arialyy.aria.core.command.ICmd; import com.arialyy.aria.core.command.normal.CancelCmd; import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.common.TaskRecord; -import com.arialyy.aria.core.common.http.PostDelegate; +import com.arialyy.aria.core.download.DGTaskWrapper; 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.download.DTaskWrapper; import com.arialyy.aria.core.manager.TEManager; -import com.arialyy.aria.core.upload.UploadTaskEntity; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; @@ -37,11 +36,11 @@ import java.util.List; /** * Created by AriaL on 2017/7/3. */ -public abstract class AbsTarget +public abstract class AbsTarget implements ITarget { protected String TAG; protected ENTITY mEntity; - protected TASK_ENTITY mTaskEntity; + protected TASK_WRAPPER mTaskWrapper; protected String mTargetName; protected AbsTarget() { @@ -55,8 +54,8 @@ public abstract class AbsTarget cmds = new ArrayList<>(); int taskType = checkTaskType(); cmds.add( - CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_STOP, taskType)); - cmds.add(CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_START, taskType)); + CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_STOP, taskType)); + cmds.add(CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_START, taskType)); AriaManager.getInstance(AriaManager.APP).setCmds(cmds).exe(); } } @@ -290,7 +289,7 @@ public abstract class AbsTarget - implements ITask { +public abstract class AbsTask + implements ITask { public static final String ERROR_INFO_KEY = "ERROR_INFO_KEY"; /** * 是否需要重试,默认为true */ public boolean needRetry = true; - protected TASK_ENTITY mTaskEntity; + protected TASK_WRAPPER mTaskWrapper; protected Handler mOutHandler; protected Context mContext; boolean isHeighestTask = false; @@ -101,14 +100,14 @@ public abstract class AbsTask extends DbEntity { - /** - * HTTP单任务载 - */ - public static final int D_HTTP = 0x11; - /** - * HTTP任务组下载 - */ - public static final int DG_HTTP = 0x12; - - /** - * FTP单文件下载 - */ - public static final int D_FTP = 0x13; - /** - * FTP文件夹下载,为避免登录过多,子任务由单线程进行处理 - */ - public static final int D_FTP_DIR = 0x14; - - /** - * HTTP单文件上传 - */ - public static final int U_HTTP = 0xA1; - /** - * FTP单文件上传 - */ - public static final int U_FTP = 0xA2; - - @Ignore private CookieManager cookieManager; - - /** - * 账号和密码 - */ - @Ignore private FtpUrlEntity urlEntity; - - /** - * 刷新信息 {@code true} 重新刷新下载信息 - */ - @Ignore private boolean refreshInfo = false; - - /** - * 是否是新任务,{@code true} 新任务 - */ - @Ignore private boolean isNewTask = false; - - /** - * 请求参数 - */ - @Ignore private Map params; - - /** - * 任务状态,和Entity的state同步 - */ - private int state = IEntity.STATE_WAIT; - - /** - * 请求类型 - * {@link AbsTaskEntity#D_HTTP}、{@link AbsTaskEntity#D_FTP}、{@link AbsTaskEntity#D_FTP_DIR}。。。 - */ - private int requestType = D_HTTP; - - /** - * http 请求头 - */ - private Map headers = new HashMap<>(); - - /** - * 字符编码,默认为"utf-8" - */ - private String charSet = "utf-8"; - - /** - * 网络请求类型 - */ - private RequestEnum requestEnum = RequestEnum.GET; - - /** - * 是否使用服务器通过content-disposition传递的文件名,内容格式{@code attachment; filename="filename.jpg"} - * {@code true} 使用 - */ - private boolean useServerFileName = false; - - /** - * 重定向链接 - */ - private String redirectUrl = ""; - - /** - * 删除任务时,是否删除已下载完成的文件 - * 未完成的任务,不管true还是false,都会删除文件 - * {@code true} 删除任务数据库记录,并且删除已经下载完成的文件 - * {@code false} 如果任务已经完成,只删除任务数据库记录 - */ - @Ignore private boolean removeFile = false; - - /** - * 是否支持断点, {@code true} 为支持断点 - */ - private boolean isSupportBP = true; - - /** - * 状态码 - */ - private int code; - - @Ignore private Proxy proxy; - - public abstract ENTITY getEntity(); - - public CookieManager getCookieManager() { - return cookieManager; - } - - public void setCookieManager(CookieManager cookieManager) { - this.cookieManager = cookieManager; - } - - /** - * 获取任务下载状态 - * - * @return {@link IEntity} - */ - public int getState() { - 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); - - @Override public void update() { - if (getEntity() != null) { - getEntity().update(); - } - super.update(); - } - - public FtpUrlEntity getUrlEntity() { - return urlEntity; - } - - public void setUrlEntity(FtpUrlEntity urlEntity) { - this.urlEntity = urlEntity; - } - - public boolean isRefreshInfo() { - return refreshInfo; - } - - public void setRefreshInfo(boolean refreshInfo) { - this.refreshInfo = refreshInfo; - } - - public boolean isNewTask() { - return isNewTask; - } - - public void setNewTask(boolean newTask) { - isNewTask = newTask; - } - - public void setState(int state) { - this.state = state; - } - - public int getRequestType() { - return requestType; - } - - public void setRequestType(int requestType) { - this.requestType = requestType; - } - - public Map getHeaders() { - return headers; - } - - public void setHeaders(Map headers) { - this.headers = headers; - } - - public String getCharSet() { - return charSet; - } - - public void setCharSet(String charSet) { - this.charSet = charSet; - } - - public RequestEnum getRequestEnum() { - return requestEnum; - } - - public void setRequestEnum(RequestEnum requestEnum) { - this.requestEnum = requestEnum; - } - - public boolean isUseServerFileName() { - return useServerFileName; - } - - public void setUseServerFileName(boolean useServerFileName) { - this.useServerFileName = useServerFileName; - } - - public String getRedirectUrl() { - return redirectUrl; - } - - public void setRedirectUrl(String redirectUrl) { - this.redirectUrl = redirectUrl; - } - - public boolean isRemoveFile() { - return removeFile; - } - - public void setRemoveFile(boolean removeFile) { - this.removeFile = removeFile; - } - - public boolean isSupportBP() { - return isSupportBP; - } - - public void setSupportBP(boolean supportBP) { - isSupportBP = supportBP; - } - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public Map getParams() { - return params; - } - - public void setParams(Map params) { - this.params = params; - } -} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java new file mode 100644 index 00000000..0285748e --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskWrapper.java @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.inf; + +import com.arialyy.aria.core.common.ftp.FtpTaskDelegate; +import com.arialyy.aria.core.common.http.HttpTaskDelegate; + +/** + * Created by lyy on 2017/2/23. 所有任务实体的父类 + */ +public abstract class AbsTaskWrapper + implements ITaskWrapper { + + private HttpTaskDelegate httpTaskDelegate; + private FtpTaskDelegate ftpTaskDelegate; + + /** + * 刷新信息 {@code true} 重新刷新下载信息 + */ + private boolean refreshInfo = false; + + /** + * 任务状态,和Entity的state同步 + */ + private int state = IEntity.STATE_WAIT; + + /** + * 是否是新任务,{@code true} 新任务 + */ + private boolean isNewTask = false; + + /** + * 请求类型 {@link AbsTaskWrapper#D_HTTP}、{@link AbsTaskWrapper#D_FTP}、{@link + * AbsTaskWrapper#D_FTP_DIR}。。。 + */ + private int requestType = D_HTTP; + + /** + * 删除任务时,是否删除已下载完成的文件 未完成的任务,不管true还是false,都会删除文件 {@code true} 删除任务数据库记录,并且删除已经下载完成的文件 {@code + * false} 如果任务已经完成,只删除任务数据库记录 + */ + private boolean removeFile = false; + + /** + * 是否支持断点, {@code true} 为支持断点 + */ + private boolean isSupportBP = true; + + /** + * 状态码 + */ + private int code; + + public abstract String getKey(); + + public abstract void setKey(String key); + + /** + * 设置或获取HTTP任务相关参数 + */ + public HttpTaskDelegate asHttp() { + if (httpTaskDelegate == null) { + httpTaskDelegate = new HttpTaskDelegate(); + } + return httpTaskDelegate; + } + + /** + * 设置或获取FTP任务相关参数 + */ + public FtpTaskDelegate asFtp() { + if (ftpTaskDelegate == null) { + ftpTaskDelegate = new FtpTaskDelegate(); + } + return ftpTaskDelegate; + } + + /** + * 获取任务下载状态 + * + * @return {@link IEntity} + */ + public int getState() { + return getEntity().getState(); + } + + public boolean isRefreshInfo() { + return refreshInfo; + } + + public void setRefreshInfo(boolean refreshInfo) { + this.refreshInfo = refreshInfo; + } + + public boolean isNewTask() { + return isNewTask; + } + + public void setNewTask(boolean newTask) { + isNewTask = newTask; + } + + public void setState(int state) { + this.state = state; + } + + public int getRequestType() { + return requestType; + } + + public void setRequestType(int requestType) { + this.requestType = requestType; + } + + public boolean isRemoveFile() { + return removeFile; + } + + public void setRemoveFile(boolean removeFile) { + this.removeFile = removeFile; + } + + public boolean isSupportBP() { + return isSupportBP; + } + + public void setSupportBP(boolean supportBP) { + isSupportBP = supportBP; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java index 6fece641..e8759e5d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java @@ -18,7 +18,7 @@ package com.arialyy.aria.core.inf; /** * Created by lyy on 2017/2/13. */ -public interface ITask { +public interface ITask { /** * 普通下载任务 @@ -68,7 +68,7 @@ public interface ITask { /** * 获取信息实体 */ - TASK_ENTITY getTaskEntity(); + TASK_WRAPPER getTaskWrapper(); void start(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ITaskDelegate.java similarity index 81% rename from Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTaskEntity.java rename to Aria/src/main/java/com/arialyy/aria/core/inf/ITaskDelegate.java index 8f9e8983..5f357575 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ITaskDelegate.java @@ -16,8 +16,8 @@ package com.arialyy.aria.core.inf; /** - * Created by Aria.Lao on 2017/10/12. - * 当任务实体 + * 任务信息 */ -public abstract class AbsNormalTaskEntity extends AbsTaskEntity { +public interface ITaskDelegate { + } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ITaskWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ITaskWrapper.java new file mode 100644 index 00000000..acfd64d5 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ITaskWrapper.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.inf; + +import com.arialyy.aria.core.download.DownloadGroupEntity; + +/** + * 组合任务实体包裹器,用于加载和任务相关的参数,如:组合任务实体{@link DownloadGroupEntity}、header头部 + */ +public interface ITaskWrapper { + + /** + * HTTP单任务载 + */ + int D_HTTP = 0x11; + /** + * HTTP任务组下载 + */ + int DG_HTTP = 0x12; + + /** + * FTP单文件下载 + */ + int D_FTP = 0x13; + /** + * FTP文件夹下载,为避免登录过多,子任务由单线程进行处理 + */ + int D_FTP_DIR = 0x14; + + /** + * HTTP单文件上传 + */ + int U_HTTP = 0xA1; + /** + * FTP单文件上传 + */ + int U_FTP = 0xA2; + + ENTITY getEntity(); +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/DGTEFactory.java b/Aria/src/main/java/com/arialyy/aria/core/manager/DGTEFactory.java index 73582af9..e19240bd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/DGTEFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/DGTEFactory.java @@ -15,10 +15,10 @@ */ package com.arialyy.aria.core.manager; +import com.arialyy.aria.core.download.DGTaskWrapper; +import com.arialyy.aria.core.download.DTaskWrapper; 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.download.wrapper.DGEWrapper; import com.arialyy.aria.core.download.wrapper.DGTEWrapper; import com.arialyy.aria.orm.DbEntity; @@ -31,7 +31,7 @@ import java.util.List; * Created by Aria.Lao on 2017/11/1. * 任务实体工厂 */ -class DGTEFactory implements IGTEFactory { +class DGTEFactory implements IGTEFactory { private static final String TAG = "DTEFactory"; private static volatile DGTEFactory INSTANCE = null; @@ -47,39 +47,39 @@ class DGTEFactory implements IGTEFactory urls) { + @Override public DGTaskWrapper getGTE(String groupName, List urls) { DownloadGroupEntity entity = createDGroupEntity(groupName, urls); List wrapper = - DbEntity.findRelationData(DGTEWrapper.class, "DownloadGroupTaskEntity.key=?", + DbEntity.findRelationData(DGTEWrapper.class, "DGTaskWrapper.key=?", entity.getGroupName()); - DownloadGroupTaskEntity gte; + DGTaskWrapper gte; if (wrapper != null && !wrapper.isEmpty()) { gte = wrapper.get(0).taskEntity; if (gte == null) { // 创建新的任务组任务实体 - gte = new DownloadGroupTaskEntity(); + gte = new DGTaskWrapper(); } } else { - gte = new DownloadGroupTaskEntity(); + gte = new DGTaskWrapper(); } - gte.setSubTaskEntities(createDGSubTaskEntity(entity)); + gte.setSubTaskWrapper(createDGSubTaskEntity(entity)); gte.setKey(entity.getGroupName()); gte.setEntity(entity); return gte; } - @Override public DownloadGroupTaskEntity getFTE(String ftpUrl) { + @Override public DGTaskWrapper getFTE(String ftpUrl) { List wrapper = - DbEntity.findRelationData(DGTEWrapper.class, "DownloadGroupTaskEntity.key=?", + DbEntity.findRelationData(DGTEWrapper.class, "DGTaskWrapper.key=?", ftpUrl); - DownloadGroupTaskEntity fte; + DGTaskWrapper fte; if (wrapper != null && !wrapper.isEmpty()) { fte = wrapper.get(0).taskEntity; if (fte == null) { - fte = new DownloadGroupTaskEntity(); + fte = new DGTaskWrapper(); DownloadGroupEntity dge = new DownloadGroupEntity(); dge.setGroupName(ftpUrl); fte.setEntity(dge); @@ -89,19 +89,19 @@ class DGTEFactory implements IGTEFactory()); } - if (fte.getSubTaskEntities() == null) { - fte.setSubTaskEntities(new ArrayList()); + if (fte.getSubTaskWrapper() == null) { + fte.setSubTaskWrapper(new ArrayList()); } return fte; } @@ -109,10 +109,10 @@ class DGTEFactory implements IGTEFactory createDGSubTaskEntity(DownloadGroupEntity dge) { - List list = new ArrayList<>(); + private List createDGSubTaskEntity(DownloadGroupEntity dge) { + List list = new ArrayList<>(); for (DownloadEntity entity : dge.getSubEntities()) { - DownloadTaskEntity taskEntity = new DownloadTaskEntity(); + DTaskWrapper taskEntity = new DTaskWrapper(); taskEntity.setEntity(entity); taskEntity.setKey(entity.getDownloadPath()); taskEntity.setGroupName(dge.getKey()); diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/DTEFactory.java b/Aria/src/main/java/com/arialyy/aria/core/manager/DTEFactory.java index bbc78383..da428909 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/DTEFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/DTEFactory.java @@ -18,8 +18,8 @@ package com.arialyy.aria.core.manager; import android.text.TextUtils; import com.arialyy.aria.core.common.AbsFileer; import com.arialyy.aria.core.common.TaskRecord; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.wrapper.DTEWrapper; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.orm.DbEntity; @@ -31,7 +31,7 @@ import java.util.UUID; * Created by Aria.Lao on 2017/11/1. * 任务实体工厂 */ -class DTEFactory implements INormalTEFactory { +class DTEFactory implements INormalTEFactory { private static final String TAG = "DTEFactory"; private static volatile DTEFactory INSTANCE = null; @@ -50,21 +50,21 @@ class DTEFactory implements INormalTEFactory /** * 通过下载实体创建任务实体 */ - private DownloadTaskEntity create(DownloadEntity entity) { + private DTaskWrapper create(DownloadEntity entity) { List wrapper = DbEntity.findRelationData(DTEWrapper.class, - "DownloadTaskEntity.key=? and DownloadTaskEntity.isGroupTask='false' and DownloadTaskEntity.url=?", + "DTaskWrapper.key=? and DTaskWrapper.isGroupTask='false' and DTaskWrapper.url=?", entity.getDownloadPath(), entity.getUrl()); - DownloadTaskEntity taskEntity; + DTaskWrapper taskEntity; if (wrapper != null && !wrapper.isEmpty()) { taskEntity = wrapper.get(0).taskEntity; if (taskEntity == null) { - taskEntity = new DownloadTaskEntity(); + taskEntity = new DTaskWrapper(); } else if (taskEntity.getEntity() == null || TextUtils.isEmpty( taskEntity.getEntity().getUrl())) { taskEntity.setEntity(entity); } } else { - taskEntity = new DownloadTaskEntity(); + taskEntity = new DTaskWrapper(); } taskEntity.setKey(entity.getDownloadPath()); taskEntity.setUrl(entity.getUrl()); @@ -75,7 +75,7 @@ class DTEFactory implements INormalTEFactory /** * 通过下载地址创建任务实体 */ - @Override public DownloadTaskEntity create(String downloadUrl) { + @Override public DTaskWrapper create(String downloadUrl) { return create(getEntity(downloadUrl)); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/IGTEFactory.java b/Aria/src/main/java/com/arialyy/aria/core/manager/IGTEFactory.java index 3b76ac7a..63333075 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/IGTEFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/IGTEFactory.java @@ -16,14 +16,14 @@ package com.arialyy.aria.core.manager; import com.arialyy.aria.core.inf.AbsEntity; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import java.util.List; /** * 任务组通过组创建任务 * Created by Aria.Lao on 2017/11/1. */ -interface IGTEFactory> { +interface IGTEFactory> { /** * 获取任务组的任务实体, diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/INormalTEFactory.java b/Aria/src/main/java/com/arialyy/aria/core/manager/INormalTEFactory.java index b55ddcf7..f9cd6642 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/INormalTEFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/INormalTEFactory.java @@ -16,12 +16,12 @@ package com.arialyy.aria.core.manager; import com.arialyy.aria.core.inf.AbsEntity; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; /** * Created by Aria.Lao on 2017/11/1. */ -interface INormalTEFactory> { +interface INormalTEFactory> { /** * 通过key创建任务,只适应于单任务 diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/SubTaskManager.java b/Aria/src/main/java/com/arialyy/aria/core/manager/SubTaskManager.java index 9c4c826d..867d0bf7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/SubTaskManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/SubTaskManager.java @@ -18,7 +18,7 @@ package com.arialyy.aria.core.manager; import android.text.TextUtils; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.command.group.GroupCmdFactory; -import com.arialyy.aria.core.inf.AbsGroupTaskEntity; +import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.util.List; @@ -29,10 +29,10 @@ import java.util.List; */ public class SubTaskManager { private String TAG = "SubTaskManager"; - private AbsGroupTaskEntity mEntity; + private DGTaskWrapper mEntity; private String mTargetName; - public SubTaskManager(String targetName, AbsGroupTaskEntity entity) { + public SubTaskManager(String targetName, DGTaskWrapper entity) { mTargetName = targetName; mEntity = entity; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java b/Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java index 49ec3094..72e049f9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/TEManager.java @@ -16,10 +16,10 @@ package com.arialyy.aria.core.manager; import android.support.v4.util.LruCache; -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.upload.UploadTaskEntity; +import com.arialyy.aria.core.download.DGTaskWrapper; +import com.arialyy.aria.core.download.DTaskWrapper; +import com.arialyy.aria.core.inf.AbsTaskWrapper; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.util.List; @@ -33,7 +33,7 @@ import java.util.concurrent.locks.ReentrantLock; public class TEManager { private static final String TAG = "TaskManager"; private static volatile TEManager INSTANCE = null; - private LruCache cache = new LruCache<>(1024); + private LruCache cache = new LruCache<>(1024); private Lock lock; public static TEManager getInstance() { @@ -54,11 +54,11 @@ public class TEManager { * * @return 如果任务实体创建失败,返回null */ - private TE createNormalTE(Class clazz, String key) { + private TE createNormalTE(Class clazz, String key) { final Lock lock = this.lock; lock.lock(); try { - AbsTaskEntity tEntity = cache.get(convertKey(key)); + AbsTaskWrapper tEntity = cache.get(convertKey(key)); if (tEntity == null || tEntity.getClass() != clazz) { INormalTEFactory factory = chooseNormalFactory(clazz); if (factory == null) { @@ -79,7 +79,7 @@ public class TEManager { * * @return 如果任务实体创建失败,返回null */ - public TE createNormalNoCacheTE(Class clazz, String key) { + public TE createNormalNoCacheTE(Class clazz, String key) { final Lock lock = this.lock; lock.lock(); try { @@ -88,7 +88,7 @@ public class TEManager { ALog.e(TAG, "任务实体创建失败"); return null; } - AbsTaskEntity tEntity = factory.create(key); + AbsTaskWrapper tEntity = factory.create(key); return (TE) tEntity; } finally { lock.unlock(); @@ -100,12 +100,12 @@ public class TEManager { * * @return 如果任务实体创建失败,返回null */ - private TE createGTEntity(Class clazz, List urls) { + private TE createGTEntity(Class clazz, List urls) { final Lock lock = this.lock; lock.lock(); try { String groupName = CommonUtil.getMd5Code(urls); - AbsTaskEntity tEntity = cache.get(convertKey(groupName)); + AbsTaskWrapper tEntity = cache.get(convertKey(groupName)); if (tEntity == null || tEntity.getClass() != clazz) { IGTEFactory factory = chooseGroupFactory(clazz); if (factory == null) { @@ -126,11 +126,11 @@ public class TEManager { * * @return 如果任务实体创建失败,返回null */ - private TE createFDTE(Class clazz, String key) { + private TE createFDTE(Class clazz, String key) { final Lock lock = this.lock; lock.lock(); try { - AbsTaskEntity tEntity = cache.get(convertKey(key)); + AbsTaskWrapper tEntity = cache.get(convertKey(key)); if (tEntity == null || tEntity.getClass() != clazz) { IGTEFactory factory = chooseGroupFactory(clazz); if (factory == null) { @@ -147,16 +147,16 @@ public class TEManager { } private IGTEFactory chooseGroupFactory(Class clazz) { - if (clazz == DownloadGroupTaskEntity.class) { + if (clazz == DGTaskWrapper.class) { return DGTEFactory.getInstance(); } return null; } private INormalTEFactory chooseNormalFactory(Class clazz) { - if (clazz == DownloadTaskEntity.class) { + if (clazz == DTaskWrapper.class) { return DTEFactory.getInstance(); - } else if (clazz == UploadTaskEntity.class) { + } else if (clazz == UTaskWrapper.class) { return UTEFactory.getInstance(); } return null; @@ -165,13 +165,13 @@ public class TEManager { /** * 从缓存中获取单任务实体,如果任务实体不存在,则创建任务实体 * - * @return 创建失败,返回null;成功返回{@link DownloadTaskEntity}或者{@link UploadTaskEntity} + * @return 创建失败,返回null;成功返回{@link DTaskWrapper}或者{@link UTaskWrapper} */ - public TE getTEntity(Class clazz, String key) { + public TE getTEntity(Class clazz, String key) { final Lock lock = this.lock; lock.lock(); try { - AbsTaskEntity tEntity = cache.get(convertKey(key)); + AbsTaskWrapper tEntity = cache.get(convertKey(key)); if (tEntity == null) { return createNormalTE(clazz, key); } else { @@ -185,13 +185,13 @@ public class TEManager { /** * 从缓存中获取FTP文件夹任务实体,如果任务实体不存在,则创建任务实体 * - * @return 创建失败,返回null;成功返回{@link DownloadTaskEntity}, + * @return 创建失败,返回null;成功返回{@link DTaskWrapper}, */ - public TE getFDTEntity(Class clazz, String key) { + public TE getFDTEntity(Class clazz, String key) { final Lock lock = this.lock; lock.lock(); try { - AbsTaskEntity tEntity = cache.get(convertKey(key)); + AbsTaskWrapper tEntity = cache.get(convertKey(key)); if (tEntity == null) { return createFDTE(clazz, key); } else { @@ -207,9 +207,9 @@ public class TEManager { * 获取{} * * @param urls HTTP任务组的子任务下载地址列表 - * @return 地址列表为null或创建实体失败,返回null;成功返回{@link DownloadGroupTaskEntity} + * @return 地址列表为null或创建实体失败,返回null;成功返回{@link DGTaskWrapper} */ - public TE getGTEntity(Class clazz, List urls) { + public TE getGTEntity(Class clazz, List urls) { if (urls == null || urls.isEmpty()) { ALog.e(TAG, "获取HTTP任务组实体失败:任务组的子任务下载地址列表为null"); return null; @@ -218,7 +218,7 @@ public class TEManager { lock.lock(); try { String groupName = CommonUtil.getMd5Code(urls); - AbsTaskEntity tEntity = cache.get(convertKey(groupName)); + AbsTaskWrapper tEntity = cache.get(convertKey(groupName)); if (tEntity == null) { return createGTEntity(clazz, urls); } else { @@ -232,7 +232,7 @@ public class TEManager { /** * 更新任务实体 */ - public void putTEntity(String key, AbsTaskEntity tEntity) { + public void putTEntity(String key, AbsTaskWrapper tEntity) { final Lock lock = this.lock; lock.lock(); try { @@ -247,7 +247,7 @@ public class TEManager { * * @return {@code false} 实体为null,添加失败 */ - public boolean addTEntity(AbsTaskEntity te) { + public boolean addTEntity(AbsTaskWrapper te) { if (te == null) { ALog.e(TAG, "任务实体添加失败"); return false; @@ -265,7 +265,7 @@ public class TEManager { * 通过key删除任务实体 * 当任务complete或删除记录时将删除缓存 */ - public AbsTaskEntity removeTEntity(String key) { + public AbsTaskWrapper removeTEntity(String key) { final Lock lock = this.lock; lock.lock(); try { diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java b/Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java index 84e21e6a..7287fbf6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java @@ -17,7 +17,7 @@ package com.arialyy.aria.core.manager; import com.arialyy.aria.core.common.AbsThreadTask; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.util.HashMap; @@ -54,7 +54,7 @@ public class ThreadTaskManager { /** * 启动线程任务 * - * @param key 任务对应的key{@link AbsTaskEntity#getKey()} + * @param key 任务对应的key{@link AbsTaskWrapper#getKey()} * @param threadTask 线程任务{@link AbsThreadTask} */ public synchronized void startThread(String key, AbsThreadTask threadTask) { @@ -74,7 +74,7 @@ public class ThreadTaskManager { /** * 停止任务的所有线程 * - * @param key 任务对应的key{@link AbsTaskEntity#getKey()} + * @param key 任务对应的key{@link AbsTaskWrapper#getKey()} */ public synchronized void stopTaskThread(String key) { if (mExePool.isShutdown()) { @@ -126,7 +126,7 @@ public class ThreadTaskManager { /** * map中的key * - * @param key 任务的key{@link AbsTaskEntity#getKey()} + * @param key 任务的key{@link AbsTaskWrapper#getKey()} * @return 转换后的map中的key */ private String getKey(String key) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/UTEFactory.java b/Aria/src/main/java/com/arialyy/aria/core/manager/UTEFactory.java index 207425c8..c56aeda6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/UTEFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/UTEFactory.java @@ -16,8 +16,8 @@ package com.arialyy.aria.core.manager; import android.text.TextUtils; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.core.upload.wrapper.UTEWrapper; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.Regular; @@ -28,7 +28,7 @@ import java.util.regex.Pattern; * Created by Aria.Lao on 2017/11/1. * 任务实体工厂 */ -class UTEFactory implements INormalTEFactory { +class UTEFactory implements INormalTEFactory { private static final String TAG = "DTEFactory"; private static volatile UTEFactory INSTANCE = null; @@ -44,29 +44,29 @@ class UTEFactory implements INormalTEFactory { return INSTANCE; } - private UploadTaskEntity create(UploadEntity entity) { + private UTaskWrapper create(UploadEntity entity) { List wrapper = - DbEntity.findRelationData(UTEWrapper.class, "UploadTaskEntity.key=?", + DbEntity.findRelationData(UTEWrapper.class, "UTaskWrapper.key=?", entity.getFilePath()); - UploadTaskEntity uTaskEntity = null; + UTaskWrapper uTaskEntity = null; if (wrapper != null && !wrapper.isEmpty()) { uTaskEntity = wrapper.get(0).taskEntity; if (uTaskEntity == null) { - uTaskEntity = new UploadTaskEntity(); + uTaskEntity = new UTaskWrapper(); uTaskEntity.setEntity(entity); } else if (uTaskEntity.getEntity() == null || TextUtils.isEmpty( uTaskEntity.getEntity().getFilePath())) { uTaskEntity.setEntity(entity); } } else { - uTaskEntity = new UploadTaskEntity(); + uTaskEntity = new UTaskWrapper(); uTaskEntity.setEntity(entity); } uTaskEntity.setKey(entity.getFilePath()); return uTaskEntity; } - @Override public UploadTaskEntity create(String key) { + @Override public UTaskWrapper create(String key) { return create(getUploadEntity(key)); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java index 509eaf8f..39138b64 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java @@ -17,7 +17,7 @@ package com.arialyy.aria.core.queue; import com.arialyy.aria.core.inf.AbsTask; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.TaskSchedulerType; import com.arialyy.aria.core.queue.pool.BaseCachePool; @@ -31,7 +31,7 @@ import java.util.Set; /** * Created by lyy on 2017/2/23. 任务队列 */ -abstract class AbsTaskQueue +abstract class AbsTaskQueue implements ITaskQueue { final int TYPE_D_QUEUE = 1; final int TYPE_DG_QUEUE = 2; @@ -68,7 +68,7 @@ abstract class AbsTaskQueue= getMaxTaskNum()) { - task.getTaskEntity().getEntity().setState(IEntity.STATE_WAIT); + task.getTaskWrapper().getEntity().setState(IEntity.STATE_WAIT); mCachePool.putTaskToFirst(task); stopTask(mExecutePool.pollTask()); } else { @@ -188,7 +188,7 @@ abstract class AbsTaskQueue { + extends AbsTaskQueue { private static volatile DownloadGroupTaskQueue INSTANCE = null; private final String TAG = "DownloadGroupTaskQueue"; @@ -52,12 +52,12 @@ public class DownloadGroupTaskQueue return AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum(); } - @Override public DownloadGroupTask createTask(DownloadGroupTaskEntity entity) { + @Override public DownloadGroupTask createTask(DGTaskWrapper wrapper) { DownloadGroupTask task = null; - if (mCachePool.getTask(entity.getEntity().getKey()) == null - && mExecutePool.getTask(entity.getEntity().getKey()) == null) { + if (mCachePool.getTask(wrapper.getEntity().getKey()) == null + && mExecutePool.getTask(wrapper.getEntity().getKey()) == null) { task = (DownloadGroupTask) TaskFactory.getInstance() - .createTask(entity, DownloadGroupSchedulers.getInstance()); + .createTask(wrapper, DownloadGroupSchedulers.getInstance()); mCachePool.putTask(task); } else { ALog.w(TAG, "任务已存在"); diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java index 98bc84e0..ba072b34 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java @@ -17,8 +17,8 @@ package com.arialyy.aria.core.queue; import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadTask; -import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.TaskSchedulerType; import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.util.ALog; @@ -30,7 +30,7 @@ import java.util.Set; * Created by lyy on 2016/8/17. * 下载任务队列 */ -public class DownloadTaskQueue extends AbsTaskQueue { +public class DownloadTaskQueue extends AbsTaskQueue { private static final String TAG = "DownloadTaskQueue"; private static volatile DownloadTaskQueue INSTANCE = null; @@ -97,12 +97,12 @@ public class DownloadTaskQueue extends AbsTaskQueue { +public interface ITaskQueue { /** * 通过key判断任务是否正在执行 @@ -112,10 +112,10 @@ public interface ITaskQueue {@link DownloadTaskEntity}、{@link UploadTaskEntity}、{@link - * DownloadGroupTaskEntity} + * @param {@link DTaskWrapper}、{@link UTaskWrapper}、{@link + * DGTaskWrapper} * @param {@link DownloadSchedulers}、{@link UploadSchedulers} * @return {@link DownloadTask}、{@link UploadTask}、{@link DownloadGroupTask} */ - ITask createTask( + ITask createTask( TASK_ENTITY entity, SCHEDULER schedulers) { - if (entity instanceof DownloadTaskEntity) { - return createDownloadTask((DownloadTaskEntity) entity, schedulers); - } else if (entity instanceof UploadTaskEntity) { - return createUploadTask((UploadTaskEntity) entity, schedulers); - } else if (entity instanceof DownloadGroupTaskEntity) { - return createDownloadGroupTask((DownloadGroupTaskEntity) entity, schedulers); + if (entity instanceof DTaskWrapper) { + return createDownloadTask((DTaskWrapper) entity, schedulers); + } else if (entity instanceof UTaskWrapper) { + return createUploadTask((UTaskWrapper) entity, schedulers); + } else if (entity instanceof DGTaskWrapper) { + return createDownloadGroupTask((DGTaskWrapper) entity, schedulers); } return null; } @@ -78,7 +78,7 @@ class TaskFactory { * @param entity 下载任务实体{@link DownloadGroupTask} * @param schedulers {@link ISchedulers} */ - private DownloadGroupTask createDownloadGroupTask(DownloadGroupTaskEntity entity, + private DownloadGroupTask createDownloadGroupTask(DGTaskWrapper entity, ISchedulers schedulers) { DownloadGroupTask.Builder builder = new DownloadGroupTask.Builder(entity); builder.setOutHandler(schedulers); @@ -86,10 +86,10 @@ class TaskFactory { } /** - * @param entity 上传任务实体{@link UploadTaskEntity} + * @param entity 上传任务实体{@link UTaskWrapper} * @param schedulers {@link ISchedulers} */ - private UploadTask createUploadTask(UploadTaskEntity entity, ISchedulers schedulers) { + private UploadTask createUploadTask(UTaskWrapper entity, ISchedulers schedulers) { UploadTask.Builder builder = new UploadTask.Builder(); builder.setUploadTaskEntity(entity); builder.setOutHandler(schedulers); @@ -97,10 +97,10 @@ class TaskFactory { } /** - * @param entity 下载任务实体{@link DownloadTaskEntity} + * @param entity 下载任务实体{@link DTaskWrapper} * @param schedulers {@link ISchedulers} */ - private DownloadTask createDownloadTask(DownloadTaskEntity entity, ISchedulers schedulers) { + private DownloadTask createDownloadTask(DTaskWrapper entity, ISchedulers schedulers) { DownloadTask.Builder builder = new DownloadTask.Builder(entity); builder.setOutHandler(schedulers); return builder.build(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java index d6190dc4..7f3c60e9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java @@ -18,15 +18,15 @@ package com.arialyy.aria.core.queue; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.scheduler.UploadSchedulers; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UploadTask; -import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.util.ALog; /** * Created by lyy on 2017/2/27. * 上传任务队列 */ -public class UploadTaskQueue extends AbsTaskQueue { +public class UploadTaskQueue extends AbsTaskQueue { private static final String TAG = "UploadTaskQueue"; private static volatile UploadTaskQueue INSTANCE = null; @@ -54,12 +54,12 @@ public class UploadTaskQueue extends AbsTaskQueue return AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum(); } - @Override public UploadTask createTask(UploadTaskEntity entity) { + @Override public UploadTask createTask(UTaskWrapper wrapper) { UploadTask task = null; - if (mCachePool.getTask(entity.getEntity().getKey()) == null - && mExecutePool.getTask(entity.getEntity().getKey()) == null) { + if (mCachePool.getTask(wrapper.getEntity().getKey()) == null + && mExecutePool.getTask(wrapper.getEntity().getKey()) == null) { task = (UploadTask) TaskFactory.getInstance() - .createTask(entity, UploadSchedulers.getInstance()); + .createTask(wrapper, UploadSchedulers.getInstance()); mCachePool.putTask(task); } else { ALog.w(TAG, "任务已存在"); diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java index 188d8f09..e425f5dd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java @@ -25,7 +25,7 @@ import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsNormalEntity; import com.arialyy.aria.core.inf.AbsTask; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.GroupSendParams; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.ITask; @@ -43,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap; /** * Created by lyy on 2017/6/4. 事件调度器,用于处理任务状态的调度 */ -abstract class AbsSchedulers> implements ISchedulers { private final String TAG = "AbsSchedulers"; @@ -202,7 +202,7 @@ abstract class AbsSchedulers reTryNum) { + || task.getTaskWrapper().getEntity().getFailNum() > reTryNum) { mQueue.removeTaskFormQueue(task.getKey()); startNextTask(task); TEManager.getInstance().removeTEntity(task.getKey()); @@ -351,7 +351,7 @@ abstract class AbsSchedulers { + AbsSchedulers { private final String TAG = "DownloadGroupSchedulers"; private static volatile DownloadGroupSchedulers INSTANCE = null; diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java index f051d864..b845ebe6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java @@ -17,9 +17,8 @@ package com.arialyy.aria.core.scheduler; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.queue.DownloadTaskQueue; -import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTask; /** @@ -27,7 +26,7 @@ import com.arialyy.aria.core.download.DownloadTask; * 任务下载器,提供抽象的方法供具体的实现类操作 */ public class DownloadSchedulers - extends AbsSchedulers { + extends AbsSchedulers { private final String TAG = "DownloadSchedulers"; private static volatile DownloadSchedulers INSTANCE = null; diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java index 1c48133b..4d259424 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java @@ -17,14 +17,14 @@ package com.arialyy.aria.core.scheduler; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.queue.UploadTaskQueue; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UploadTask; -import com.arialyy.aria.core.upload.UploadTaskEntity; /** * Created by lyy on 2017/2/27. * 上传任务调度器 */ -public class UploadSchedulers extends AbsSchedulers { +public class UploadSchedulers extends AbsSchedulers { private static final String TAG = "UploadSchedulers"; private static volatile UploadSchedulers INSTANCE = null; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/AbsUploadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/AbsUploadTarget.java index c4fd733a..a5f39961 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/AbsUploadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/AbsUploadTarget.java @@ -17,12 +17,12 @@ package com.arialyy.aria.core.upload; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsTarget; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; /** * Created by AriaL on 2017/6/29. */ -abstract class AbsUploadTarget +abstract class AbsUploadTarget extends AbsTarget { } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/BaseNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/BaseNormalTarget.java index 45ba22a7..a7f55d66 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/BaseNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/BaseNormalTarget.java @@ -27,13 +27,13 @@ import java.io.File; * Created by AriaL on 2018/3/9. */ abstract class BaseNormalTarget - extends AbsUploadTarget { + extends AbsUploadTarget { protected String mTempUrl; void initTarget(String filePath) { - mTaskEntity = TEManager.getInstance().getTEntity(UploadTaskEntity.class, filePath); - mEntity = mTaskEntity.getEntity(); + mTaskWrapper = TEManager.getInstance().getTEntity(UTaskWrapper.class, filePath); + mEntity = mTaskWrapper.getEntity(); File file = new File(filePath); mEntity.setFileName(file.getName()); mEntity.setFileSize(file.length()); @@ -78,14 +78,13 @@ abstract class BaseNormalTarget boolean b = checkUrl() && checkFilePath(); if (b) { mEntity.save(); - mTaskEntity.save(); } - if (mTaskEntity.getUrlEntity() != null && mTaskEntity.getUrlEntity().isFtps) { - //if (TextUtils.isEmpty(mTaskEntity.getUrlEntity().storePath)) { + if (mTaskWrapper.asFtp().getUrlEntity() != null && mTaskWrapper.asFtp().getUrlEntity().isFtps) { + //if (TextUtils.isEmpty(mTaskWrapper.getUrlEntity().storePath)) { // ALog.e(TAG, "证书路径为空"); // return false; //} - if (TextUtils.isEmpty(mTaskEntity.getUrlEntity().keyAlias)) { + if (TextUtils.isEmpty(mTaskWrapper.asFtp().getUrlEntity().keyAlias)) { ALog.e(TAG, "证书别名为空"); return false; } @@ -117,7 +116,7 @@ abstract class BaseNormalTarget ALog.e(TAG, "上传失败,文件【" + filePath + "】不能是文件夹"); return false; } - mTaskEntity.setKey(mEntity.getFilePath()); + mTaskWrapper.setKey(mEntity.getFilePath()); return true; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java b/Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java index 8019ebe7..6252c66b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/BaseUListener.java @@ -17,16 +17,14 @@ package com.arialyy.aria.core.upload; import android.os.Handler; import com.arialyy.aria.core.common.BaseListener; -import com.arialyy.aria.core.common.TaskRecord; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IUploadListener; -import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.CommonUtil; /** * 下载监听类 */ -class BaseUListener extends BaseListener +class BaseUListener extends BaseListener implements IUploadListener { BaseUListener(UploadTask task, Handler outHandler) { @@ -51,6 +49,5 @@ class BaseUListener extends BaseListener 0) { mEntity.setCurrentProgress(location); } - mTaskEntity.update(); } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java index 99f4978b..3535d46c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/FtpUploadTarget.java @@ -21,7 +21,8 @@ import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.common.ftp.FTPSConfig; import com.arialyy.aria.core.common.ftp.FtpDelegate; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.common.ftp.FtpTaskDelegate; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IFtpTarget; import com.arialyy.aria.util.CommonUtil; import java.net.Proxy; @@ -44,7 +45,7 @@ public class FtpUploadTarget extends BaseNormalTarget private void initTask(String filePath) { initTarget(filePath); - mTaskEntity.setRequestType(AbsTaskEntity.U_FTP); + mTaskWrapper.setRequestType(AbsTaskWrapper.U_FTP); mDelegate = new FtpDelegate<>(this); } @@ -54,7 +55,7 @@ public class FtpUploadTarget extends BaseNormalTarget public void add() { if (checkEntity()) { AriaManager.getInstance(AriaManager.APP) - .setCmd(CommonUtil.createNormalCmd(mTaskEntity, NormalCmdFactory.TASK_CREATE, + .setCmd(CommonUtil.createNormalCmd(mTaskWrapper, NormalCmdFactory.TASK_CREATE, checkTaskType())) .exe(); } @@ -65,7 +66,8 @@ public class FtpUploadTarget extends BaseNormalTarget if (!b) { return false; } - FtpUrlEntity temp = mTaskEntity.getUrlEntity(); + FtpTaskDelegate taskDelegate = mTaskWrapper.asFtp(); + FtpUrlEntity temp = taskDelegate.getUrlEntity(); FtpUrlEntity newEntity = CommonUtil.getFtpUrlInfo(mTempUrl); if (temp != null) { //处理FTPS的信息 newEntity.isFtps = temp.isFtps; @@ -74,11 +76,11 @@ public class FtpUploadTarget extends BaseNormalTarget newEntity.protocol = temp.protocol; newEntity.storePath = temp.storePath; } - mTaskEntity.setUrlEntity(newEntity); - mTaskEntity.getUrlEntity().account = mAccount; - mTaskEntity.getUrlEntity().user = mUser; - mTaskEntity.getUrlEntity().password = mPw; - mTaskEntity.getUrlEntity().needLogin = needLogin; + taskDelegate.setUrlEntity(newEntity); + taskDelegate.getUrlEntity().account = mAccount; + taskDelegate.getUrlEntity().user = mUser; + taskDelegate.getUrlEntity().password = mPw; + taskDelegate.getUrlEntity().needLogin = needLogin; return true; } @@ -89,10 +91,10 @@ public class FtpUploadTarget extends BaseNormalTarget */ @CheckResult public FTPSConfig asFtps() { - if (mTaskEntity.getUrlEntity() == null) { + if (mTaskWrapper.asFtp().getUrlEntity() == null) { FtpUrlEntity urlEntity = new FtpUrlEntity(); urlEntity.isFtps = true; - mTaskEntity.setUrlEntity(urlEntity); + mTaskWrapper.asFtp().setUrlEntity(urlEntity); } return new FTPSConfig<>(this); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java new file mode 100644 index 00000000..207b3065 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UTaskWrapper.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.upload; + +import com.arialyy.aria.core.inf.AbsTaskWrapper; + +/** + * Created by lyy on 2017/2/9. 上传任务实体 + */ +public class UTaskWrapper extends AbsTaskWrapper { + + private UploadEntity entity; + + private String filePath; + + private String key; + + public UTaskWrapper() { + } + + @Override public UploadEntity getEntity() { + return entity; + } + + @Override public String getKey() { + return key; + } + + public void setEntity(UploadEntity entity) { + this.entity = entity; + } + + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public void setKey(String key) { + this.key = key; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java index bf80d9ff..476773f4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java @@ -18,7 +18,7 @@ package com.arialyy.aria.core.upload; import android.os.Parcel; import android.os.Parcelable; import com.arialyy.aria.core.inf.AbsNormalEntity; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.orm.annotation.Primary; /** @@ -57,7 +57,7 @@ public class UploadEntity extends AbsNormalEntity implements Parcelable { } @Override public int getTaskType() { - return getUrl().startsWith("ftp") ? AbsTaskEntity.D_FTP : AbsTaskEntity.D_HTTP; + return getUrl().startsWith("ftp") ? AbsTaskWrapper.D_FTP : AbsTaskWrapper.D_HTTP; } public UploadEntity() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java index 63c3de42..15248434 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java @@ -89,7 +89,7 @@ public class UploadReceiver extends AbsReceiver { * @return {@code true}存在,{@code false} 不存在 */ public boolean taskExists(String filePath) { - return DbEntity.checkDataExist(UploadTaskEntity.class, "key=?", filePath); + return DbEntity.checkDataExist(UTaskWrapper.class, "key=?", filePath); } /** @@ -123,7 +123,7 @@ public class UploadReceiver extends AbsReceiver { public void stopAllTask() { AriaManager.getInstance(AriaManager.APP) .setCmd(NormalCmdFactory.getInstance() - .createCmd(new UploadTaskEntity(), NormalCmdFactory.TASK_STOP_ALL, + .createCmd(new UTaskWrapper(), NormalCmdFactory.TASK_STOP_ALL, ICmd.TASK_TYPE_UPLOAD)) .exe(); } @@ -137,7 +137,7 @@ public class UploadReceiver extends AbsReceiver { public void removeAllTask(boolean removeFile) { final AriaManager am = AriaManager.getInstance(AriaManager.APP); CancelAllCmd cancelCmd = - (CancelAllCmd) CommonUtil.createNormalCmd(new UploadTaskEntity(), + (CancelAllCmd) CommonUtil.createNormalCmd(new UTaskWrapper(), NormalCmdFactory.TASK_CANCEL_ALL, ICmd.TASK_TYPE_UPLOAD); cancelCmd.removeFile = removeFile; am.setCmd(cancelCmd).exe(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java index fdd91f7d..01c5f57d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java @@ -19,7 +19,7 @@ import android.support.annotation.CheckResult; import android.support.annotation.NonNull; import com.arialyy.aria.core.common.http.HttpHeaderDelegate; import com.arialyy.aria.core.common.http.PostDelegate; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IHttpHeaderDelegate; import java.net.Proxy; import java.util.Map; @@ -41,8 +41,8 @@ public class UploadTarget extends BaseNormalTarget initTarget(filePath); //http暂时不支持断点上传 - mTaskEntity.setSupportBP(false); - mTaskEntity.setRequestType(AbsTaskEntity.U_HTTP); + mTaskWrapper.setSupportBP(false); + mTaskWrapper.setRequestType(AbsTaskWrapper.U_HTTP); mDelegate = new HttpHeaderDelegate<>(this); } @@ -58,7 +58,7 @@ public class UploadTarget extends BaseNormalTarget */ @CheckResult public UploadTarget setUserAngent(@NonNull String userAgent) { - mTaskEntity.setUserAgent(userAgent); + mTaskWrapper.asHttp().setUserAgent(userAgent); return this; } @@ -69,7 +69,7 @@ public class UploadTarget extends BaseNormalTarget */ @CheckResult public UploadTarget setAttachment(@NonNull String attachment) { - mTaskEntity.setAttachment(attachment); + mTaskWrapper.asHttp().setAttachment(attachment); return this; } @@ -80,7 +80,7 @@ public class UploadTarget extends BaseNormalTarget */ @CheckResult public UploadTarget setContentType(String contentType) { - mTaskEntity.setContentType(contentType); + mTaskWrapper.asHttp().setContentType(contentType); return this; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java index 406e101f..c967d2ce 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java @@ -21,8 +21,8 @@ import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.common.TaskRecord; import com.arialyy.aria.core.common.ThreadRecord; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.DbHelper; import java.util.ArrayList; @@ -31,17 +31,17 @@ import java.util.ArrayList; * Created by Aria.Lao on 2017/9/26. * 单任务上传远程服务器文件信息 */ -class FtpFileInfoThread extends AbsFtpInfoThread { +class FtpFileInfoThread extends AbsFtpInfoThread { private static final String TAG = "FtpUploadFileInfoThread"; static final int CODE_COMPLETE = 0xab1; private boolean isComplete = false; - FtpFileInfoThread(UploadTaskEntity taskEntity, OnFileInfoCallback callback) { + FtpFileInfoThread(UTaskWrapper taskEntity, OnFileInfoCallback callback) { super(taskEntity, callback); } @Override protected String setRemotePath() { - return mTaskEntity.getUrlEntity().remotePath + "/" + mEntity.getFileName(); + return mTaskWrapper.asFtp().getUrlEntity().remotePath + "/" + mEntity.getFileName(); } /** @@ -68,14 +68,14 @@ class FtpFileInfoThread extends AbsFtpInfoThread + "尝试从位置:" + (ftpFile.getSize() - 1) + "开始上传"); - mTaskEntity.setNewTask(false); + mTaskWrapper.setNewTask(false); // 修改记录 - TaskRecord record = DbHelper.getTaskRecord(mTaskEntity.getKey()); + TaskRecord record = DbHelper.getTaskRecord(mTaskWrapper.getKey()); if (record == null) { record = new TaskRecord(); record.fileName = mEntity.getFileName(); - record.filePath = mTaskEntity.getKey(); + record.filePath = mTaskWrapper.getKey(); record.threadRecords = new ArrayList<>(); } ThreadRecord threadRecord; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java index d49abf88..60764c5a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java @@ -23,7 +23,7 @@ import com.arialyy.aria.core.common.SubThreadConfig; import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask; import com.arialyy.aria.core.inf.IEventListener; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.exception.AriaIOException; import com.arialyy.aria.exception.TaskException; import com.arialyy.aria.util.ALog; @@ -34,12 +34,12 @@ import java.io.UnsupportedEncodingException; /** * Created by Aria.Lao on 2017/7/28. FTP 单线程上传任务,需要FTP 服务器给用户打开append和write的权限 */ -class FtpThreadTask extends AbsFtpThreadTask { +class FtpThreadTask extends AbsFtpThreadTask { private final String TAG = "FtpThreadTask"; private String dir, remotePath; FtpThreadTask(StateConstance constance, IEventListener listener, - SubThreadConfig info) { + SubThreadConfig info) { super(constance, listener, info); mConnectTimeOut = mAridManager.getUploadConfig().getConnectTimeOut(); mReadTimeOut = mAridManager.getUploadConfig().getIOTimeOut(); @@ -123,9 +123,13 @@ class FtpThreadTask extends AbsFtpThreadTask { } private void initPath() throws UnsupportedEncodingException { - dir = new String(mTaskEntity.getUrlEntity().remotePath.getBytes(charSet), SERVER_CHARSET); + dir = new String(mTaskWrapper.asFtp().getUrlEntity().remotePath.getBytes(charSet), + SERVER_CHARSET); remotePath = new String( - ("/" + mTaskEntity.getUrlEntity().remotePath + "/" + mEntity.getFileName()).getBytes( + ("/" + + mTaskWrapper.asFtp().getUrlEntity().remotePath + + "/" + + mEntity.getFileName()).getBytes( charSet), SERVER_CHARSET); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java index c5ce84fc..33cffe21 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java @@ -18,9 +18,10 @@ package com.arialyy.aria.core.upload.uploader; import com.arialyy.aria.core.common.AbsThreadTask; import com.arialyy.aria.core.common.StateConstance; import com.arialyy.aria.core.common.SubThreadConfig; +import com.arialyy.aria.core.common.http.HttpTaskDelegate; import com.arialyy.aria.core.inf.IUploadListener; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.TaskException; import com.arialyy.aria.util.ALog; @@ -42,7 +43,7 @@ import java.util.UUID; * Created by Aria.Lao on 2017/7/28. * 不支持断点的HTTP上传任务 */ -class HttpThreadTask extends AbsThreadTask { +class HttpThreadTask extends AbsThreadTask { private final String TAG = "HttpThreadTask"; private final String BOUNDARY = UUID.randomUUID().toString(); // 边界标识 随机生成 @@ -51,7 +52,7 @@ class HttpThreadTask extends AbsThreadTask { private OutputStream mOutputStream; HttpThreadTask(StateConstance constance, IUploadListener listener, - SubThreadConfig uploadInfo) { + SubThreadConfig uploadInfo) { super(constance, listener, uploadInfo); mConnectTimeOut = mAridManager.getUploadConfig().getConnectTimeOut(); mReadTimeOut = mAridManager.getUploadConfig().getIOTimeOut(); @@ -72,15 +73,16 @@ class HttpThreadTask extends AbsThreadTask { URL url; try { url = new URL(mEntity.getUrl()); + HttpTaskDelegate taskDelegate = mTaskWrapper.asHttp(); mHttpConn = (HttpURLConnection) url.openConnection(); - mHttpConn.setRequestMethod(mTaskEntity.getRequestEnum().name); + mHttpConn.setRequestMethod(taskDelegate.getRequestEnum().name); mHttpConn.setUseCaches(false); mHttpConn.setDoOutput(true); mHttpConn.setDoInput(true); mHttpConn.setRequestProperty("Connection", "Keep-Alive"); mHttpConn.setRequestProperty("Content-Type", - mTaskEntity.getContentType() + "; boundary=" + BOUNDARY); - mHttpConn.setRequestProperty("User-Agent", mTaskEntity.getUserAgent()); + taskDelegate.getContentType() + "; boundary=" + BOUNDARY); + mHttpConn.setRequestProperty("User-Agent", taskDelegate.getUserAgent()); mHttpConn.setConnectTimeout(mConnectTimeOut); mHttpConn.setReadTimeout(mReadTimeOut); //mHttpConn.setRequestProperty("Range", "bytes=" + 0 + "-" + "100"); @@ -88,20 +90,20 @@ class HttpThreadTask extends AbsThreadTask { mHttpConn.setChunkedStreamingMode(mBufSize); //添加Http请求头部 - Set keys = mTaskEntity.getHeaders().keySet(); + Set keys = taskDelegate.getHeaders().keySet(); for (String key : keys) { - mHttpConn.setRequestProperty(key, mTaskEntity.getHeaders().get(key)); + mHttpConn.setRequestProperty(key, taskDelegate.getHeaders().get(key)); } mOutputStream = mHttpConn.getOutputStream(); PrintWriter writer = - new PrintWriter(new OutputStreamWriter(mOutputStream, mTaskEntity.getCharSet()), true); + new PrintWriter(new OutputStreamWriter(mOutputStream, taskDelegate.getCharSet()), true); //添加文件上传表单字段 - keys = mTaskEntity.getFormFields().keySet(); + keys = taskDelegate.getFormFields().keySet(); for (String key : keys) { - addFormField(writer, key, mTaskEntity.getFormFields().get(key)); + addFormField(writer, key, taskDelegate.getFormFields().get(key)); } - uploadFile(writer, mTaskEntity.getAttachment(), uploadFile); - mTaskEntity.getEntity().setResponseStr(finish(writer)); + uploadFile(writer, taskDelegate.getAttachment(), uploadFile); + mTaskWrapper.getEntity().setResponseStr(finish(writer)); mListener.onComplete(); } catch (Exception e) { e.printStackTrace(); @@ -133,7 +135,7 @@ class HttpThreadTask extends AbsThreadTask { .append("\"") .append(LINE_END); writer.append("Content-Type: text/plain; charset=") - .append(mTaskEntity.getCharSet()) + .append(mTaskWrapper.asHttp().getCharSet()) .append(LINE_END); writer.append(LINE_END); writer.append(value).append(LINE_END); @@ -152,11 +154,11 @@ class HttpThreadTask extends AbsThreadTask { writer.append("Content-Disposition: form-data; name=\"") .append(attachment) .append("\"; filename=\"") - .append(mTaskEntity.getEntity().getFileName()) + .append(mTaskWrapper.getEntity().getFileName()) .append("\"") .append(LINE_END); writer.append("Content-Type: ") - .append(URLConnection.guessContentTypeFromName(mTaskEntity.getEntity().getFileName())) + .append(URLConnection.guessContentTypeFromName(mTaskWrapper.getEntity().getFileName())) .append(LINE_END); writer.append("Content-Transfer-Encoding: binary").append(LINE_END); writer.append(LINE_END); diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/SimpleUploadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/SimpleUploadUtil.java index 774fe935..810de951 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/SimpleUploadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/SimpleUploadUtil.java @@ -18,12 +18,11 @@ package com.arialyy.aria.core.upload.uploader; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.IUtil; import com.arialyy.aria.core.common.OnFileInfoCallback; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IUploadListener; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.exception.BaseException; -import com.arialyy.aria.exception.TaskException; import com.arialyy.aria.util.CheckUtil; /** @@ -34,11 +33,11 @@ public class SimpleUploadUtil implements IUtil, Runnable { private static final String TAG = "SimpleUploadUtil"; private UploadEntity mUploadEntity; - private UploadTaskEntity mTaskEntity; + private UTaskWrapper mTaskEntity; private IUploadListener mListener; private Uploader mUploader; - public SimpleUploadUtil(UploadTaskEntity taskEntity, IUploadListener listener) { + public SimpleUploadUtil(UTaskWrapper taskEntity, IUploadListener listener) { mTaskEntity = taskEntity; CheckUtil.checkTaskEntity(taskEntity); mUploadEntity = taskEntity.getEntity(); @@ -52,7 +51,7 @@ public class SimpleUploadUtil implements IUtil, Runnable { @Override public void run() { mListener.onPre(); switch (mTaskEntity.getRequestType()) { - case AbsTaskEntity.U_FTP: + case AbsTaskWrapper.U_FTP: new FtpFileInfoThread(mTaskEntity, new OnFileInfoCallback() { @Override public void onComplete(String url, CompleteInfo info) { if (info.code == FtpFileInfoThread.CODE_COMPLETE) { @@ -67,7 +66,7 @@ public class SimpleUploadUtil implements IUtil, Runnable { } }).start(); break; - case AbsTaskEntity.U_HTTP: + case AbsTaskWrapper.U_HTTP: mUploader.start(); break; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java index 64859186..eade3ffa 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java @@ -19,20 +19,19 @@ import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.AbsFileer; import com.arialyy.aria.core.common.AbsThreadTask; import com.arialyy.aria.core.common.SubThreadConfig; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.IUploadListener; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; -import com.arialyy.aria.orm.DbEntity; import java.io.File; /** * Created by Aria.Lao on 2017/7/27. * 文件上传器 */ -class Uploader extends AbsFileer { +class Uploader extends AbsFileer { - Uploader(IUploadListener listener, UploadTaskEntity taskEntity) { + Uploader(IUploadListener listener, UTaskWrapper taskEntity) { super(listener, taskEntity); mTempFile = new File(mEntity.getFilePath()); setUpdateInterval( @@ -47,11 +46,11 @@ class Uploader extends AbsFileer { return 1; } - @Override protected AbsThreadTask selectThreadTask(SubThreadConfig config) { + @Override protected AbsThreadTask selectThreadTask(SubThreadConfig config) { switch (mTaskEntity.getRequestType()) { - case AbsTaskEntity.U_FTP: + case AbsTaskWrapper.U_FTP: return new FtpThreadTask(mConstance, mListener, config); - case AbsTaskEntity.U_HTTP: + case AbsTaskWrapper.U_HTTP: return new HttpThreadTask(mConstance, (IUploadListener) mListener, config); } return null; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/wrapper/UTEWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/upload/wrapper/UTEWrapper.java index e94de626..ce430c76 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/wrapper/UTEWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/wrapper/UTEWrapper.java @@ -15,8 +15,8 @@ */ package com.arialyy.aria.core.upload.wrapper; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.orm.AbsWrapper; import com.arialyy.aria.orm.annotation.Many; import com.arialyy.aria.orm.annotation.One; @@ -33,9 +33,9 @@ public class UTEWrapper extends AbsWrapper { public UploadEntity entity; @Many(parentColumn = "filePath", entityColumn = "key") - private List taskEntitys = null; + private List taskEntitys = null; - public UploadTaskEntity taskEntity; + public UTaskWrapper taskEntity; @Override public void handleConvert() { //taskEntity.entity = (tEntity == null || tEntity.isEmpty()) ? null : tEntity.get(0); diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java index 510016b1..7597ed9b 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -20,10 +20,10 @@ import com.arialyy.aria.core.common.TaskRecord; import com.arialyy.aria.core.common.ThreadRecord; 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.download.DGTaskWrapper; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; +import com.arialyy.aria.core.upload.UTaskWrapper; import java.util.HashMap; import java.util.Map; @@ -52,10 +52,10 @@ class DBConfig { } static { - mapping.put("DownloadGroupTaskEntity", DownloadGroupTaskEntity.class); + mapping.put("DGTaskWrapper", DGTaskWrapper.class); mapping.put("DownloadGroupEntity", DownloadGroupEntity.class); - mapping.put("DownloadTaskEntity", DownloadTaskEntity.class); - mapping.put("UploadTaskEntity", UploadTaskEntity.class); + mapping.put("DTaskWrapper", DTaskWrapper.class); + mapping.put("UTaskWrapper", UTaskWrapper.class); mapping.put("DownloadEntity", DownloadEntity.class); mapping.put("UploadEntity", UploadEntity.class); mapping.put("TaskRecord", TaskRecord.class); diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java index fa633970..d9448e25 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -21,15 +21,10 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.text.TextUtils; +import com.arialyy.aria.core.download.DTaskWrapper; 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.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.util.ALog; import java.lang.reflect.Field; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -191,39 +186,39 @@ final class SqlHelper extends SQLiteOpenHelper { //创建一个原本的表 mDelegate.createTable(db, clazz); - //插入数据 - if (list != null && list.size() > 0) { - DelegateUpdate update = DelegateManager.getInstance().getDelegate(DelegateUpdate.class); - try { - for (DbEntity entity : list) { - if (entity instanceof DownloadTaskEntity && ((DownloadTaskEntity) entity).isGroupTask()) { - if (TextUtils.isEmpty(((DownloadTaskEntity) entity).getKey())) { - ALog.w(TAG, "DownloadTaskEntity的key为空,将忽略该条数据"); - continue; - } - if (TextUtils.isEmpty(((DownloadTaskEntity) entity).getUrl())) { - List temp = map.get("DownloadEntity"); - boolean isRefresh = false; - for (DbEntity dbEntity : temp) { - if (((DownloadEntity) dbEntity).getDownloadPath() - .equals(((DownloadTaskEntity) entity).getKey())) { - ((DownloadTaskEntity) entity).setUrl(((DownloadEntity) dbEntity).getUrl()); - isRefresh = true; - break; - } - } - if (isRefresh) { - update.insertData(db, entity); - } - } - } else { - update.insertData(db, entity); - } - } - } catch (Exception e) { - ALog.e(TAG, ALog.getExceptionString(e)); - } - } + //插入数据,3.6版本后移除任务实体的保存 + //if (list != null && list.size() > 0) { + // DelegateUpdate update = DelegateManager.getInstance().getDelegate(DelegateUpdate.class); + // try { + // for (DbEntity entity : list) { + // if (entity instanceof DTaskWrapper && ((DTaskWrapper) entity).isGroupTask()) { + // if (TextUtils.isEmpty(((DTaskWrapper) entity).getKey())) { + // ALog.w(TAG, "DownloadTaskEntity的key为空,将忽略该条数据"); + // continue; + // } + // if (TextUtils.isEmpty(((DTaskWrapper) entity).getUrl())) { + // List temp = map.get("DownloadEntity"); + // boolean isRefresh = false; + // for (DbEntity dbEntity : temp) { + // if (((DownloadEntity) dbEntity).getDownloadPath() + // .equals(((DTaskWrapper) entity).getKey())) { + // ((DTaskWrapper) entity).setUrl(((DownloadEntity) dbEntity).getUrl()); + // isRefresh = true; + // break; + // } + // } + // if (isRefresh) { + // update.insertData(db, entity); + // } + // } + // } else { + // update.insertData(db, entity); + // } + // } + // } catch (Exception e) { + // ALog.e(TAG, ALog.getExceptionString(e)); + // } + //} //删除中介表 mDelegate.dropTable(db, tableName + "_temp"); diff --git a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java index 4ea24293..7b14f403 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java @@ -17,12 +17,11 @@ package com.arialyy.aria.util; import android.text.TextUtils; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; +import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; -import com.arialyy.aria.exception.FileException; import java.io.File; import java.util.List; import java.util.regex.Matcher; @@ -157,11 +156,11 @@ public class CheckUtil { /** * 检查任务实体 */ - public static void checkTaskEntity(AbsTaskEntity entity) { - if (entity instanceof DownloadTaskEntity) { - checkDownloadTaskEntity(((DownloadTaskEntity) entity).getEntity()); - } else if (entity instanceof UploadTaskEntity) { - checkUploadTaskEntity(((UploadTaskEntity) entity).getEntity()); + public static void checkTaskEntity(AbsTaskWrapper entity) { + if (entity instanceof DTaskWrapper) { + checkDownloadTaskEntity(((DTaskWrapper) entity).getEntity()); + } else if (entity instanceof UTaskWrapper) { + checkUploadTaskEntity(((UTaskWrapper) entity).getEntity()); } } @@ -171,10 +170,10 @@ public class CheckUtil { * @param checkType 删除命令和停止命令不需要检查下载链接和保存路径 * @return {@code false}实体无效 */ - public static boolean checkCmdEntity(AbsTaskEntity entity, boolean checkType) { + public static boolean checkCmdEntity(AbsTaskWrapper entity, boolean checkType) { boolean b = false; - if (entity instanceof DownloadTaskEntity) { - DownloadEntity entity1 = ((DownloadTaskEntity) entity).getEntity(); + if (entity instanceof DTaskWrapper) { + DownloadEntity entity1 = ((DTaskWrapper) entity).getEntity(); if (entity1 == null) { ALog.e(TAG, "下载实体不能为空"); } else if (checkType && TextUtils.isEmpty(entity1.getUrl())) { @@ -184,8 +183,8 @@ public class CheckUtil { } else { b = true; } - } else if (entity instanceof UploadTaskEntity) { - UploadEntity entity1 = ((UploadTaskEntity) entity).getEntity(); + } else if (entity instanceof UTaskWrapper) { + UploadEntity entity1 = ((UTaskWrapper) entity).getEntity(); if (entity1 == null) { ALog.e(TAG, "上传实体不能为空"); } else if (TextUtils.isEmpty(entity1.getFilePath())) { diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index 24b27a91..a3aed86c 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -35,12 +35,11 @@ import com.arialyy.aria.core.common.AbsFileer; 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.download.DownloadTaskEntity; -import com.arialyy.aria.core.inf.AbsGroupTaskEntity; +import com.arialyy.aria.core.download.DownloadGroupTask; +import com.arialyy.aria.core.inf.AbsGroupTaskWrapper; import com.arialyy.aria.core.inf.AbsNormalEntity; -import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; -import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.orm.DbEntity; import dalvik.system.DexFile; import java.io.File; @@ -700,10 +699,8 @@ public class CommonUtil { } //下载任务实体和下载实体为一对一关系,下载实体删除,任务实体自动删除 if (type == 1) { - DbEntity.deleteData(DownloadTaskEntity.class, "key=?", filePath); DbEntity.deleteData(DownloadEntity.class, "downloadPath=?", filePath); } else { - DbEntity.deleteData(UploadTaskEntity.class, "key=?", filePath); DbEntity.deleteData(UploadEntity.class, "filePath=?", filePath); } } @@ -856,7 +853,7 @@ public class CommonUtil { * @param taskType {@link ICmd#TASK_TYPE_DOWNLOAD}、{@link ICmd#TASK_TYPE_DOWNLOAD_GROUP}、{@link * ICmd#TASK_TYPE_UPLOAD} */ - public static AbsNormalCmd createNormalCmd(T entity, int cmd, + public static AbsNormalCmd createNormalCmd(T entity, int cmd, int taskType) { return NormalCmdFactory.getInstance().createCmd(entity, cmd, taskType); } @@ -866,7 +863,7 @@ public class CommonUtil { * * @param childUrl 子任务url */ - public static AbsGroupCmd createGroupCmd(String target, T entity, + public static AbsGroupCmd createGroupCmd(String target, T entity, int cmd, String childUrl) { return GroupCmdFactory.getInstance().createCmd(target, entity, cmd, childUrl); } diff --git a/app/src/main/java/com/arialyy/simple/DbTestActivity.java b/app/src/main/java/com/arialyy/simple/DbTestActivity.java index a7b318e5..30de9f59 100644 --- a/app/src/main/java/com/arialyy/simple/DbTestActivity.java +++ b/app/src/main/java/com/arialyy/simple/DbTestActivity.java @@ -4,8 +4,8 @@ import android.os.Bundle; import android.util.Log; import android.view.View; +import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.orm.DbEntity; import com.arialyy.simple.base.BaseActivity; @@ -40,7 +40,7 @@ public class DbTestActivity extends BaseActivity { private void searchAll(){ long startT = System.currentTimeMillis(); - //List data = DownloadEntity.findRelationData(DownloadEntity.class); + //List data = DownloadEntity.findRelationData(DownloadEntity.class); long endT = System.currentTimeMillis(); Log.d(TAG, "search_time=" + (endT - startT)); @@ -58,7 +58,7 @@ public class DbTestActivity extends BaseActivity { entity.setFileName("ssssssssssssssssss"); entity.setDownloadPath(key); - DownloadTaskEntity dte = new DownloadTaskEntity(); + DTaskWrapper dte = new DTaskWrapper(); dte.setUrl(url); dte.setKey(key); dte.setEntity(entity); 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 d100451c..021f83a8 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 @@ -25,7 +25,7 @@ import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupTask; -import com.arialyy.aria.core.download.DownloadGroupTaskEntity; +import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.T; import com.arialyy.simple.R; @@ -48,7 +48,7 @@ public class DownloadGroupActivity extends BaseActivity { mBar.setVisibility(View.GONE); module = new AnyRunnModule(this); urls = getResources().getStringArray(R.array.group_urls); - DownloadTaskEntity entity = Aria.download(this).getDownloadTask(URL); + DTaskWrapper entity = Aria.download(this).getDownloadTask(URL); Log.d(TAG, entity + ""); } diff --git a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java index c4a38254..1281a680 100644 --- a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java +++ b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java @@ -25,10 +25,10 @@ import com.arialyy.aria.core.upload.uploader.SimpleUploadUtil; /** * Created by lyy on 2017/2/23. 上传任务 */ -public class UploadTask extends AbsNormalTask { +public class UploadTask extends AbsNormalTask { - private UploadTask(UploadTaskEntity taskEntity, Handler outHandler) { - mTaskEntity = taskEntity; + private UploadTask(UTaskWrapper taskEntity, Handler outHandler) { + mTaskWrapper = taskEntity; mOutHandler = outHandler; mListener = new BaseUListener(this, mOutHandler); mUtil = new SimpleUploadUtil(taskEntity, (IUploadListener) mListener); @@ -39,26 +39,26 @@ public class UploadTask extends AbsNormalTask { } @Override public String getKey() { - return mTaskEntity.getEntity().getFilePath(); + return mTaskWrapper.getEntity().getFilePath(); } public UploadEntity getEntity() { - return mTaskEntity.getEntity(); + return mTaskWrapper.getEntity(); } @Override public String getTaskName() { - return mTaskEntity.getEntity().getFileName(); + return mTaskWrapper.getEntity().getFileName(); } public static class Builder { private Handler mOutHandler; - private UploadTaskEntity mTaskEntity; + private UTaskWrapper mTaskEntity; public void setOutHandler(ISchedulers outHandler) { mOutHandler = new Handler(Looper.getMainLooper(), outHandler); } - public void setUploadTaskEntity(UploadTaskEntity taskEntity) { + public void setUploadTaskEntity(UTaskWrapper taskEntity) { mTaskEntity = taskEntity; } diff --git a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java deleted file mode 100644 index 09fc362f..00000000 --- a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskEntity.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.arialyy.aria.core.upload; - -import com.arialyy.aria.core.inf.AbsNormalTaskEntity; -import com.arialyy.aria.orm.ActionPolicy; -import com.arialyy.aria.orm.annotation.Foreign; -import com.arialyy.aria.orm.annotation.Ignore; -import com.arialyy.aria.orm.annotation.Primary; -import java.util.HashMap; -import java.util.Map; - -/** - * Created by lyy on 2017/2/9. - * 上传任务实体 - */ -public class UploadTaskEntity extends AbsNormalTaskEntity { - private String attachment; //文件上传需要的key - private String contentType = "multipart/form-data"; //上传的文件类型 - private String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)"; - - @Ignore private UploadEntity entity; - - private String filePath; - - @Primary - @Foreign(parent = UploadEntity.class, column = "filePath", - onUpdate = ActionPolicy.CASCADE, onDelete = ActionPolicy.CASCADE) - private String key; - - /** - * 文件上传表单 - */ - private Map formFields = new HashMap<>(); - - public UploadTaskEntity() { - } - - @Override public UploadEntity getEntity() { - return entity; - } - - @Override public String getKey() { - return key; - } - - public void setEntity(UploadEntity entity) { - this.entity = entity; - } - - public String getFilePath() { - return filePath; - } - - public void setFilePath(String filePath) { - this.filePath = filePath; - } - - public void setKey(String key) { - this.key = key; - } - - public Map getFormFields() { - return formFields; - } - - public void setFormFields(Map formFields) { - this.formFields = formFields; - } - - public String getAttachment() { - return attachment; - } - - public void setAttachment(String attachment) { - this.attachment = attachment; - } - - public String getContentType() { - return contentType; - } - - public void setContentType(String contentType) { - this.contentType = contentType; - } - - public String getUserAgent() { - return userAgent; - } - - public void setUserAgent(String userAgent) { - this.userAgent = userAgent; - } -}