组件化功能基本完成

pull/617/head
laoyuyu 5 years ago
parent 7ee1347ab4
commit 2a92321785
  1. 1
      AppFrame/src/main/java/com/arialyy/frame/cache/DiskLruCache.java
  2. 10
      Aria/build.gradle
  3. 139
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  4. 2
      Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java
  5. 2
      Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java
  6. 10
      Aria/src/main/java/com/arialyy/aria/core/command/AbsGroupCmd.java
  7. 20
      Aria/src/main/java/com/arialyy/aria/core/command/AbsNormalCmd.java
  8. 4
      Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java
  9. 14
      Aria/src/main/java/com/arialyy/aria/core/command/CancelAllCmd.java
  10. 4
      Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java
  11. 44
      Aria/src/main/java/com/arialyy/aria/core/command/CmdHelper.java
  12. 2
      Aria/src/main/java/com/arialyy/aria/core/command/DGSubStartCmd.java
  13. 2
      Aria/src/main/java/com/arialyy/aria/core/command/DGSubStopCmd.java
  14. 2
      Aria/src/main/java/com/arialyy/aria/core/command/GroupCmdFactory.java
  15. 8
      Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java
  16. 2
      Aria/src/main/java/com/arialyy/aria/core/command/NormalCmdFactory.java
  17. 4
      Aria/src/main/java/com/arialyy/aria/core/command/ReStartCmd.java
  18. 18
      Aria/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.java
  19. 41
      Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java
  20. 2
      Aria/src/main/java/com/arialyy/aria/core/command/StopAllCmd.java
  21. 4
      Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java
  22. 1
      Aria/src/main/java/com/arialyy/aria/core/common/AbsNormalTarget.java
  23. 3
      Aria/src/main/java/com/arialyy/aria/core/common/BaseDelegate.java
  24. 31
      Aria/src/main/java/com/arialyy/aria/core/common/FTPSDelegate.java
  25. 21
      Aria/src/main/java/com/arialyy/aria/core/common/FtpDelegate.java
  26. 94
      Aria/src/main/java/com/arialyy/aria/core/common/HttpDelegate.java
  27. 457
      Aria/src/main/java/com/arialyy/aria/core/common/RecordHandler.java
  28. 10
      Aria/src/main/java/com/arialyy/aria/core/common/controller/BuilderController.java
  29. 10
      Aria/src/main/java/com/arialyy/aria/core/common/controller/FeatureController.java
  30. 18
      Aria/src/main/java/com/arialyy/aria/core/common/controller/NormalController.java
  31. 28
      Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java
  32. 8
      Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java
  33. 11
      Aria/src/main/java/com/arialyy/aria/core/download/CheckFtpDirEntityUtil.java
  34. 16
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  35. 129
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java
  36. 140
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/SimpleDownloadUtil.java
  37. 133
      Aria/src/main/java/com/arialyy/aria/core/download/group/SubDLoadUtil.java
  38. 22
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java
  39. 12
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveDelegate.java
  40. 13
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodDelegate.java
  41. 145
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodUtil.java
  42. 6
      Aria/src/main/java/com/arialyy/aria/core/download/target/AbsGroupConfigHandler.java
  43. 4
      Aria/src/main/java/com/arialyy/aria/core/download/target/DNormalConfigHandler.java
  44. 10
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java
  45. 8
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java
  46. 5
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirConfigHandler.java
  47. 8
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java
  48. 10
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java
  49. 11
      Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java
  50. 6
      Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java
  51. 14
      Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java
  52. 1
      Aria/src/main/java/com/arialyy/aria/core/download/target/HttpGroupConfigHandler.java
  53. 4
      Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java
  54. 4
      Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java
  55. 7
      Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpDelegate.java
  56. 36
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java
  57. 8
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsReceiver.java
  58. 3
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  59. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/IConfigHandler.java
  60. 6
      Aria/src/main/java/com/arialyy/aria/core/manager/DTaskWrapperFactory.java
  61. 4
      Aria/src/main/java/com/arialyy/aria/core/manager/IGroupWrapperFactory.java
  62. 4
      Aria/src/main/java/com/arialyy/aria/core/manager/INormalTEFactory.java
  63. 6
      Aria/src/main/java/com/arialyy/aria/core/manager/SubTaskManager.java
  64. 2
      Aria/src/main/java/com/arialyy/aria/core/manager/TaskWrapperManager.java
  65. 18
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  66. 23
      Aria/src/main/java/com/arialyy/aria/core/queue/DGroupTaskQueue.java
  67. 23
      Aria/src/main/java/com/arialyy/aria/core/queue/DTaskQueue.java
  68. 11
      Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
  69. 12
      Aria/src/main/java/com/arialyy/aria/core/queue/TaskFactory.java
  70. 23
      Aria/src/main/java/com/arialyy/aria/core/queue/UTaskQueue.java
  71. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java
  72. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java
  73. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/DGLoadExecutePool.java
  74. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/DLoadExecutePool.java
  75. 4
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/IPool.java
  76. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/UploadExecutePool.java
  77. 4
      Aria/src/main/java/com/arialyy/aria/core/scheduler/FailureTaskHandler.java
  78. 8
      Aria/src/main/java/com/arialyy/aria/core/scheduler/NormalTaskListener.java
  79. 4
      Aria/src/main/java/com/arialyy/aria/core/scheduler/SubTaskListener.java
  80. 29
      Aria/src/main/java/com/arialyy/aria/core/scheduler/TaskSchedulers.java
  81. 13
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  82. 8
      Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java
  83. 11
      Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java
  84. 6
      Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java
  85. 6
      Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java
  86. 17
      Aria/src/main/java/com/arialyy/aria/core/upload/target/UNormalConfigHandler.java
  87. 116
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/SimpleUploadUtil.java
  88. 61
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/Uploader.java
  89. 10
      AriaAnnotations/src/main/java/com/arialyy/annotations/TaskEnum.java
  90. 2
      AriaCompiler/src/main/java/com/arialyy/compiler/EntityInfo.java
  91. 26
      AriaFtpComponent/src/androidTest/java/com/example/ariaftpcomponent/ExampleInstrumentedTest.java
  92. 4
      AriaFtpComponent/src/main/java/com/arialyy/aria/ftpcomponent/bb.java
  93. 17
      AriaFtpComponent/src/test/java/com/example/ariaftpcomponent/ExampleUnitTest.java
  94. 0
      FtpComponent/.gitignore
  95. 33
      FtpComponent/build.gradle
  96. 0
      FtpComponent/consumer-rules.pro
  97. 0
      FtpComponent/proguard-rules.pro
  98. 0
      FtpComponent/src/main/AndroidManifest.xml
  99. 46
      FtpComponent/src/main/java/com/arialyy/aria/ftp/AbsFtpInfoThread.java
  100. 35
      FtpComponent/src/main/java/com/arialyy/aria/ftp/BaseFtpThreadTaskAdapter.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -245,7 +245,6 @@ public final class DiskLruCache implements Closeable {
/**
* Recursively delete everything in {@code dir}.
*/
// TODO: this should specify paths as Strings rather than as Files
public static void deleteContents(File dir) throws IOException {
File[] files = dir.listFiles();
if (files == null) {

@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 329
versionName "3.2.9"
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
}
buildTypes {
release {
@ -26,9 +26,13 @@ dependencies {
testImplementation 'junit:junit:4.12'
implementation "androidx.appcompat:appcompat:${rootProject.ext.XAppcompatVersion}"
api project(':AriaAnnotations')
api 'com.arialyy.aria:aria-ftp-plug:1.0.4' //
api project(path: ':PublicComponent')
api 'com.arialyy.aria:aria-ftp-plug:1.0.4'
implementation project(path: ':HttpComponent') //
// compile project(':AriaFtpPlug')
// implementation project(path: ':AriaFtpComponent')
}
apply from: 'bintray-release.gradle'

@ -34,18 +34,16 @@ import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import com.arialyy.aria.core.command.CommandManager;
import com.arialyy.aria.core.common.QueueMod;
import com.arialyy.aria.core.common.RecordHandler;
import com.arialyy.aria.core.config.AppConfig;
import com.arialyy.aria.core.config.Configuration;
import com.arialyy.aria.core.config.DGroupConfig;
import com.arialyy.aria.core.config.DownloadConfig;
import com.arialyy.aria.core.config.UploadConfig;
import com.arialyy.aria.core.config.XMLReader;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.IReceiver;
import com.arialyy.aria.core.inf.IRecordHandler;
import com.arialyy.aria.core.inf.ReceiverType;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadReceiver;
@ -53,19 +51,13 @@ import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.DelegateWrapper;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.AriaCrashHandler;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.RecordUtil;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
/**
* Created by lyy on 2016/12/1. https://github.com/AriaLyy/Aria Aria管理器,任务操作在这里执行
@ -73,12 +65,8 @@ import org.xml.sax.SAXException;
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class AriaManager {
private static final String TAG = "AriaManager";
private static final Object LOCK = new Object();
public static final String DOWNLOAD_TEMP_DIR = "/Aria/temp/download/";
public static final String UPLOAD_TEMP_DIR = "/Aria/temp/upload/";
/**
* 是否已经联网true 已经联网
*/
private static boolean isConnectedNet = true;
@SuppressLint("StaticFieldLeak") private static volatile AriaManager INSTANCE = null;
private Map<String, AbsReceiver> mReceivers = new ConcurrentHashMap<>();
@ -87,12 +75,9 @@ import org.xml.sax.SAXException;
*/
private Map<String, List<String>> mSubClass = new ConcurrentHashMap<>();
private static Context APP;
private DownloadConfig mDConfig;
private UploadConfig mUConfig;
private AppConfig mAConfig;
private DGroupConfig mDGConfig;
private Handler mAriaHandler;
private DelegateWrapper mDbWrapper;
private AriaConfig mConfig;
private AriaManager(Context context) {
APP = context.getApplicationContext();
@ -118,55 +103,18 @@ import org.xml.sax.SAXException;
}
private void initData() {
mConfig = AriaConfig.init(APP);
initDb(APP);
regAppLifeCallback(APP);
initConfig();
initAria();
amendTaskState();
regNetCallBack(APP);
}
public Context getAPP() {
return APP;
}
/**
* 注册网络监听只有配置了检查网络{@link AppConfig#isNetCheck()}才会注册事件
*/
private void regNetCallBack(Context context) {
if (!getAppConfig().isNetCheck()) {
return;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return;
}
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null) {
return;
}
NetworkRequest.Builder builder = new NetworkRequest.Builder();
NetworkRequest request = builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
.build();
cm.registerNetworkCallback(request, new ConnectivityManager.NetworkCallback() {
@Override public void onLost(Network network) {
super.onLost(network);
isConnectedNet = false;
ALog.d(TAG, "onLost");
}
@Override public void onAvailable(Network network) {
super.onAvailable(network);
ALog.d(TAG, "onAvailable");
isConnectedNet = true;
}
});
}
/**
* 初始化数据库
@ -186,10 +134,11 @@ import org.xml.sax.SAXException;
}
private void initAria() {
if (mAConfig.getUseAriaCrashHandler()) {
AppConfig appConfig = mConfig.getAConfig();
if (appConfig.getUseAriaCrashHandler()) {
Thread.setDefaultUncaughtExceptionHandler(new AriaCrashHandler());
}
mAConfig.setLogLevel(mAConfig.getLogLevel());
appConfig.setLogLevel(appConfig.getLogLevel());
CommandManager.init();
}
@ -217,9 +166,7 @@ import org.xml.sax.SAXException;
return mAriaHandler;
}
public boolean isConnectedNet() {
return isConnectedNet;
}
public Map<String, AbsReceiver> getReceiver() {
return mReceivers;
@ -237,7 +184,7 @@ import org.xml.sax.SAXException;
* @deprecated 后续版本会删除该api
*/
@Deprecated public AriaManager setUploadQueueMod(QueueMod mod) {
mUConfig.setQueueMod(mod.tag);
mConfig.getUConfig().setQueueMod(mod.tag);
return this;
}
@ -253,7 +200,7 @@ import org.xml.sax.SAXException;
* @deprecated 后续版本会删除该api
*/
@Deprecated public AriaManager setDownloadQueueMod(QueueMod mod) {
mDConfig.setQueueMod(mod.tag);
mConfig.getDConfig().setQueueMod(mod.tag);
return this;
}
@ -267,7 +214,7 @@ import org.xml.sax.SAXException;
* </pre>
*/
public DownloadConfig getDownloadConfig() {
return mDConfig;
return mConfig.getDConfig();
}
/**
@ -280,14 +227,14 @@ import org.xml.sax.SAXException;
* </pre>
*/
public UploadConfig getUploadConfig() {
return mUConfig;
return mConfig.getUConfig();
}
/**
* 获取APP配置
*/
public AppConfig getAppConfig() {
return mAConfig;
return mConfig.getAConfig();
}
/**
@ -300,7 +247,7 @@ import org.xml.sax.SAXException;
* </pre>
*/
public DGroupConfig getDGroupConfig() {
return mDGConfig;
return mConfig.getDGConfig();
}
/**
@ -335,13 +282,13 @@ import org.xml.sax.SAXException;
public void delRecord(int type, String key, boolean removeFile) {
switch (type) {
case 1: // 删除普通任务记录
RecordUtil.delTaskRecord(key, RecordHandler.TYPE_DOWNLOAD, removeFile, true);
RecordUtil.delTaskRecord(key, IRecordHandler.TYPE_DOWNLOAD, removeFile, true);
break;
case 2:
RecordUtil.delGroupTaskRecord(key, removeFile);
break;
case 3:
RecordUtil.delTaskRecord(key, RecordHandler.TYPE_UPLOAD);
RecordUtil.delTaskRecord(key, IRecordHandler.TYPE_UPLOAD);
break;
}
}
@ -442,58 +389,6 @@ import org.xml.sax.SAXException;
return String.format("%s_%s_%s", obj.getClass().getName(), type, obj.hashCode());
}
/**
* 初始化配置文件
*/
private void initConfig() {
mDConfig = Configuration.getInstance().downloadCfg;
mUConfig = Configuration.getInstance().uploadCfg;
mAConfig = Configuration.getInstance().appCfg;
mDGConfig = Configuration.getInstance().dGroupCfg;
File xmlFile = new File(APP.getFilesDir().getPath() + Configuration.XML_FILE);
File tempDir = new File(APP.getFilesDir().getPath() + "/temp");
if (!xmlFile.exists()) {
loadConfig();
} else {
try {
String md5Code = CommonUtil.getFileMD5(xmlFile);
File file = new File(APP.getFilesDir().getPath() + "/temp.xml");
if (file.exists()) {
file.delete();
}
CommonUtil.createFileFormInputStream(APP.getAssets().open("aria_config.xml"),
file.getPath());
if (!CommonUtil.checkMD5(md5Code, file) || !Configuration.getInstance().configExists()) {
loadConfig();
}
} catch (IOException e) {
e.printStackTrace();
}
}
if (tempDir.exists()) {
File newDir = new File(APP.getFilesDir().getPath() + DOWNLOAD_TEMP_DIR);
newDir.mkdirs();
tempDir.renameTo(newDir);
}
}
/**
* 加载配置文件
*/
private void loadConfig() {
try {
XMLReader helper = new XMLReader();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
parser.parse(APP.getAssets().open("aria_config.xml"), helper);
CommonUtil.createFileFormInputStream(APP.getAssets().open("aria_config.xml"),
APP.getFilesDir().getPath() + Configuration.XML_FILE);
} catch (ParserConfigurationException | IOException | SAXException e) {
ALog.e(TAG, e.toString());
}
}
/**
* 注册APP生命周期回调
*/

@ -16,7 +16,7 @@
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.queue.AbsTaskQueue;
/**

@ -15,7 +15,7 @@
*/
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
/**
* Created by AriaL on 2017/6/29.

@ -15,11 +15,11 @@
*/
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.download.AbsGroupTaskWrapper;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.inf.AbsGroupTask;
import com.arialyy.aria.core.inf.AbsGroupTaskWrapper;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DGroupTaskQueue;
import com.arialyy.aria.core.task.AbsGroupTask;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
@ -39,7 +39,7 @@ public abstract class AbsGroupCmd<T extends AbsGroupTaskWrapper> extends AbsCmd<
mTaskWrapper = entity;
TAG = CommonUtil.getClassName(this);
if (entity instanceof DGTaskWrapper) {
mQueue = DownloadGroupTaskQueue.getInstance();
mQueue = DGroupTaskQueue.getInstance();
isDownloadCmd = true;
}
}

@ -18,14 +18,14 @@ package com.arialyy.aria.core.command;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask;
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.task.ITask;
import com.arialyy.aria.core.queue.DGroupTaskQueue;
import com.arialyy.aria.core.queue.DTaskQueue;
import com.arialyy.aria.core.queue.UTaskQueue;
import com.arialyy.aria.core.listener.ISchedulers;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
@ -54,19 +54,19 @@ public abstract class AbsNormalCmd<T extends AbsTaskWrapper> extends AbsCmd<T> {
ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD");
return;
}
mQueue = DownloadTaskQueue.getInstance();
mQueue = DTaskQueue.getInstance();
} else if (taskType == ITask.DOWNLOAD_GROUP) {
if (!(entity instanceof DGTaskWrapper)) {
ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD_GROUP");
return;
}
mQueue = DownloadGroupTaskQueue.getInstance();
mQueue = DGroupTaskQueue.getInstance();
} else if (taskType == ITask.UPLOAD) {
if (!(entity instanceof UTaskWrapper)) {
ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_UPLOAD");
return;
}
mQueue = UploadTaskQueue.getInstance();
mQueue = UTaskQueue.getInstance();
} else {
ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD、TASK_TYPE_DOWNLOAD_GROUP、TASK_TYPE_UPLOAD");
return;

@ -16,8 +16,8 @@
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.ALog;

@ -20,11 +20,11 @@ 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.inf.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.manager.TaskWrapperManager;
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.queue.DGroupTaskQueue;
import com.arialyy.aria.core.queue.DTaskQueue;
import com.arialyy.aria.core.queue.UTaskQueue;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.orm.DbEntity;
@ -104,11 +104,11 @@ final public class CancelAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T
return;
}
if (te instanceof DTaskWrapper) {
mQueue = DownloadTaskQueue.getInstance();
mQueue = DTaskQueue.getInstance();
} else if (te instanceof UTaskWrapper) {
mQueue = UploadTaskQueue.getInstance();
mQueue = UTaskQueue.getInstance();
} else if (te instanceof DGTaskWrapper) {
mQueue = DownloadGroupTaskQueue.getInstance();
mQueue = DGroupTaskQueue.getInstance();
}
te.setRemoveFile(removeFile);
removeTask(te);

@ -16,8 +16,8 @@
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
/**
* Created by lyy on 2016/9/20.

@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.command;
import com.arialyy.aria.core.download.AbsGroupTaskWrapper;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
public class CmdHelper {
/**
* 创建任务命令
*
* @param taskType {@link ITask#DOWNLOAD}{@link ITask#DOWNLOAD_GROUP}{@link ITask#UPLOAD}
*/
public static <T extends AbsTaskWrapper> AbsNormalCmd createNormalCmd(T entity, int cmd,
int taskType) {
return NormalCmdFactory.getInstance().createCmd(entity, cmd, taskType);
}
/**
* 创建任务组命令
*
* @param childUrl 子任务url
*/
public static <T extends AbsGroupTaskWrapper> AbsGroupCmd createGroupCmd(T entity, int cmd,
String childUrl) {
return GroupCmdFactory.getInstance().createCmd(entity, cmd, childUrl);
}
}

@ -15,7 +15,7 @@
*/
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsGroupTaskWrapper;
import com.arialyy.aria.core.download.AbsGroupTaskWrapper;
/**
* Created by AriaL on 2017/6/29.

@ -15,7 +15,7 @@
*/
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsGroupTaskWrapper;
import com.arialyy.aria.core.download.AbsGroupTaskWrapper;
/**
* Created by AriaL on 2017/6/29.

@ -15,7 +15,7 @@
*/
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsGroupTaskWrapper;
import com.arialyy.aria.core.download.AbsGroupTaskWrapper;
/**
* Created by AriaL on 2017/6/29. 任务组子任务控制命令

@ -16,9 +16,9 @@
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.queue.DTaskQueue;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.NetUtils;
@ -50,7 +50,7 @@ final class HighestPriorityCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T>
task = (DownloadTask) createTask();
}
if (task != null) {
((DownloadTaskQueue) mQueue).setTaskHighestPriority(task);
((DTaskQueue) mQueue).setTaskHighestPriority(task);
}
}
}

@ -16,7 +16,7 @@
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
/**
* Created by Lyy on 2016/9/23.

@ -15,8 +15,8 @@
*/
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.TaskSchedulerType;
/**

@ -5,14 +5,14 @@ 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.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.manager.TaskWrapperManager;
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.queue.DGroupTaskQueue;
import com.arialyy.aria.core.queue.DTaskQueue;
import com.arialyy.aria.core.queue.UTaskQueue;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.orm.DbEntity;
@ -112,11 +112,11 @@ final class ResumeAllCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
for (AbsTaskWrapper te : mWaitList) {
if (te instanceof DTaskWrapper) {
mQueue = DownloadTaskQueue.getInstance();
mQueue = DTaskQueue.getInstance();
} else if (te instanceof UTaskWrapper) {
mQueue = UploadTaskQueue.getInstance();
mQueue = UTaskQueue.getInstance();
} else if (te instanceof DGTaskWrapper) {
mQueue = DownloadGroupTaskQueue.getInstance();
mQueue = DGroupTaskQueue.getInstance();
}
if (mQueue.getCurrentExePoolNum() < maxTaskNum) {
startTask(createTask(te));

@ -22,16 +22,17 @@ 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.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.manager.TaskWrapperManager;
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.queue.DGroupTaskQueue;
import com.arialyy.aria.core.queue.DTaskQueue;
import com.arialyy.aria.core.queue.UTaskQueue;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
@ -156,22 +157,24 @@ final class StartCmd<T extends AbsTaskWrapper> extends AbsNormalCmd<T> {
}
private void handleTask(List<AbsTaskWrapper> waitList) {
for (AbsTaskWrapper te : waitList) {
if (te.getEntity() == null) continue;
AbsTask task = getTask(te.getKey());
for (AbsTaskWrapper wrapper : waitList) {
if (wrapper.getEntity() == null) continue;
AbsTask task = getTask(wrapper.getKey());
if (task != null) continue;
if (te instanceof DTaskWrapper) {
if (te.getRequestType() == ITaskWrapper.D_FTP
|| te.getRequestType() == ITaskWrapper.U_FTP) {
te.asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(te.getEntity().getKey()));
if (wrapper instanceof DTaskWrapper) {
if (wrapper.getRequestType() == ITaskWrapper.D_FTP
|| wrapper.getRequestType() == ITaskWrapper.U_FTP) {
wrapper.getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity,
CommonUtil.getFtpUrlInfo(wrapper.getEntity().getKey()));
}
mQueue = DownloadTaskQueue.getInstance();
} else if (te instanceof UTaskWrapper) {
mQueue = UploadTaskQueue.getInstance();
} else if (te instanceof DGTaskWrapper) {
mQueue = DownloadGroupTaskQueue.getInstance();
mQueue = DTaskQueue.getInstance();
} else if (wrapper instanceof UTaskWrapper) {
mQueue = UTaskQueue.getInstance();
} else if (wrapper instanceof DGTaskWrapper) {
mQueue = DGroupTaskQueue.getInstance();
}
createTask(te);
createTask(wrapper);
}
}
}

@ -1,6 +1,6 @@
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
/**
* Created by AriaL on 2017/6/13.

@ -16,8 +16,8 @@
package com.arialyy.aria.core.command;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.ALog;

@ -18,7 +18,6 @@ package com.arialyy.aria.core.common;
import com.arialyy.aria.core.common.controller.INormalFeature;
import com.arialyy.aria.core.common.controller.NormalController;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.manager.TaskWrapperManager;

@ -19,7 +19,8 @@ import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.common.controller.FeatureController;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.CommonUtil;
public abstract class BaseDelegate<TARGET extends AbsTarget> {

@ -13,15 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.common.ftp;
package com.arialyy.aria.core.common;
import android.text.TextUtils;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseDelegate;
import com.arialyy.aria.core.common.ProtocolType;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.ProtocolType;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.util.ALog;
/**
* D_FTP SSL/TSL 参数委托
@ -32,8 +34,11 @@ public class FTPSDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
public FTPSDelegate(TARGET target, AbsTaskWrapper wrapper) {
super(target, wrapper);
mUrlEntity = getTaskWrapper().asFtp().getUrlEntity();
mUrlEntity.isFtps = true;
mUrlEntity = (FtpUrlEntity) getTaskWrapper().getOptionParams()
.getParam(IOptionConstant.ftpUrlEntity);
if (mUrlEntity != null) {
mUrlEntity.isFtps = true;
}
}
/**
@ -44,7 +49,8 @@ public class FTPSDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FTPSDelegate<TARGET> setProtocol(@ProtocolType String protocol) {
if (TextUtils.isEmpty(protocol)) {
throw new NullPointerException("协议为空");
ALog.e(TAG, "设置协议失败,协议信息为空");
return this;
}
mUrlEntity.protocol = protocol;
return this;
@ -58,7 +64,8 @@ public class FTPSDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FTPSDelegate<TARGET> setAlias(String keyAlias) {
if (TextUtils.isEmpty(keyAlias)) {
throw new NullPointerException("别名为空");
ALog.e(TAG, "设置证书别名失败,证书别名为空");
return this;
}
mUrlEntity.keyAlias = keyAlias;
return this;
@ -72,7 +79,8 @@ public class FTPSDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FTPSDelegate<TARGET> setStorePass(String storePass) {
if (TextUtils.isEmpty(storePass)) {
throw new NullPointerException("证书密码为空");
ALog.e(TAG, "设置证书密码失败,证书密码为空");
return this;
}
mUrlEntity.storePass = storePass;
return this;
@ -86,7 +94,8 @@ public class FTPSDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FTPSDelegate<TARGET> setStorePath(String storePath) {
if (TextUtils.isEmpty(storePath)) {
throw new NullPointerException("证书路径为空");
ALog.e(TAG, "设置证书路径失败,证书路径为空");
return this;
}
mUrlEntity.storePath = storePath;
return this;

@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.common.ftp;
package com.arialyy.aria.core.common;
import android.text.TextUtils;
import androidx.annotation.CheckResult;
import aria.apache.commons.net.ftp.FTPClientConfig;
import com.arialyy.aria.core.common.BaseDelegate;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.util.ALog;
/**
@ -39,7 +40,7 @@ public class FtpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
if (TextUtils.isEmpty(charSet)) {
throw new NullPointerException("字符编码为空");
}
getTaskWrapper().asFtp().setCharSet(charSet);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.charSet, charSet);
return this;
}
@ -58,7 +59,13 @@ public class FtpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
return this;
}
// urlEntity 不能在构造函数中获取,因为ftp上传时url是后于构造函数的
FtpUrlEntity urlEntity = getTaskWrapper().asFtp().getUrlEntity();
FtpUrlEntity urlEntity =
(FtpUrlEntity) getTaskWrapper().getOptionParams()
.getParam(IOptionConstant.ftpUrlEntity);
if (urlEntity == null) {
ALog.e(TAG, "设置登陆信息失败,FtpUrlEntity为空");
return this;
}
urlEntity.needLogin = true;
urlEntity.user = userName;
urlEntity.password = password;
@ -81,7 +88,7 @@ public class FtpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FtpDelegate<TARGET> setFtpClentConfig(FTPClientConfig config) {
getTaskWrapper().asFtp().setClientConfig(config);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.clientConfig, config);
return this;
}

@ -13,28 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.common.http;
package com.arialyy.aria.core.common;
import android.text.TextUtils;
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import com.arialyy.aria.core.common.BaseDelegate;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.util.ALog;
import java.net.Proxy;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* HTTP协议处理
*/
public class HttpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET> {
private Map<String, String> params;
private Map<String, String> headers;
public HttpDelegate(TARGET target, AbsTaskWrapper wrapper) {
super(target, wrapper);
}
@ -46,7 +46,7 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public HttpDelegate<TARGET> setRequestType(RequestEnum requestEnum) {
getTaskWrapper().asHttp().setRequestEnum(requestEnum);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.requestEnum, requestEnum);
return this;
}
@ -55,7 +55,11 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public HttpDelegate<TARGET> setParams(Map<String, String> params) {
getTaskWrapper().asHttp().setParams(params);
if (this.params == null) {
this.params = new HashMap<>();
}
this.params.putAll(params);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.params, this.params);
return this;
}
@ -68,12 +72,11 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
ALog.d(TAG, "key 或value 为空");
return this;
}
Map<String, String> params = getTaskWrapper().asHttp().getParams();
if (params == null) {
params = new HashMap<>();
getTaskWrapper().asHttp().setParams(params);
}
params.put(key, value);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.params, params);
return this;
}
@ -82,7 +85,7 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public HttpDelegate<TARGET> setFormFields(Map<String, String> params) {
getTaskWrapper().asHttp().setFormFields(params);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.formFields, params);
return this;
}
@ -102,7 +105,11 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
ALog.w(TAG, "设置header失败,header对应的value不能为null");
return this;
}
addHeader(getTaskWrapper(), key, value);
if (this.headers == null) {
this.headers = new HashMap<>();
}
this.headers.put(key, value);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.headers, this.headers);
return this;
}
@ -118,7 +125,11 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
ALog.w(TAG, "设置header失败,map没有header数据");
return this;
}
addHeaders(getTaskWrapper(), headers);
if (this.headers == null) {
this.headers = new HashMap<>();
}
this.headers.putAll(headers);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.headers, this.headers);
return this;
}
@ -127,60 +138,7 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public HttpDelegate<TARGET> setUrlProxy(Proxy proxy) {
getTaskWrapper().asHttp().setProxy(proxy);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.proxy, proxy);
return this;
}
private void addHeader(AbsTaskWrapper taskWrapper, String key, String value) {
HttpTaskConfig 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);
}
}
private void addHeaders(AbsTaskWrapper taskWrapper, Map<String, String> headers) {
HttpTaskConfig taskDelegate = taskWrapper.asHttp();
/*
两个map比较逻辑
1比对key是否相同
2如果key相同比对value是否相同
3只有当上面两个步骤中key value都相同时才能任务两个map数据一致
*/
boolean mapEquals = false;
if (taskDelegate.getHeaders().size() == headers.size()) {
int i = 0;
Set<String> keys = taskDelegate.getHeaders().keySet();
for (String key : keys) {
if (headers.containsKey(key)) {
i++;
} else {
break;
}
}
if (i == taskDelegate.getHeaders().size()) {
int j = 0;
Collection<String> values = taskDelegate.getHeaders().values();
for (String value : values) {
if (headers.containsValue(value)) {
j++;
} else {
break;
}
}
if (j == taskDelegate.getHeaders().size()) {
mapEquals = true;
}
}
}
if (!mapEquals) {
taskDelegate.getHeaders().clear();
Set<String> keys = headers.keySet();
for (String key : keys) {
taskDelegate.getHeaders().put(key, headers.get(key));
}
}
}
}

@ -1,457 +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.common;
import com.arialyy.aria.core.config.Configuration;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.m3u8.BaseM3U8Loader;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.DbDataHelper;
import com.arialyy.aria.util.FileUtil;
import com.arialyy.aria.util.RecordUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
/**
* 处理任务记录分配线程区间
*/
public class RecordHandler {
private final String TAG = "RecordHandler";
public static final int TYPE_DOWNLOAD = 1;
public static final int TYPE_UPLOAD = 2;
public static final int TYPE_M3U8_VOD = 3;
public static final int TYPE_M3U8_LIVE = 4;
private static final String STATE = "_state_";
private static final String RECORD = "_record_";
/**
* 小于1m的文件不启用多线程
*/
private static final long SUB_LEN = 1024 * 1024;
/**
* 分块文件路径
*/
public static final String SUB_PATH = "%s.%s.part";
@Deprecated private File mConfigFile;
private TaskRecord mTaskRecord;
private AbsTaskWrapper mTaskWrapper;
private AbsNormalEntity mEntity;
RecordHandler(AbsTaskWrapper wrapper) {
mTaskWrapper = wrapper;
mEntity = (AbsNormalEntity) mTaskWrapper.getEntity();
}
/**
* 获取任务记录如果任务记录存在检查任务记录
* 检查记录 对于分块任务 子分块不存在或被删除子线程将重新下载
* 对于普通任务 预下载文件不存在则任务任务呗删除
* 如果任务记录不存在或线程记录不存在初始化记录
*
* @return 任务记录
*/
TaskRecord getRecord() {
mConfigFile = new File(CommonUtil.getFileConfigPath(false, mEntity.getFileName()));
if (mConfigFile.exists()) {
convertDb();
} else {
mTaskRecord = DbDataHelper.getTaskRecord(getFilePath());
if (mTaskRecord == null) {
initRecord(true);
} else {
if (mTaskRecord.threadRecords == null || mTaskRecord.threadRecords.isEmpty()) {
initRecord(false);
}
if (mTaskWrapper.getRequestType() == ITaskWrapper.M3U8_VOD) {
handleM3U8Record();
} else if (mTaskWrapper.getRequestType() == ITaskWrapper.M3U8_LIVE) {
ALog.i(TAG, "直播下载不处理历史记录");
} else {
if (mTaskRecord.isBlock) {
handleBlockRecord();
} else if (!mTaskWrapper.isSupportBP()) {
handleNoSupportBPRecord();
} else if (!mTaskRecord.isBlock && mTaskRecord.threadNum > 1) {
handleNoBlockMultiThreadRecord();
} else {
handleSingleThreadRecord();
}
}
}
}
saveRecord();
return mTaskRecord;
}
/**
* 处理m3u8记录
* 1如果分片文件存在并且分片文件的记录没有完成则需要删除该分片文件
* 2如果记录显示已完成但是分片文件不存在则重新开始该分片
* 3如果记录显示已完成并且文件存在记录当前任务进度
*/
private void handleM3U8Record() {
DTaskWrapper wrapper = (DTaskWrapper) mTaskWrapper;
String cacheDir = wrapper.asM3U8().getCacheDir();
long currentProgress = 0;
int completeNum = 0;
for (ThreadRecord record : mTaskRecord.threadRecords) {
File temp = new File(BaseM3U8Loader.getTsFilePath(cacheDir, record.threadId));
if (!record.isComplete) {
if (temp.exists()) {
temp.delete();
}
record.startLocation = 0;
//ALog.d(TAG, String.format("分片【%s】未完成,将重新下载该分片", record.threadId));
} else {
if (!temp.exists()) {
record.startLocation = 0;
record.isComplete = false;
ALog.w(TAG, String.format("分片【%s】不存在,将重新下载该分片", record.threadId));
} else {
completeNum++;
currentProgress += temp.length();
}
}
}
wrapper.asM3U8().setCompleteNum(completeNum);
wrapper.getEntity().setCurrentProgress(currentProgress);
mTaskRecord.bandWidth = wrapper.asM3U8().getBandWidth();
}
/**
* 处理不支持断点的记录
*/
private void handleNoSupportBPRecord() {
ThreadRecord tr = mTaskRecord.threadRecords.get(0);
tr.startLocation = 0;
tr.endLocation = mEntity.getFileSize();
tr.taskKey = mTaskRecord.filePath;
tr.blockLen = tr.endLocation;
tr.isComplete = false;
}
/**
* 处理为不分块的多线程任务
*/
private void handleNoBlockMultiThreadRecord() {
File file = new File(mTaskRecord.filePath);
if (!file.exists()) {
ALog.w(TAG, String.format("文件【%s】不存在,重新分配线程区间", mTaskRecord.filePath));
DbEntity.deleteData(ThreadRecord.class, "taskKey=?", mTaskRecord.filePath);
initRecord(false);
}
}
/**
* 处理单线程的任务的记录
*/
private void handleSingleThreadRecord() {
File file = new File(mTaskRecord.filePath);
ThreadRecord tr = mTaskRecord.threadRecords.get(0);
if (!file.exists()) {
ALog.w(TAG, String.format("文件【%s】不存在,任务将重新开始", file.getPath()));
tr.startLocation = 0;
tr.isComplete = false;
tr.endLocation = mEntity.getFileSize();
} else if (mTaskRecord.isOpenDynamicFile) {
if (file.length() > mEntity.getFileSize()) {
ALog.i(TAG, String.format("文件【%s】错误,任务重新开始", file.getPath()));
file.delete();
tr.startLocation = 0;
tr.isComplete = false;
tr.endLocation = mEntity.getFileSize();
} else if (file.length() == mEntity.getFileSize()) {
tr.isComplete = true;
} else {
if (file.length() != tr.startLocation) {
ALog.i(TAG, String.format("修正【%s】的进度记录为:%s", file.getPath(), file.length()));
tr.startLocation = file.length();
tr.isComplete = false;
}
}
}
mTaskWrapper.setNewTask(false);
}
/**
* 处理分块任务的记录分块文件blockFileLen长度必须需要小于等于线程区间threadRectLen的长度
*/
private void handleBlockRecord() {
// 默认线程分块长度
long normalRectLen = mEntity.getFileSize() / mTaskRecord.threadRecords.size();
for (ThreadRecord tr : mTaskRecord.threadRecords) {
long threadRect = tr.blockLen;
File temp = new File(String.format(SUB_PATH, mTaskRecord.filePath, tr.threadId));
if (!temp.exists()) {
ALog.i(TAG, String.format("分块文件【%s】不存在,该分块将重新开始", temp.getPath()));
tr.isComplete = false;
tr.startLocation = tr.threadId * normalRectLen;
} else {
if (!tr.isComplete) {
ALog.i(TAG, String.format(
"startLocation = %s; endLocation = %s; block = %s; tempLen = %s; threadId = %s",
tr.startLocation, tr.endLocation, threadRect, temp.length(), tr.threadId));
long blockFileLen = temp.length(); // 磁盘中的分块文件长度
/*
* 检查磁盘中的分块文件
*/
if (blockFileLen > threadRect) {
ALog.i(TAG, String.format("分块【%s】错误,分块长度【%s】 > 线程区间长度【%s】,将重新开始该分块",
tr.threadId, blockFileLen, threadRect));
temp.delete();
tr.startLocation = tr.threadId * threadRect;
continue;
}
long realLocation =
tr.threadId * normalRectLen + blockFileLen; //正常情况下,该线程的startLocation的位置
/*
* 检查记录文件
*/
if (blockFileLen == threadRect) {
ALog.i(TAG, String.format("分块【%s】已完成,更新记录", temp.getPath()));
tr.startLocation = blockFileLen;
tr.isComplete = true;
} else if (tr.startLocation != realLocation) { // 处理记录小于分块文件长度的情况
ALog.i(TAG, String.format("修正分块【%s】的进度记录为:%s", temp.getPath(), realLocation));
tr.startLocation = realLocation;
}
} else {
ALog.i(TAG, String.format("分块【%s】已完成", temp.getPath()));
}
}
}
mTaskWrapper.setNewTask(false);
}
/**
* convertDb 是兼容性代码 从3.4.1开始线程配置信息将存储在数据库中 将配置文件的内容复制到数据库中并将配置文件删除
*/
private void convertDb() {
List<RecordWrapper> records =
DbEntity.findRelationData(RecordWrapper.class, "TaskRecord.filePath=?",
getFilePath());
if (records == null || records.size() == 0) {
Properties pro = FileUtil.loadConfig(mConfigFile);
if (pro.isEmpty()) {
ALog.d(TAG, "老版本的线程记录为空,任务为新任务");
initRecord(true);
return;
}
Set<Object> keys = pro.keySet();
// 老版本记录是5s存一次,但是5s中内,如果线程执行完成,record记录是没有的,只有state记录...
// 第一步应该是record 和 state去重取正确的线程数
Set<Integer> set = new HashSet<>();
for (Object key : keys) {
String str = String.valueOf(key);
int i = Integer.parseInt(str.substring(str.length() - 1));
set.add(i);
}
int threadNum = set.size();
if (threadNum == 0) {
ALog.d(TAG, "线程数为空,任务为新任务");
initRecord(true);
return;
}
mTaskWrapper.setNewTask(false);
mTaskRecord = createTaskRecord(threadNum);
mTaskRecord.isOpenDynamicFile = false;
mTaskRecord.isBlock = false;
File tempFile = new File(getFilePath());
for (int i = 0; i < threadNum; i++) {
ThreadRecord tRecord = new ThreadRecord();
tRecord.taskKey = mTaskRecord.filePath;
Object state = pro.getProperty(tempFile.getName() + STATE + i);
Object record = pro.getProperty(tempFile.getName() + RECORD + i);
if (state != null && Integer.parseInt(String.valueOf(state)) == 1) {
tRecord.isComplete = true;
continue;
}
if (record != null) {
long temp = Long.parseLong(String.valueOf(record));
tRecord.startLocation = temp > 0 ? temp : 0;
} else {
tRecord.startLocation = 0;
}
mTaskRecord.threadRecords.add(tRecord);
}
mConfigFile.delete();
}
}
/**
* 初始化任务记录分配线程区间
*
* @param newRecord {@code true} 需要创建新{@link TaskRecord}
*/
private void initRecord(boolean newRecord) {
if (newRecord) {
mTaskRecord = createTaskRecord(getNewTaskThreadNum());
}
mTaskWrapper.setNewTask(true);
int requestType = mTaskWrapper.getRequestType();
if (requestType == ITaskWrapper.M3U8_LIVE) {
return;
}
long blockSize = mEntity.getFileSize() / mTaskRecord.threadNum;
// 处理线程区间记录
for (int i = 0; i < mTaskRecord.threadNum; i++) {
long startL = i * blockSize, endL = (i + 1) * blockSize;
ThreadRecord tr;
tr = new ThreadRecord();
tr.taskKey = mTaskRecord.filePath;
tr.threadId = i;
tr.startLocation = startL;
tr.isComplete = false;
if (requestType == ITaskWrapper.M3U8_VOD) {
tr.startLocation = 0;
tr.threadType = TaskRecord.TYPE_M3U8_VOD;
tr.tsUrl = ((DTaskWrapper) mTaskWrapper).asM3U8().getUrls().get(i);
} else {
tr.threadType = TaskRecord.TYPE_HTTP_FTP;
//最后一个线程的结束位置即为文件的总长度
if (i == (mTaskRecord.threadNum - 1)) {
endL = mEntity.getFileSize();
}
tr.endLocation = endL;
tr.blockLen = RecordUtil.getBlockLen(mEntity.getFileSize(), i, mTaskRecord.threadNum);
}
mTaskRecord.threadRecords.add(tr);
}
}
/**
* 创建任务记录
*
* @param threadNum 线程总数
*/
private TaskRecord createTaskRecord(int threadNum) {
TaskRecord record = new TaskRecord();
record.fileName = mEntity.getFileName();
record.filePath = getFilePath();
record.threadRecords = new ArrayList<>();
record.threadNum = threadNum;
int requestType = mTaskWrapper.getRequestType();
if (requestType == ITaskWrapper.M3U8_VOD) {
record.taskType = TaskRecord.TYPE_M3U8_VOD;
record.isOpenDynamicFile = true;
record.bandWidth = ((DTaskWrapper)mTaskWrapper).asM3U8().getBandWidth();
} else if (requestType == ITaskWrapper.M3U8_LIVE) {
record.taskType = TaskRecord.TYPE_M3U8_LIVE;
record.isOpenDynamicFile = true;
record.bandWidth = ((DTaskWrapper)mTaskWrapper).asM3U8().getBandWidth();
} else {
if (getRecordType() == TYPE_DOWNLOAD) {
record.isBlock = threadNum > 1 && Configuration.getInstance().downloadCfg.isUseBlock();
// 线程数为1,或者使用了分块,则认为是使用动态长度文件
record.isOpenDynamicFile = threadNum == 1 || record.isBlock;
} else {
record.isBlock = false;
}
record.taskType = TaskRecord.TYPE_HTTP_FTP;
record.isGroupRecord = mEntity.isGroupChild();
if (record.isGroupRecord) {
if (mEntity instanceof DownloadEntity) {
record.dGroupHash = ((DownloadEntity) mEntity).getGroupHash();
}
}
}
return record;
}
/**
* 保存任务记录
*/
private void saveRecord() {
mTaskRecord.threadNum = mTaskRecord.threadRecords.size();
mTaskRecord.save();
if (mTaskRecord.threadRecords != null && !mTaskRecord.threadRecords.isEmpty()) {
DbEntity.saveAll(mTaskRecord.threadRecords);
}
ALog.d(TAG, String.format("保存记录,线程记录数:%s", mTaskRecord.threadRecords.size()));
}
/**
* 获取记录类型
*
* @return {@link #TYPE_DOWNLOAD}{@link #TYPE_UPLOAD}
*/
private int getRecordType() {
if (mEntity instanceof DownloadEntity) {
return TYPE_DOWNLOAD;
} else {
return TYPE_UPLOAD;
}
}
/**
* 获取任务路径
*
* @return 任务文件路径
*/
private String getFilePath() {
if (mEntity instanceof DownloadEntity) {
return ((DownloadEntity) mTaskWrapper.getEntity()).getFilePath();
} else {
return ((UploadEntity) mTaskWrapper.getEntity()).getFilePath();
}
}
/**
* 小于1m的文件或是任务组的子任务线程数强制为1
* 不支持断点或chunked模式的线程数都为线程数强制为1
*/
private int getNewTaskThreadNum() {
if (getRecordType() == TYPE_DOWNLOAD) {
if (mTaskWrapper.getRequestType() == ITaskWrapper.M3U8_VOD) {
return ((DTaskWrapper) mTaskWrapper).asM3U8().getUrls().size();
}
if (mTaskWrapper.getRequestType() == ITaskWrapper.M3U8_LIVE) {
return 1;
}
if (!mTaskWrapper.isSupportBP() || mTaskWrapper.asHttp().isChunked()) {
return 1;
}
int threadNum = Configuration.getInstance().downloadCfg.getThreadNum();
return mEntity.getFileSize() <= SUB_LEN
|| mEntity.isGroupChild()
|| threadNum == 1
? 1
: threadNum;
} else {
return 1;
}
}
}

@ -17,8 +17,8 @@ package com.arialyy.aria.core.common.controller;
import com.arialyy.aria.core.command.NormalCmdFactory;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.command.CmdHelper;
/**
* 创建任务时使用的控制器
@ -37,7 +37,7 @@ public final class BuilderController extends FeatureController implements IStart
public long add() {
if (checkConfig()) {
EventMsgUtil.getDefault()
.post(CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_CREATE,
.post(CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_CREATE,
checkTaskType()));
return getEntity().getId();
}
@ -52,7 +52,7 @@ public final class BuilderController extends FeatureController implements IStart
public long create() {
if (checkConfig()) {
EventMsgUtil.getDefault()
.post(CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_START,
.post(CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_START,
checkTaskType()));
return getEntity().getId();
}
@ -63,7 +63,7 @@ public final class BuilderController extends FeatureController implements IStart
@Override public long setHighestPriority() {
if (checkConfig()) {
EventMsgUtil.getDefault()
.post(CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_HIGHEST_PRIORITY,
.post(CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_HIGHEST_PRIORITY,
checkTaskType()));
return getEntity().getId();
}

@ -25,12 +25,12 @@ import com.arialyy.aria.core.download.CheckDGEntityUtil;
import com.arialyy.aria.core.download.CheckFtpDirEntityUtil;
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.AbsTaskWrapper;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.ICheckEntityUtil;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.core.listener.ISchedulers;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.core.upload.CheckUEntityUtil;
import com.arialyy.aria.core.upload.UTaskWrapper;

@ -18,9 +18,9 @@ package com.arialyy.aria.core.common.controller;
import com.arialyy.aria.core.command.CancelCmd;
import com.arialyy.aria.core.command.NormalCmdFactory;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.core.command.CmdHelper;
/**
* 启动控制器
@ -39,7 +39,7 @@ public final class NormalController extends FeatureController implements INormal
public void stop() {
if (checkConfig()) {
EventMsgUtil.getDefault()
.post(CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_STOP,
.post(CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_STOP,
checkTaskType()));
}
}
@ -51,7 +51,7 @@ public final class NormalController extends FeatureController implements INormal
public void resume() {
if (checkConfig()) {
EventMsgUtil.getDefault()
.post(CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_START,
.post(CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_START,
checkTaskType()));
}
}
@ -63,7 +63,7 @@ public final class NormalController extends FeatureController implements INormal
public void cancel() {
if (checkConfig()) {
EventMsgUtil.getDefault()
.post(CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_CANCEL,
.post(CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_CANCEL,
checkTaskType()));
}
}
@ -76,10 +76,10 @@ public final class NormalController extends FeatureController implements INormal
if (checkConfig()) {
int taskType = checkTaskType();
EventMsgUtil.getDefault()
.post(CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_STOP, taskType));
.post(CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_STOP, taskType));
EventMsgUtil.getDefault()
.post(
CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_START, taskType));
CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_START, taskType));
}
}
@ -93,7 +93,7 @@ public final class NormalController extends FeatureController implements INormal
public void cancel(boolean removeFile) {
if (checkConfig()) {
CancelCmd cancelCmd =
(CancelCmd) CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_CANCEL,
(CancelCmd) CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_CANCEL,
checkTaskType());
cancelCmd.removeFile = removeFile;
EventMsgUtil.getDefault().post(cancelCmd);
@ -107,7 +107,7 @@ public final class NormalController extends FeatureController implements INormal
public void reStart() {
if (checkConfig()) {
EventMsgUtil.getDefault()
.post(CommonUtil.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_RESTART,
.post(CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_RESTART,
checkTaskType()));
}
}

@ -16,11 +16,11 @@
package com.arialyy.aria.core.download;
import android.text.TextUtils;
import com.arialyy.aria.core.common.RecordHandler;
import com.arialyy.aria.core.download.m3u8.M3U8Entity;
import com.arialyy.aria.core.inf.ICheckEntityUtil;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.inf.IRecordHandler;
import com.arialyy.aria.core.inf.ITargetHandler;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
@ -64,20 +64,24 @@ public class CheckDEntityUtil implements ICheckEntityUtil {
private void handleM3U8() {
File file = new File(mWrapper.getTempFilePath());
int bandWidth = (int) mWrapper.getM3U8Params().getParam(IOptionConstant.bandWidth);
// 缓存文件夹格式:问文件夹/.文件名_码率
String cacheDir = String.format("%s/.%s_%s", file.getParent(), file.getName(),
mWrapper.asM3U8().getBandWidth());
mWrapper.asM3U8().setCacheDir(cacheDir);
String cacheDir = String.format("%s/.%s_%s", file.getParent(), file.getName(), bandWidth);
mWrapper.getM3U8Params().setParams(IOptionConstant.cacheDir, cacheDir);
M3U8Entity m3U8Entity = mEntity.getM3U8Entity();
Object temp = mWrapper.getM3U8Params().getParam(IOptionConstant.generateIndexFileTemp);
boolean generateIndexFileTemp = temp != null && (boolean) temp;
if (m3U8Entity == null) {
m3U8Entity = new M3U8Entity();
m3U8Entity.setFilePath(mEntity.getFilePath());
m3U8Entity.setPeerIndex(0);
m3U8Entity.setCacheDir(cacheDir);
m3U8Entity.setGenerateIndexFile(mWrapper.asM3U8().isGenerateIndexFileTemp());
m3U8Entity.setGenerateIndexFile(generateIndexFileTemp);
m3U8Entity.insert();
} else {
m3U8Entity.setGenerateIndexFile(mWrapper.asM3U8().isGenerateIndexFileTemp());
m3U8Entity.setGenerateIndexFile(generateIndexFileTemp);
m3U8Entity.update();
}
if (mWrapper.getRequestType() == ITaskWrapper.M3U8_VOD) {
@ -92,8 +96,8 @@ public class CheckDEntityUtil implements ICheckEntityUtil {
}
}
if (mWrapper.asM3U8().getBandWidthUrlConverter() != null
&& mWrapper.asM3U8().getBandWidth() == 0) {
if (mWrapper.getM3U8Params().getHandler(IOptionConstant.bandWidthUrlConverter) != null
&& bandWidth == 0) {
ALog.w(TAG, "你已经设置了码率url转换器,但是没有设置码率,Aria框架将采用第一个获取到的码率");
}
}
@ -140,7 +144,7 @@ public class CheckDEntityUtil implements ICheckEntityUtil {
return false;
} else {
ALog.w(TAG, String.format("保存路径【%s】已经被其它任务占用,当前任务将覆盖该路径的文件", filePath));
RecordUtil.delTaskRecord(filePath, RecordHandler.TYPE_DOWNLOAD);
RecordUtil.delTaskRecord(filePath, IRecordHandler.TYPE_DOWNLOAD);
}
}
@ -149,7 +153,7 @@ public class CheckDEntityUtil implements ICheckEntityUtil {
mEntity.setFileName(newFile.getName());
// 如过使用Content-Disposition中的文件名,将不会执行重命名工作
if (mWrapper.asHttp().isUseServerFileName()
if ((boolean) mWrapper.getOptionParams().getParam(IOptionConstant.useServerFileName)
|| mWrapper.getRequestType() == ITaskWrapper.M3U8_LIVE) {
return true;
}

@ -18,6 +18,7 @@ package com.arialyy.aria.core.download;
import android.text.TextUtils;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.inf.ICheckEntityUtil;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
@ -133,9 +134,10 @@ public class CheckDGEntityUtil implements ICheckEntityUtil {
return false;
}
if (mWrapper.asHttp().getRequestEnum() == RequestEnum.POST) {
for (DTaskWrapper subTask : mWrapper.getSubTaskWrapper()) {
subTask.asHttp().setRequestEnum(RequestEnum.POST);
if (mWrapper.getOptionParams().getParam(IOptionConstant.requestEnum)
== RequestEnum.POST) {
for (DTaskWrapper subWrapper : mWrapper.getSubTaskWrapper()) {
subWrapper.getOptionParams().setParams(IOptionConstant.requestEnum, RequestEnum.POST);
}
}

@ -16,7 +16,9 @@
package com.arialyy.aria.core.download;
import android.text.TextUtils;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.inf.ICheckEntityUtil;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import java.io.File;
@ -83,12 +85,15 @@ public class CheckFtpDirEntityUtil implements ICheckEntityUtil {
if (b) {
mEntity.save();
}
if (mWrapper.asFtp().getUrlEntity().isFtps) {
if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().storePath)) {
FtpUrlEntity urlEntity =
(FtpUrlEntity) mWrapper.getOptionParams().getParam(IOptionConstant.ftpUrlEntity);
assert urlEntity != null;
if (urlEntity.isFtps) {
if (TextUtils.isEmpty(urlEntity.storePath)) {
ALog.e(TAG, "证书路径为空");
return false;
}
if (TextUtils.isEmpty(mWrapper.asFtp().getUrlEntity().keyAlias)) {
if (TextUtils.isEmpty(urlEntity.keyAlias)) {
ALog.e(TAG, "证书别名为空");
return false;
}

@ -33,15 +33,17 @@ import com.arialyy.aria.core.download.target.GroupNormalTarget;
import com.arialyy.aria.core.download.target.HttpBuilderTarget;
import com.arialyy.aria.core.download.target.HttpNormalTarget;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.inf.ReceiverType;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.core.command.CmdHelper;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ComponentUtil;
import com.arialyy.aria.util.DbDataHelper;
import java.util.ArrayList;
import java.util.List;
@ -73,6 +75,7 @@ public class DownloadReceiver extends AbsReceiver {
*/
@CheckResult
public HttpBuilderTarget load(@NonNull String url) {
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_HTTP);
CheckUtil.checkUrlInvalidThrow(url);
return DTargetFactory.getInstance()
.generateBuilderTarget(HttpBuilderTarget.class, url);
@ -86,6 +89,7 @@ public class DownloadReceiver extends AbsReceiver {
*/
@CheckResult
public HttpNormalTarget load(long taskId) {
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_HTTP);
CheckUtil.checkTaskId(taskId);
return DTargetFactory.getInstance()
.generateNormalTarget(HttpNormalTarget.class, taskId);
@ -98,6 +102,7 @@ public class DownloadReceiver extends AbsReceiver {
*/
@CheckResult
public GroupBuilderTarget loadGroup(List<String> urls) {
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_HTTP);
CheckUtil.checkDownloadUrls(urls);
return DTargetFactory.getInstance().generateGroupBuilderTarget(urls);
}
@ -110,6 +115,7 @@ public class DownloadReceiver extends AbsReceiver {
*/
@CheckResult
public GroupNormalTarget loadGroup(long taskId) {
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_HTTP);
CheckUtil.checkTaskId(taskId);
return DTargetFactory.getInstance()
.generateNormalTarget(GroupNormalTarget.class, taskId);
@ -120,6 +126,7 @@ public class DownloadReceiver extends AbsReceiver {
*/
@CheckResult
public FtpBuilderTarget loadFtp(@NonNull String url) {
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_FTP);
CheckUtil.checkUrlInvalidThrow(url);
return DTargetFactory.getInstance()
.generateBuilderTarget(FtpBuilderTarget.class, url);
@ -133,6 +140,7 @@ public class DownloadReceiver extends AbsReceiver {
*/
@CheckResult
public FtpNormalTarget loadFtp(long taskId) {
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_FTP);
CheckUtil.checkTaskId(taskId);
return DTargetFactory.getInstance()
.generateNormalTarget(FtpNormalTarget.class, taskId);
@ -143,6 +151,7 @@ public class DownloadReceiver extends AbsReceiver {
*/
@CheckResult
public FtpDirBuilderTarget loadFtpDir(@NonNull String dirUrl) {
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_FTP);
CheckUtil.checkUrlInvalidThrow(dirUrl);
return DTargetFactory.getInstance().generateDirBuilderTarget(dirUrl);
}
@ -155,6 +164,7 @@ public class DownloadReceiver extends AbsReceiver {
*/
@CheckResult
public FtpDirNormalTarget loadFtpDir(long taskId) {
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_FTP);
CheckUtil.checkTaskId(taskId);
return DTargetFactory.getInstance()
.generateNormalTarget(FtpDirNormalTarget.class, taskId);
@ -461,7 +471,7 @@ public class DownloadReceiver extends AbsReceiver {
public void removeAllTask(boolean removeFile) {
final AriaManager ariaManager = AriaManager.getInstance();
CancelAllCmd cancelCmd =
(CancelAllCmd) CommonUtil.createNormalCmd(new DTaskWrapper(null),
(CancelAllCmd) CmdHelper.createNormalCmd(new DTaskWrapper(null),
NormalCmdFactory.TASK_CANCEL_ALL, ITask.DOWNLOAD);
cancelCmd.removeFile = removeFile;
EventMsgUtil.getDefault().post(cancelCmd);

@ -1,129 +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.download.downloader;
import com.arialyy.aria.core.common.AbsThreadTask;
import com.arialyy.aria.core.common.NormalFileer;
import com.arialyy.aria.core.common.RecordHandler;
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.event.Event;
import com.arialyy.aria.core.event.SpeedEvent;
import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.BufferedRandomAccessFile;
import java.io.File;
import java.io.IOException;
/**
* Created by AriaL on 2017/7/1. 文件下载器
*/
public class Downloader extends NormalFileer<DownloadEntity, DTaskWrapper> {
private String TAG = "Downloader";
public Downloader(IDownloadListener listener, DTaskWrapper taskWrapper) {
super(listener, taskWrapper);
mTempFile = new File(mEntity.getFilePath());
setUpdateInterval(taskWrapper.getConfig().getUpdateInterval());
}
@Override protected boolean handleNewTask() {
if (!mRecord.isBlock) {
if (mTempFile.exists()) {
mTempFile.delete();
}
//CommonUtil.createFile(mTempFile.getPath());
} else {
for (int i = 0; i < mTotalThreadNum; i++) {
File blockFile = new File(String.format(RecordHandler.SUB_PATH, mTempFile.getPath(), i));
if (blockFile.exists()) {
ALog.d(TAG, String.format("分块【%s】已经存在,将删除该分块", i));
blockFile.delete();
}
}
}
BufferedRandomAccessFile file = null;
try {
if (mTotalThreadNum > 1 && !mRecord.isBlock) {
file = new BufferedRandomAccessFile(new File(mTempFile.getPath()), "rwd", 8192);
//设置文件长度
file.setLength(mEntity.getFileSize());
}
return true;
} catch (IOException e) {
failDownload(new TaskException(TAG,
String.format("下载失败,filePath: %s, url: %s", mEntity.getDownloadPath(),
mEntity.getUrl()), e));
} finally {
if (file != null) {
try {
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return false;
}
/**
* 如果使用"Content-Disposition"中的文件名需要更新{@link #mTempFile}的路径
*/
void updateTempFile() {
if (!mTempFile.getPath().equals(mEntity.getFilePath())) {
if (!mTempFile.exists()) {
mTempFile = new File(mEntity.getFilePath());
} else {
boolean b = mTempFile.renameTo(new File(mEntity.getDownloadPath()));
ALog.d(TAG, String.format("更新tempFile文件名%s", b ? "成功" : "失败"));
}
}
}
@Event
public void setMaxSpeed(SpeedEvent event) {
setMaxSpeed(event.speed);
}
@Override protected void onPostPre() {
super.onPostPre();
((IDownloadListener) mListener).onPostPre(mEntity.getFileSize());
File file = new File(mEntity.getDownloadPath());
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
}
@Override protected AbsThreadTask selectThreadTask(SubThreadConfig<DTaskWrapper> config) {
switch (mTaskWrapper.getRequestType()) {
case ITaskWrapper.D_FTP:
case ITaskWrapper.D_FTP_DIR:
return new FtpThreadTask(config);
case ITaskWrapper.D_HTTP:
return new HttpThreadTask(config);
}
return null;
}
private void failDownload(BaseException e) {
closeTimer();
mListener.onFail(false, e);
}
}

@ -1,140 +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.download.downloader;
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.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.exception.BaseException;
/**
* Created by lyy on 2015/8/25.
* D_HTTP\FTP单任务下载工具
*/
public class SimpleDownloadUtil implements IUtil {
private String TAG = "SimpleDownloadUtil";
private IDownloadListener mListener;
private Downloader mDownloader;
private DTaskWrapper mTaskWrapper;
private boolean isStop = false, isCancel = false;
public SimpleDownloadUtil(DTaskWrapper wrapper, IDownloadListener downloadListener) {
mTaskWrapper = wrapper;
mListener = downloadListener;
mDownloader = new Downloader(downloadListener, wrapper);
}
@Override public String getKey() {
return mTaskWrapper.getKey();
}
@Override public long getFileSize() {
return mDownloader.getFileSize();
}
/**
* 获取当前下载位置
*/
@Override public long getCurrentLocation() {
return mDownloader.getCurrentLocation();
}
@Override public boolean isRunning() {
return mDownloader.isRunning();
}
/**
* 取消下载
*/
@Override public void cancel() {
isCancel = true;
mDownloader.cancel();
}
/**
* 停止下载
*/
@Override public void stop() {
isStop = true;
mDownloader.stop();
}
/**
* 多线程断点续传下载文件开始下载
*/
@Override public void start() {
if (isStop || isCancel) {
return;
}
mListener.onPre();
// 如果网址没有变,而服务器端端文件改变,以下代码就没有用了
//if (mTaskWrapper.getEntity().getFileSize() <= 1
// || mTaskWrapper.isRefreshInfo()
// || mTaskWrapper.getRequestType() == AbsTaskWrapper.D_FTP
// || mTaskWrapper.getState() == IEntity.STATE_FAIL) {
// new Thread(createInfoThread()).create();
//} else {
// mDownloader.create();
//}
new Thread(createInfoThread()).start();
}
private void failDownload(BaseException e, boolean needRetry) {
if (isStop || isCancel) {
return;
}
mListener.onFail(needRetry, e);
mDownloader.onDestroy();
}
/**
* 通过链接类型创建不同的获取文件信息的线程
*/
private Runnable createInfoThread() {
switch (mTaskWrapper.getRequestType()) {
case ITaskWrapper.D_FTP:
return new FtpFileInfoThread(mTaskWrapper, new OnFileInfoCallback() {
@Override public void onComplete(String url, CompleteInfo info) {
mDownloader.updateTempFile();
mDownloader.start();
}
@Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) {
failDownload(e, needRetry);
mDownloader.closeTimer();
}
});
case ITaskWrapper.D_HTTP:
return new HttpFileInfoThread(mTaskWrapper, new OnFileInfoCallback() {
@Override public void onComplete(String url, CompleteInfo info) {
mDownloader.updateTempFile();
mDownloader.start();
}
@Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) {
failDownload(e, needRetry);
mDownloader.closeTimer();
}
});
}
return null;
}
}

@ -1,133 +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.download.group;
import android.os.Handler;
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.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.downloader.Downloader;
import com.arialyy.aria.core.download.downloader.HttpFileInfoThread;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog;
/**
* 子任务下载器负责创建{@link Downloader}
*/
class SubDLoadUtil implements IUtil {
private final String TAG = "SubDownloadLoader";
private Downloader mDownloader;
private DTaskWrapper mWrapper;
private Handler mSchedulers;
private ChildDLoadListener mListener;
private boolean needGetInfo;
/**
* @param schedulers 调度器
* @param needGetInfo {@code true} 需要获取文件信息{@code false} 不需要获取文件信息
*/
SubDLoadUtil(Handler schedulers, DTaskWrapper taskWrapper, boolean needGetInfo) {
mWrapper = taskWrapper;
mSchedulers = schedulers;
this.needGetInfo = needGetInfo;
mListener = new ChildDLoadListener(mSchedulers, SubDLoadUtil.this);
}
@Override public String getKey() {
return mWrapper.getKey();
}
public DTaskWrapper getWrapper() {
return mWrapper;
}
public DownloadEntity getEntity() {
return mWrapper.getEntity();
}
/**
* 重新开始任务
*/
void reStart() {
if (mDownloader != null) {
mDownloader.retryTask();
}
}
public Downloader getDownloader() {
return mDownloader;
}
@Override public long getFileSize() {
return mDownloader == null ? -1 : mDownloader.getFileSize();
}
@Override public long getCurrentLocation() {
return mDownloader == null ? -1 : mDownloader.getCurrentLocation();
}
@Override public boolean isRunning() {
return mDownloader != null && mDownloader.isRunning();
}
@Override public void cancel() {
if (mDownloader != null && isRunning()) {
mDownloader.cancel();
} else {
mSchedulers.obtainMessage(ISchedulers.CANCEL, this).sendToTarget();
}
}
@Override public void stop() {
if (mDownloader != null && isRunning()) {
mDownloader.stop();
} else {
mSchedulers.obtainMessage(ISchedulers.STOP, this).sendToTarget();
}
}
@Override public void start() {
if (mWrapper.getRequestType() == ITaskWrapper.D_HTTP) {
if (needGetInfo) {
new Thread(new HttpFileInfoThread(mWrapper, new OnFileInfoCallback() {
@Override public void onComplete(String url, CompleteInfo info) {
mDownloader = new Downloader(mListener, mWrapper);
mDownloader.start();
}
@Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) {
mSchedulers.obtainMessage(ISchedulers.FAIL, SubDLoadUtil.this).sendToTarget();
}
})).start();
} else {
mDownloader = new Downloader(mListener, mWrapper);
mDownloader.start();
}
} else if (mWrapper.getRequestType() == ITaskWrapper.D_FTP) {
mDownloader = new Downloader(mListener, mWrapper);
mDownloader.start();
} else {
ALog.w(TAG, String.format("不识别的类型,requestType:%s", mWrapper.getRequestType()));
}
}
}

@ -17,10 +17,15 @@ package com.arialyy.aria.core.download.m3u8;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseDelegate;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.processor.IBandWidthUrlConverter;
import com.arialyy.aria.core.processor.ITsMergeHandler;
import com.arialyy.aria.core.processor.IVodTsUrlConverter;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ComponentUtil;
/**
* m3u8 委托
@ -30,6 +35,7 @@ public class M3U8Delegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
public M3U8Delegate(TARGET target, AbsTaskWrapper wrapper) {
super(target, wrapper);
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_M3U8);
mTaskWrapper = (DTaskWrapper) getTaskWrapper();
mTaskWrapper.setRequestType(AbsTaskWrapper.M3U8_VOD);
}
@ -40,7 +46,7 @@ public class M3U8Delegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> generateIndexFile() {
mTaskWrapper.asM3U8().setGenerateIndexFileTemp(true);
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.generateIndexFileTemp, true);
return this;
}
@ -51,7 +57,7 @@ public class M3U8Delegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> merge(boolean merge) {
mTaskWrapper.asM3U8().setMergeFile(merge);
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.mergeFile, merge);
return this;
}
@ -61,7 +67,7 @@ public class M3U8Delegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> setMergeHandler(ITsMergeHandler handler) {
mTaskWrapper.asM3U8().setMergeHandler(handler);
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.mergeHandler, handler);
return this;
}
@ -73,7 +79,7 @@ public class M3U8Delegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> setTsUrlConvert(IVodTsUrlConverter converter) {
mTaskWrapper.asM3U8().setVodUrlConverter(converter);
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.vodUrlConverter, converter);
return this;
}
@ -84,7 +90,7 @@ public class M3U8Delegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> setBandWidth(int bandWidth) {
mTaskWrapper.asM3U8().setBandWidth(bandWidth);
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.bandWidth, bandWidth);
return this;
}
@ -96,7 +102,7 @@ public class M3U8Delegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> setBandWidthUrlConverter(IBandWidthUrlConverter converter) {
mTaskWrapper.asM3U8().setBandWidthUrlConverter(converter);
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.bandWidthUrlConverter, converter);
return this;
}

@ -17,10 +17,12 @@ package com.arialyy.aria.core.download.m3u8;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseDelegate;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.processor.ILiveTsUrlConverter;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.util.ALog;
/**
@ -41,7 +43,8 @@ public class M3U8LiveDelegate<TARGET extends AbsTarget> extends BaseDelegate<TAR
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8LiveDelegate<TARGET> setLiveTsUrlConvert(ILiveTsUrlConverter converter) {
((DTaskWrapper) getTaskWrapper()).asM3U8().setLiveTsUrlConverter(converter);
((DTaskWrapper) getTaskWrapper()).getM3U8Params()
.setParams(IOptionConstant.liveTsUrlConverter, converter);
return this;
}
@ -56,7 +59,8 @@ public class M3U8LiveDelegate<TARGET extends AbsTarget> extends BaseDelegate<TAR
ALog.e(TAG, "间隔时间错误");
return this;
}
((DTaskWrapper) getTaskWrapper()).asM3U8().setLiveUpdateInterval(interval);
((DTaskWrapper) getTaskWrapper()).getM3U8Params()
.setParams(IOptionConstant.liveUpdateInterval, interval);
return this;
}
}

@ -17,13 +17,14 @@ package com.arialyy.aria.core.download.m3u8;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseDelegate;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.event.PeerIndexEvent;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.queue.DTaskQueue;
import com.arialyy.aria.util.ALog;
/**
@ -64,7 +65,7 @@ public class M3U8VodDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARG
ALog.e(TAG, "同时下载的分片数量不能小于1");
return this;
}
mTaskWrapper.asM3U8().setMaxTsQueueNum(num);
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.maxTsQueueNum, num);
return this;
}
@ -84,7 +85,7 @@ public class M3U8VodDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARG
ALog.e(TAG, "切片索引不能小于1");
return this;
}
mTaskWrapper.asM3U8().setJumpIndex(index);
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.jumpIndex, index);
return this;
}
@ -103,7 +104,7 @@ public class M3U8VodDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARG
return;
}
if (!DownloadTaskQueue.getInstance().taskIsRunning(mTaskWrapper.getKey())) {
if (!DTaskQueue.getInstance().taskIsRunning(mTaskWrapper.getKey())) {
ALog.e(TAG,
String.format("任务【%s】没有运行,如果你希望在启动任务时初始化索引位置,请调用setPeerIndex(xxx)",
mTaskWrapper.getKey()));

@ -1,145 +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.download.m3u8;
import android.text.TextUtils;
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.DTaskWrapper;
import com.arialyy.aria.core.download.M3U8Listener;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.M3U8Exception;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* M3U8点播文件下载工具
* 工作流程
* 1创建一个和文件同父路径并且同名隐藏文件夹
* 2将所有m3u8的ts文件下载到该文件夹中
* 3完成所有分片下载后合并ts文件
* 4删除该隐藏文件夹
*/
public class M3U8VodUtil implements IUtil {
private final String TAG = "M3U8DownloadUtil";
private DTaskWrapper mWrapper;
private M3U8Listener mListener;
private boolean isStop = false, isCancel = false;
private List<String> mUrls = new ArrayList<>();
private M3U8VodLoader mLoader;
public M3U8VodUtil(DTaskWrapper wrapper, M3U8Listener listener) {
mWrapper = wrapper;
mListener = listener;
mLoader = new M3U8VodLoader(mListener, mWrapper);
}
@Override public String getKey() {
return mWrapper.getKey();
}
@Override public long getFileSize() {
return 0;
}
@Override public long getCurrentLocation() {
return 0;
}
@Override public boolean isRunning() {
return mLoader.isRunning();
}
@Override public void cancel() {
isCancel = true;
mLoader.cancel();
}
@Override public void stop() {
isStop = true;
mLoader.stop();
}
@Override public void start() {
if (isStop || isCancel) {
return;
}
mListener.onPre();
// peer数量小于0,
M3U8Entity m3U8Entity = mWrapper.getEntity().getM3U8Entity();
if (m3U8Entity.getPeerNum() <= 0 || (m3U8Entity.isGenerateIndexFile() && !new File(
String.format(M3U8InfoThread.M3U8_INDEX_FORMAT,
mWrapper.getEntity().getFilePath())).exists())) {
getVodInfo();
} else {
mLoader.start();
}
}
/**
* 获取点播文件信息
*/
private void getVodInfo() {
M3U8InfoThread thread = new M3U8InfoThread(mWrapper, new OnFileInfoCallback() {
@Override public void onComplete(String key, CompleteInfo info) {
IVodTsUrlConverter converter = mWrapper.asM3U8().getVodUrlConverter();
if (converter != null) {
if (TextUtils.isEmpty(mWrapper.asM3U8().getBandWidthUrl())) {
mUrls.addAll(converter.convert(mWrapper.getEntity().getUrl(), (List<String>) info.obj));
} else {
mUrls.addAll(
converter.convert(mWrapper.asM3U8().getBandWidthUrl(), (List<String>) info.obj));
}
} else {
mUrls.addAll((Collection<? extends String>) info.obj);
}
if (mUrls.isEmpty()) {
failDownload(new M3U8Exception(TAG, "获取地址失败"), false);
return;
} else if (!mUrls.get(0).startsWith("http")) {
failDownload(new M3U8Exception(TAG, "地址错误,请使用IM3U8UrlExtInfHandler处理你的url信息"), false);
return;
}
mWrapper.asM3U8().setUrls(mUrls);
if (isStop) {
mListener.onStop(mWrapper.getEntity().getCurrentProgress());
} else if (isCancel) {
mListener.onCancel();
} else {
mLoader.start();
}
}
@Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) {
failDownload(e, needRetry);
}
});
new Thread(thread).start();
}
private void failDownload(BaseException e, boolean needRetry) {
if (isStop || isCancel) {
return;
}
mListener.onFail(needRetry, e);
mLoader.onDestroy();
}
}

@ -19,13 +19,13 @@ import android.text.TextUtils;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.event.ErrorEvent;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IConfigHandler;
import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DGroupTaskQueue;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil;
@ -77,7 +77,7 @@ abstract class AbsGroupConfigHandler<TARGET extends AbsTarget> implements IConfi
}
@Override public boolean isRunning() {
DownloadGroupTask task = DownloadGroupTaskQueue.getInstance().getTask(getEntity().getKey());
DownloadGroupTask task = DGroupTaskQueue.getInstance().getTask(getEntity().getKey());
return task != null && task.isRunning();
}

@ -22,7 +22,7 @@ import com.arialyy.aria.core.event.ErrorEvent;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IConfigHandler;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.DTaskQueue;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
@ -83,7 +83,7 @@ class DNormalConfigHandler<TARGET extends AbsTarget> implements IConfigHandler {
}
@Override public boolean isRunning() {
return DownloadTaskQueue.getInstance().taskIsRunning(mEntity.getKey());
return DTaskQueue.getInstance().taskIsRunning(mEntity.getKey());
}
void setForceDownload(boolean forceDownload) {

@ -18,10 +18,11 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.FtpDelegate;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.CommonUtil;
/**
@ -33,7 +34,8 @@ public class FtpBuilderTarget extends AbsBuilderTarget<FtpBuilderTarget> {
FtpBuilderTarget(String url) {
mConfigHandler = new DNormalConfigHandler<>(this, -1);
mConfigHandler.setUrl(url);
getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(url));
getTaskWrapper().getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(url));
getTaskWrapper().setRequestType(ITaskWrapper.D_FTP);
}

@ -17,9 +17,10 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.FtpDelegate;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.util.CommonUtil;
@ -33,7 +34,8 @@ public class FtpDirBuilderTarget extends AbsBuilderTarget<FtpDirBuilderTarget> {
FtpDirBuilderTarget(String url) {
mConfigHandler = new FtpDirConfigHandler<>(this, -1);
getEntity().setGroupHash(url);
getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(url));
getTaskWrapper().getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(url));
}
/**

@ -16,10 +16,9 @@
package com.arialyy.aria.core.download.target;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.target.AbsGroupConfigHandler;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import java.util.List;
/**

@ -17,9 +17,10 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.FtpDelegate;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.util.CommonUtil;
@ -32,7 +33,8 @@ public class FtpDirNormalTarget extends AbsNormalTarget<FtpDirNormalTarget> {
FtpDirNormalTarget(long taskId) {
mConfigHandler = new FtpDirConfigHandler<>(this, taskId);
getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getKey()));
getTaskWrapper().getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(getEntity().getKey()));
}
@Override public boolean isRunning() {

@ -18,10 +18,11 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.FtpDelegate;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.CommonUtil;
/**
@ -33,7 +34,8 @@ public class FtpNormalTarget extends AbsNormalTarget<FtpNormalTarget> {
FtpNormalTarget(long taskId) {
mConfigHandler = new DNormalConfigHandler<>(this, taskId);
getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getUrl()));
getTaskWrapper().getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(getEntity().getUrl()));
getTaskWrapper().setRequestType(ITaskWrapper.D_FTP);
}

@ -17,12 +17,13 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.http.HttpDelegate;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.HttpDelegate;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.inf.IHttpFileLenAdapter;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.processor.IHttpFileLenAdapter;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.ALog;
import java.util.List;
@ -150,7 +151,7 @@ public class GroupBuilderTarget extends AbsBuilderTarget<GroupBuilderTarget> {
if (adapter == null) {
throw new IllegalArgumentException("adapter为空");
}
getTaskWrapper().asHttp().setFileLenAdapter(adapter);
getTaskWrapper().getOptionParams().setObjs(IOptionConstant.fileLenAdapter, adapter);
return this;
}
}

@ -17,9 +17,9 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.http.HttpDelegate;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.HttpDelegate;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.core.manager.SubTaskManager;
import java.util.List;

@ -18,11 +18,12 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.http.HttpDelegate;
import com.arialyy.aria.core.common.HttpDelegate;
import com.arialyy.aria.core.download.m3u8.M3U8Delegate;
import com.arialyy.aria.core.inf.IHttpFileLenAdapter;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.processor.IHttpFileLenAdapter;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
public class HttpBuilderTarget extends AbsBuilderTarget<HttpBuilderTarget> {
@ -54,7 +55,7 @@ public class HttpBuilderTarget extends AbsBuilderTarget<HttpBuilderTarget> {
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpBuilderTarget useServerFileName(boolean use) {
getTaskWrapper().asHttp().setUseServerFileName(use);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.useServerFileName, use);
return this;
}
@ -94,7 +95,8 @@ public class HttpBuilderTarget extends AbsBuilderTarget<HttpBuilderTarget> {
if (adapter == null) {
throw new IllegalArgumentException("adapter为空");
}
getTaskWrapper().asHttp().setFileLenAdapter(adapter);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.fileLenAdapter, adapter);
return this;
}
}

@ -18,7 +18,6 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.target.AbsGroupConfigHandler;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;

@ -17,8 +17,8 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.http.HttpDelegate;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.HttpDelegate;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.m3u8.M3U8Delegate;

@ -18,9 +18,9 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.download.tcp.TcpDelegate;
import com.arialyy.aria.core.inf.ITaskWrapper;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
/**
* @Author aria

@ -18,10 +18,9 @@ package com.arialyy.aria.core.download.tcp;
import android.text.TextUtils;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseDelegate;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ALog;
import java.nio.charset.Charset;
@ -36,7 +35,7 @@ public class TcpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET>
public TcpDelegate(TARGET target, AbsTaskWrapper wrapper) {
super(target, wrapper);
mTcpConfig = ((DTaskWrapper) wrapper).asTcp();
mTcpConfig = (TcpTaskConfig) wrapper.getTaskOption();
}
/**

@ -1,36 +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/6/3.
*/
public abstract class AbsNormalTask<TASK_WRAPPER extends AbsTaskWrapper>
extends AbsTask<TASK_WRAPPER> {
/**
* 最高优先级命令最高优先级命令有以下属性
* 1在下载队列中有且只有一个最高优先级任务
* 2最高优先级任务会一直存在直到用户手动暂停或任务完成
* 3任务调度器不会暂停最高优先级任务
* 4用户手动暂停或任务完成后第二次重新执行该任务该命令将失效
* 5如果下载队列中已经满了则会停止队尾的任务
* 6把任务设置为最高优先级任务后将自动执行任务不需要重新调用start()启动任务
*/
public void setHighestPriority(boolean isHighestPriority) {
isHeighestTask = isHighestPriority;
}
}

@ -16,9 +16,9 @@
package com.arialyy.aria.core.inf;
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.queue.DGroupTaskQueue;
import com.arialyy.aria.core.queue.DTaskQueue;
import com.arialyy.aria.core.queue.UTaskQueue;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -85,7 +85,7 @@ public abstract class AbsReceiver implements IReceiver {
}
/**
* 移除{@link DownloadTaskQueue}{@link DownloadGroupTaskQueue}{@link UploadTaskQueue}中注册的观察者
* 移除{@link DTaskQueue}{@link DGroupTaskQueue}{@link UTaskQueue}中注册的观察者
*/
protected abstract void unRegisterListener();
}

@ -17,7 +17,8 @@ package com.arialyy.aria.core.inf;
import android.text.TextUtils;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.common.controller.BuilderController;
import com.arialyy.aria.core.common.controller.NormalController;
import com.arialyy.aria.util.ALog;

@ -15,6 +15,8 @@
*/
package com.arialyy.aria.core.inf;
import com.arialyy.aria.core.common.AbsEntity;
/**
* Created by lyy on 2019/4/5.
* 普通任务配置处理

@ -15,11 +15,11 @@
*/
package com.arialyy.aria.core.manager;
import com.arialyy.aria.core.common.RecordHandler;
import com.arialyy.aria.core.common.TaskRecord;
import com.arialyy.aria.core.TaskRecord;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.IRecordHandler;
import java.io.File;
/**
@ -75,7 +75,7 @@ class DTaskWrapperFactory implements INormalTEFactory<DownloadEntity, DTaskWrapp
if (record.isBlock) {
int count = 0;
for (int i = 0, len = record.threadNum; i < len; i++) {
File temp = new File(String.format(RecordHandler.SUB_PATH, record.filePath, i));
File temp = new File(String.format(IRecordHandler.SUB_PATH, record.filePath, i));
if (!temp.exists()) {
count++;
}

@ -15,8 +15,8 @@
*/
package com.arialyy.aria.core.manager;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
/**
* 任务组通过组创建任务

@ -15,8 +15,8 @@
*/
package com.arialyy.aria.core.manager;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
/**
* Created by Aria.Lao on 2017/11/1.

@ -20,7 +20,7 @@ import com.arialyy.aria.core.command.GroupCmdFactory;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.core.command.CmdHelper;
import java.util.List;
/**
@ -43,7 +43,7 @@ public class SubTaskManager {
public void startSubTask(String url) {
if (checkUrl(url)) {
EventMsgUtil.getDefault().post(
CommonUtil.createGroupCmd(mEntity, GroupCmdFactory.SUB_TASK_START, url));
CmdHelper.createGroupCmd(mEntity, GroupCmdFactory.SUB_TASK_START, url));
}
}
@ -55,7 +55,7 @@ public class SubTaskManager {
public void stopSubTask(String url) {
if (checkUrl(url)) {
EventMsgUtil.getDefault().post(
CommonUtil.createGroupCmd(mEntity, GroupCmdFactory.SUB_TASK_STOP, url));
CmdHelper.createGroupCmd(mEntity, GroupCmdFactory.SUB_TASK_STOP, url));
}
}

@ -18,7 +18,7 @@ package com.arialyy.aria.core.manager;
import androidx.collection.LruCache;
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.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;

@ -16,10 +16,10 @@
package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.TaskSchedulerType;
import com.arialyy.aria.core.manager.TaskWrapperManager;
@ -29,7 +29,7 @@ import com.arialyy.aria.core.queue.pool.BaseExecutePool;
import com.arialyy.aria.core.queue.pool.DGLoadSharePool;
import com.arialyy.aria.core.queue.pool.DLoadSharePool;
import com.arialyy.aria.core.queue.pool.UploadSharePool;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.core.task.UploadTask;
import com.arialyy.aria.util.ALog;
/**
@ -153,10 +153,10 @@ public abstract class AbsTaskQueue<TASK extends AbsTask, TASK_WRAPPER extends Ab
return mExecutePool.size();
}
@Override public void setMaxTaskNum(int downloadNum) {
@Override public void setMaxTaskNum(int maxNum) {
int oldMaxSize = getOldMaxNum();
int diff = downloadNum - oldMaxSize;
if (oldMaxSize == downloadNum) {
int diff = maxNum - oldMaxSize;
if (oldMaxSize == maxNum) {
ALog.w(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过");
return;
}
@ -169,7 +169,7 @@ public abstract class AbsTaskQueue<TASK extends AbsTask, TASK_WRAPPER extends Ab
}
}
}
mExecutePool.setMaxNum(downloadNum);
mExecutePool.setMaxNum(maxNum);
if (diff >= 1) {
for (int i = 0; i < diff; i++) {
TASK nextTask = getNextTask();

@ -18,35 +18,44 @@ package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.event.DGMaxNumEvent;
import com.arialyy.aria.core.event.Event;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.util.ALog;
/**
* Created by AriaL on 2017/6/29. 任务组下载队列
*/
public class DownloadGroupTaskQueue
public class DGroupTaskQueue
extends AbsTaskQueue<DownloadGroupTask, DGTaskWrapper> {
private static volatile DownloadGroupTaskQueue INSTANCE = null;
private static volatile DGroupTaskQueue INSTANCE = null;
private final String TAG = "DownloadGroupTaskQueue";
public static DownloadGroupTaskQueue getInstance() {
public static DGroupTaskQueue getInstance() {
if (INSTANCE == null) {
synchronized (DownloadGroupTaskQueue.class) {
INSTANCE = new DownloadGroupTaskQueue();
synchronized (DGroupTaskQueue.class) {
INSTANCE = new DGroupTaskQueue();
EventMsgUtil.getDefault().register(INSTANCE);
}
}
return INSTANCE;
}
private DownloadGroupTaskQueue() {
private DGroupTaskQueue() {
}
@Override int getQueueType() {
return TYPE_DG_QUEUE;
}
@Event
public void maxTaskNum(DGMaxNumEvent event) {
setMaxTaskNum(event.maxNum);
}
@Override public int getMaxTaskNum() {
return AriaManager.getInstance().getDGroupConfig().getMaxTaskNum();
}

@ -18,7 +18,10 @@ 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.task.DownloadTask;
import com.arialyy.aria.core.event.DMaxNumEvent;
import com.arialyy.aria.core.event.Event;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.inf.TaskSchedulerType;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.util.ALog;
@ -30,26 +33,32 @@ import java.util.Set;
* Created by lyy on 2016/8/17.
* 下载任务队列
*/
public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DTaskWrapper> {
public class DTaskQueue extends AbsTaskQueue<DownloadTask, DTaskWrapper> {
private static final String TAG = "DownloadTaskQueue";
private static volatile DownloadTaskQueue INSTANCE = null;
private static volatile DTaskQueue INSTANCE = null;
public static DownloadTaskQueue getInstance() {
public static DTaskQueue getInstance() {
if (INSTANCE == null) {
synchronized (DownloadTaskQueue.class) {
INSTANCE = new DownloadTaskQueue();
synchronized (DTaskQueue.class) {
INSTANCE = new DTaskQueue();
EventMsgUtil.getDefault().register(INSTANCE);
}
}
return INSTANCE;
}
private DownloadTaskQueue() {
private DTaskQueue() {
}
@Override int getQueueType() {
return TYPE_D_QUEUE;
}
@Event
public void maxTaskNum(DMaxNumEvent event) {
setMaxTaskNum(event.maxNum);
}
@Override public int getOldMaxNum() {
return AriaManager.getInstance().getDownloadConfig().oldMaxTaskNum;
}

@ -17,13 +17,12 @@
package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.task.UploadTask;
import com.arialyy.aria.core.upload.UTaskWrapper;
/**

@ -18,13 +18,13 @@ package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.listener.ISchedulers;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.core.task.UploadTask;
/**
* Created by lyy on 2016/8/18.

@ -17,28 +17,37 @@
package com.arialyy.aria.core.queue;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.event.Event;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.event.UMaxNumEvent;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.core.task.UploadTask;
import com.arialyy.aria.util.ALog;
/**
* Created by lyy on 2017/2/27. 上传任务队列
*/
public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UTaskWrapper> {
public class UTaskQueue extends AbsTaskQueue<UploadTask, UTaskWrapper> {
private static final String TAG = "UploadTaskQueue";
private static volatile UploadTaskQueue INSTANCE = null;
private static volatile UTaskQueue INSTANCE = null;
public static UploadTaskQueue getInstance() {
public static UTaskQueue getInstance() {
if (INSTANCE == null) {
synchronized (UploadTaskQueue.class) {
INSTANCE = new UploadTaskQueue();
synchronized (UTaskQueue.class) {
INSTANCE = new UTaskQueue();
EventMsgUtil.getDefault().register(INSTANCE);
}
}
return INSTANCE;
}
private UploadTaskQueue() {
private UTaskQueue() {
}
@Event
public void maxTaskNum(UMaxNumEvent event){
setMaxTaskNum(event.maxNum);
}
@Override int getQueueType() {

@ -17,7 +17,7 @@
package com.arialyy.aria.core.queue.pool;
import android.text.TextUtils;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.util.LinkedHashSet;

@ -18,7 +18,7 @@ package com.arialyy.aria.core.queue.pool;
import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.util.Map;

@ -16,7 +16,7 @@
package com.arialyy.aria.core.queue.pool;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.task.AbsTask;
/**
* Created by AriaL on 2017/6/29.

@ -16,7 +16,7 @@
package com.arialyy.aria.core.queue.pool;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.util.Set;

@ -16,8 +16,8 @@
package com.arialyy.aria.core.queue.pool;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.task.AbsTask;
/**
* Created by lyy on 2016/8/14. 任务池

@ -16,7 +16,7 @@
package com.arialyy.aria.core.queue.pool;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.task.AbsTask;
/**
* Created by Aria.Lao on 2017/7/17.

@ -16,8 +16,8 @@
package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.ITaskQueue;
import com.arialyy.aria.util.ALog;

@ -15,10 +15,10 @@
*/
package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.task.UploadTask;
/**
* Created by Aria.Lao on 2017/6/7.

@ -15,8 +15,8 @@
*/
package com.arialyy.aria.core.scheduler;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.common.AbsNormalEntity;
import com.arialyy.aria.core.task.ITask;
/**
* Created by Aria.Lao on 2019/6/26.

@ -20,21 +20,22 @@ import android.os.Bundle;
import android.os.Message;
import com.arialyy.annotations.TaskEnum;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.GroupSendParams;
import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.common.AbsNormalEntity;
import com.arialyy.aria.core.task.AbsTask;
import com.arialyy.aria.core.group.GroupSendParams;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.listener.ISchedulers;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.inf.TaskSchedulerType;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.DGroupTaskQueue;
import com.arialyy.aria.core.queue.DTaskQueue;
import com.arialyy.aria.core.queue.ITaskQueue;
import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.core.queue.UTaskQueue;
import com.arialyy.aria.core.task.UploadTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.NetUtils;
import java.util.Iterator;
@ -78,13 +79,13 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
ITaskQueue getQueue(TASK curTask) {
int taskType = curTask.getTaskType();
if (taskType == ITask.DOWNLOAD) {
return DownloadTaskQueue.getInstance();
return DTaskQueue.getInstance();
}
if (taskType == ITask.DOWNLOAD_GROUP) {
return DownloadGroupTaskQueue.getInstance();
return DGroupTaskQueue.getInstance();
}
if (taskType == ITask.UPLOAD) {
return UploadTaskQueue.getInstance();
return UTaskQueue.getInstance();
}
throw new NullPointerException("任务类型错误,type = " + taskType);
}

@ -21,15 +21,16 @@ import androidx.annotation.NonNull;
import com.arialyy.annotations.TaskEnum;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.CancelAllCmd;
import com.arialyy.aria.core.command.CmdHelper;
import com.arialyy.aria.core.command.NormalCmdFactory;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.common.ProxyHelper;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.ReceiverType;
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.upload.target.FtpBuilderTarget;
import com.arialyy.aria.core.upload.target.FtpNormalTarget;
import com.arialyy.aria.core.upload.target.HttpBuilderTarget;
@ -38,7 +39,7 @@ import com.arialyy.aria.core.upload.target.UTargetFactory;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ComponentUtil;
import java.util.List;
import java.util.Set;
@ -68,6 +69,7 @@ public class UploadReceiver extends AbsReceiver {
*/
@CheckResult
public HttpBuilderTarget load(@NonNull String filePath) {
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_HTTP);
CheckUtil.checkUploadPath(filePath);
return UTargetFactory.getInstance()
.generateBuilderTarget(HttpBuilderTarget.class, filePath);
@ -81,6 +83,7 @@ public class UploadReceiver extends AbsReceiver {
*/
@CheckResult
public HttpNormalTarget load(long taskId) {
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_HTTP);
CheckUtil.checkTaskId(taskId);
return UTargetFactory.getInstance()
.generateNormalTarget(HttpNormalTarget.class, taskId);
@ -93,6 +96,7 @@ public class UploadReceiver extends AbsReceiver {
*/
@CheckResult
public FtpBuilderTarget loadFtp(@NonNull String filePath) {
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_FTP);
CheckUtil.checkUploadPath(filePath);
return UTargetFactory.getInstance()
.generateBuilderTarget(FtpBuilderTarget.class, filePath);
@ -106,6 +110,7 @@ public class UploadReceiver extends AbsReceiver {
*/
@CheckResult
public FtpNormalTarget loadFtp(long taskId) {
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_FTP);
CheckUtil.checkTaskId(taskId);
return UTargetFactory.getInstance()
.generateNormalTarget(FtpNormalTarget.class, taskId);
@ -237,7 +242,7 @@ public class UploadReceiver extends AbsReceiver {
public void removeAllTask(boolean removeFile) {
final AriaManager am = AriaManager.getInstance();
CancelAllCmd cancelCmd =
(CancelAllCmd) CommonUtil.createNormalCmd(new UTaskWrapper(null),
(CancelAllCmd) CmdHelper.createNormalCmd(new UTaskWrapper(null),
NormalCmdFactory.TASK_CANCEL_ALL, ITask.UPLOAD);
cancelCmd.removeFile = removeFile;

@ -17,11 +17,11 @@ package com.arialyy.aria.core.upload.target;
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import com.arialyy.aria.core.processor.IFtpUploadInterceptor;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.common.ftp.IFtpUploadInterceptor;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.common.FtpDelegate;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
/**
* Created by Aria.Lao on 2017/7/27.

@ -17,9 +17,10 @@ package com.arialyy.aria.core.upload.target;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.ftp.FtpDelegate;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.FtpDelegate;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.util.CommonUtil;
@ -32,7 +33,9 @@ public class FtpNormalTarget extends AbsNormalTarget<FtpNormalTarget> {
FtpNormalTarget(long taskId) {
mConfigHandler = new UNormalConfigHandler<>(this, taskId);
getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getUrl()));
getTaskWrapper().getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(getEntity().getUrl()));
getTaskWrapper().setRequestType(AbsTaskWrapper.U_FTP);
}

@ -17,9 +17,9 @@ package com.arialyy.aria.core.upload.target;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.http.HttpDelegate;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.HttpDelegate;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
/**
* Created by lyy on 2017/2/28.

@ -17,9 +17,9 @@ package com.arialyy.aria.core.upload.target;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.Suggest;
import com.arialyy.aria.core.common.http.HttpDelegate;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.HttpDelegate;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
/**
* Created by lyy on 2017/2/28.

@ -15,16 +15,17 @@
*/
package com.arialyy.aria.core.upload.target;
import com.arialyy.aria.core.common.ftp.IFtpUploadInterceptor;
import com.arialyy.aria.core.processor.IFtpUploadInterceptor;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.event.ErrorEvent;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IConfigHandler;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.manager.TaskWrapperManager;
import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.core.queue.UTaskQueue;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.core.task.UploadTask;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil;
import java.io.File;
@ -65,7 +66,8 @@ class UNormalConfigHandler<TARGET extends AbsTarget> implements IConfigHandler {
if (uploadInterceptor == null) {
throw new NullPointerException("ftp拦截器为空");
}
getTaskWrapper().asFtp().setUploadInterceptor(uploadInterceptor);
getTaskWrapper().getOptionParams()
.setObjs(IOptionConstant.uploadInterceptor, uploadInterceptor);
return mTarget;
}
@ -78,13 +80,14 @@ class UNormalConfigHandler<TARGET extends AbsTarget> implements IConfigHandler {
}
@Override public boolean isRunning() {
UploadTask task = UploadTaskQueue.getInstance().getTask(mEntity.getKey());
UploadTask task = UTaskQueue.getInstance().getTask(mEntity.getKey());
return task != null && task.isRunning();
}
void setTempUrl(String tempUrl) {
getTaskWrapper().setTempUrl(tempUrl);
getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(tempUrl));
getTaskWrapper().getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(tempUrl));
}
private UTaskWrapper getTaskWrapper() {

@ -1,116 +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.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.AbsEntity;
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.exception.BaseException;
import com.arialyy.aria.util.CheckUtil;
/**
* Created by lyy on 2017/2/9.
* 简单的文件上传工具
*/
public class SimpleUploadUtil implements IUtil, Runnable {
private static final String TAG = "SimpleUploadUtil";
private UTaskWrapper mTaskWrapper;
private IUploadListener mListener;
private Uploader mUploader;
private boolean isStop = false, isCancel = false;
public SimpleUploadUtil(UTaskWrapper taskWrapper, IUploadListener listener) {
mTaskWrapper = taskWrapper;
CheckUtil.checkTaskEntity(taskWrapper);
if (listener == null) {
throw new IllegalArgumentException("上传监听不能为空");
}
mListener = listener;
mUploader = new Uploader(mListener, taskWrapper);
}
@Override public void run() {
mListener.onPre();
switch (mTaskWrapper.getRequestType()) {
case AbsTaskWrapper.U_FTP:
FtpFileInfoThread infoThread =
new FtpFileInfoThread(mTaskWrapper, new OnFileInfoCallback() {
@Override public void onComplete(String url, CompleteInfo info) {
if (info.code == FtpFileInfoThread.CODE_COMPLETE) {
mListener.onComplete();
} else {
mUploader.start();
}
}
@Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) {
failUpload(e, needRetry);
}
});
new Thread(infoThread).start();
break;
case AbsTaskWrapper.U_HTTP:
mUploader.start();
break;
}
}
private void failUpload(BaseException e, boolean needRetry) {
if (isStop || isCancel) {
return;
}
mListener.onFail(needRetry, e);
mUploader.onDestroy();
}
@Override public String getKey() {
return mTaskWrapper.getKey();
}
@Override public long getFileSize() {
return mUploader.getFileSize();
}
@Override public long getCurrentLocation() {
return mUploader.getCurrentLocation();
}
@Override public boolean isRunning() {
return mUploader.isRunning();
}
@Override public void cancel() {
isCancel = true;
mUploader.cancel();
}
@Override public void stop() {
isStop = true;
mUploader.stop();
}
@Override public void start() {
if (isStop || isCancel) {
return;
}
new Thread(this).start();
}
}

@ -1,61 +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.uploader;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.AbsThreadTask;
import com.arialyy.aria.core.common.NormalFileer;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.event.Event;
import com.arialyy.aria.core.event.SpeedEvent;
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 java.io.File;
/**
* Created by Aria.Lao on 2017/7/27.
* 文件上传器
*/
class Uploader extends NormalFileer<UploadEntity, UTaskWrapper> {
Uploader(IUploadListener listener, UTaskWrapper taskEntity) {
super(listener, taskEntity);
mTempFile = new File(mEntity.getFilePath());
setUpdateInterval(
AriaManager.getInstance().getUploadConfig().getUpdateInterval());
}
@Override protected boolean handleNewTask() {
return true;
}
@Override protected AbsThreadTask selectThreadTask(SubThreadConfig<UTaskWrapper> config) {
switch (mTaskWrapper.getRequestType()) {
case AbsTaskWrapper.U_FTP:
return new FtpThreadTask(config);
case AbsTaskWrapper.U_HTTP:
return new HttpThreadTask(config);
}
return null;
}
@Event
public void setMaxSpeed(SpeedEvent event) {
setMaxSpeed(event.speed);
}
}

@ -20,15 +20,15 @@ package com.arialyy.annotations;
* 任务类型枚举
*/
public enum TaskEnum {
DOWNLOAD("com.arialyy.aria.core.download", "DownloadTask", "$$DownloadListenerProxy",
DOWNLOAD("com.arialyy.aria.core.task", "DownloadTask", "$$DownloadListenerProxy",
"NormalTaskListener"),
DOWNLOAD_GROUP("com.arialyy.aria.core.download", "DownloadGroupTask",
DOWNLOAD_GROUP("com.arialyy.aria.core.task", "DownloadGroupTask",
"$$DownloadGroupListenerProxy", "NormalTaskListener"),
DOWNLOAD_GROUP_SUB("com.arialyy.aria.core.download", "DownloadGroupTask",
DOWNLOAD_GROUP_SUB("com.arialyy.aria.core.task", "DownloadGroupTask",
"$$DGSubListenerProxy", "SubTaskListener"),
UPLOAD("com.arialyy.aria.core.upload", "UploadTask", "$$UploadListenerProxy",
UPLOAD("com.arialyy.aria.core.task", "UploadTask", "$$UploadListenerProxy",
"NormalTaskListener"),
M3U8_PEER("com.arialyy.aria.core.download", "DownloadTask", "$$M3U8PeerListenerProxy",
M3U8_PEER("com.arialyy.aria.core.task", "DownloadTask", "$$M3U8PeerListenerProxy",
"M3U8PeerTaskListener");
public String pkg, className, proxySuffix, proxySuperClass;

@ -20,7 +20,7 @@ package com.arialyy.compiler;
* 实体信息
*/
enum EntityInfo {
NORMAL("com.arialyy.aria.core.inf", "AbsNormalEntity"),
NORMAL("com.arialyy.aria.core.common", "AbsNormalEntity"),
DOWNLOAD("com.arialyy.aria.core.download", "DownloadEntity"),
UPLOAD("com.arialyy.aria.core.upload", "UploadEntity");
String pkg, className;

@ -1,26 +0,0 @@
package com.example.ariaftpcomponent;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.example.ariaftpcomponent.test", appContext.getPackageName());
}
}

@ -1,4 +0,0 @@
package com.arialyy.aria.ftpcomponent;
public class bb {
}

@ -1,17 +0,0 @@
package com.example.ariaftpcomponent;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}

@ -0,0 +1,33 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.appcompat:appcompat:${rootProject.ext.XAppcompatVersion}"
testImplementation 'junit:junit:4.12'
implementation project(path: ':AriaFtpPlug')
implementation project(path: ':PublicComponent')
}

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.common.ftp;
package com.arialyy.aria.ftp;
import android.net.TrafficStats;
import android.os.Process;
@ -24,10 +24,11 @@ import aria.apache.commons.net.ftp.FTPClientConfig;
import aria.apache.commons.net.ftp.FTPFile;
import aria.apache.commons.net.ftp.FTPReply;
import aria.apache.commons.net.ftp.FTPSClient;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.OnFileInfoCallback;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.BaseException;
@ -55,7 +56,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
private final String TAG = "AbsFtpInfoThread";
protected ENTITY mEntity;
protected TASK_WRAPPER mTaskWrapper;
private FtpTaskConfig mTaskDelegate;
protected FtpTaskOption mTaskOption;
private int mConnectTimeOut;
protected OnFileInfoCallback mCallback;
protected long mSize = 0;
@ -65,9 +66,8 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
public AbsFtpInfoThread(TASK_WRAPPER taskWrapper, OnFileInfoCallback callback) {
mTaskWrapper = taskWrapper;
mEntity = taskWrapper.getEntity();
mTaskDelegate = taskWrapper.asFtp();
mConnectTimeOut =
AriaManager.getInstance().getDownloadConfig().getConnectTimeOut();
mTaskOption = (FtpTaskOption) taskWrapper.getTaskOption();
mConnectTimeOut = AriaConfig.getInstance().getDConfig().getConnectTimeOut();
mCallback = callback;
if (mEntity instanceof UploadEntity) {
isUpload = true;
@ -89,7 +89,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
try {
client = createFtpClient();
if (client == null) {
ALog.e(TAG, String.format("任务【%s】失败", mTaskDelegate.getUrlEntity().url));
ALog.e(TAG, String.format("任务【%s】失败", mTaskOption.getUrlEntity().url));
return;
}
String remotePath = CommonUtil.convertFtpChar(charSet, getRemotePath());
@ -118,7 +118,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
closeClient(client);
failDownload(new FileNotFoundException(TAG,
String.format("文件不存在,url: %s, remotePath:%s", mTaskDelegate.getUrlEntity().url,
String.format("文件不存在,url: %s, remotePath:%s", mTaskOption.getUrlEntity().url,
remotePath)), false);
return;
}
@ -141,7 +141,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
closeClient(client);
failDownload(new AriaIOException(TAG,
String.format("获取文件信息错误,url: %s, errorCode:%s, errorMsg:%s",
mTaskDelegate.getUrlEntity().url, reply, client.getReplyString())), true);
mTaskOption.getUrlEntity().url, reply, client.getReplyString())), true);
return;
}
}
@ -193,7 +193,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
*/
private FTPClient createFtpClient() {
FTPClient client = null;
final FtpUrlEntity urlEntity = mTaskDelegate.getUrlEntity();
final FtpUrlEntity urlEntity = mTaskOption.getUrlEntity();
try {
Pattern p = Pattern.compile(Regular.REG_IP_V4);
Matcher m = p.matcher(urlEntity.hostName);
@ -203,7 +203,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
InetAddress ip = InetAddress.getByName(urlEntity.hostName);
client = connect(client, new InetAddress[] { ip }, 0, Integer.parseInt(urlEntity.port));
mTaskDelegate.getUrlEntity().validAddr = ip;
mTaskOption.getUrlEntity().validAddr = ip;
} else {
DNSQueryThread dnsThread = new DNSQueryThread(urlEntity.hostName);
dnsThread.start();
@ -214,7 +214,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
if (client == null) {
failDownload(new AriaIOException(TAG,
String.format("链接失败, url: %s", mTaskDelegate.getUrlEntity().url)), false);
String.format("链接失败, url: %s", mTaskOption.getUrlEntity().url)), false);
return null;
}
@ -248,7 +248,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
client.disconnect();
failDownload(new AriaIOException(TAG,
String.format("无法连接到ftp服务器,filePath: %s, url: %s, errorCode: %s, errorMsg:%s",
mEntity.getKey(), mTaskDelegate.getUrlEntity().url, reply,
mEntity.getKey(), mTaskOption.getUrlEntity().url, reply,
client.getReplyString())),
true);
return null;
@ -258,8 +258,8 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
reply = client.sendCommand("OPTS UTF8", "ON");
if (reply != FTPReply.COMMAND_IS_SUPERFLUOUS) {
ALog.i(TAG, "D_FTP 服务器不支持开启UTF8编码,尝试使用Aria手动设置的编码");
if (!TextUtils.isEmpty(mTaskWrapper.asFtp().getCharSet())) {
charSet = mTaskWrapper.asFtp().getCharSet();
if (!TextUtils.isEmpty(mTaskOption.getCharSet())) {
charSet = mTaskOption.getCharSet();
}
}
client.setControlEncoding(charSet);
@ -308,8 +308,8 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
}
FTPClientConfig clientConfig;
if (mTaskWrapper.asFtp().getClientConfig() != null) {
clientConfig = mTaskWrapper.asFtp().getClientConfig();
if (mTaskOption.getClientConfig() != null) {
clientConfig = mTaskOption.getClientConfig();
} else {
clientConfig = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
clientConfig.setServerLanguageCode("en");
@ -330,9 +330,9 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
try {
client.setConnectTimeout(mConnectTimeOut); //需要先设置超时,这样才不会出现阻塞
client.connect(ips[index], port);
mTaskDelegate.getUrlEntity().validAddr = ips[index];
mTaskOption.getUrlEntity().validAddr = ips[index];
FtpUrlEntity urlEntity = mTaskWrapper.asFtp().getUrlEntity();
FtpUrlEntity urlEntity = mTaskOption.getUrlEntity();
if (urlEntity.isFtps) {
FTPSClient sClient = (FTPSClient) client;
sClient.execPBSZ(0);
@ -353,7 +353,7 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER ex
e1.printStackTrace();
}
ALog.w(TAG, "遇到[ECONNREFUSED-连接被服务器拒绝]错误,正在尝试下一个地址");
return connect(newInstanceClient(mTaskDelegate.getUrlEntity()), ips, index + 1, port);
return connect(newInstanceClient(mTaskOption.getUrlEntity()), ips, index + 1, port);
}
}

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.common.ftp;
package com.arialyy.aria.ftp;
import android.text.TextUtils;
import aria.apache.commons.net.ftp.FTP;
@ -21,10 +21,9 @@ import aria.apache.commons.net.ftp.FTPClient;
import aria.apache.commons.net.ftp.FTPClientConfig;
import aria.apache.commons.net.ftp.FTPReply;
import aria.apache.commons.net.ftp.FTPSClient;
import com.arialyy.aria.core.common.AbsThreadTask;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.task.AbsThreadTaskAdapter;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.SSLContextUtil;
@ -34,15 +33,17 @@ import java.net.UnknownHostException;
import javax.net.ssl.SSLContext;
/**
* Created by lyy on 2017/9/26. FTP单任务父类
* @Author lyy
* @Date 2019-09-18
*/
public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAPPER extends AbsTaskWrapper<ENTITY>>
extends AbsThreadTask<ENTITY, TASK_WRAPPER> {
private final String TAG = "AbsFtpThreadTask";
public abstract class BaseFtpThreadTaskAdapter extends AbsThreadTaskAdapter {
protected FtpTaskOption mTaskOption;
protected String charSet;
protected AbsFtpThreadTask(SubThreadConfig<TASK_WRAPPER> config) {
protected BaseFtpThreadTaskAdapter(SubThreadConfig config) {
super(config);
}
protected void closeClient(FTPClient client) {
@ -61,7 +62,7 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAP
*/
protected FTPClient createClient() {
FTPClient client = null;
final FtpUrlEntity urlEntity = getTaskWrapper().asFtp().getUrlEntity();
final FtpUrlEntity urlEntity = mTaskOption.getUrlEntity();
if (urlEntity.validAddr == null) {
try {
InetAddress[] ips = InetAddress.getAllByName(urlEntity.hostName);
@ -103,15 +104,15 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAP
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
client.disconnect();
fail(mChildCurrentLocation, new AriaIOException(TAG,
fail(new AriaIOException(TAG,
String.format("无法连接到ftp服务器,错误码为:%s,msg:%s", reply, client.getReplyString())), false);
return null;
}
// 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码
charSet = "UTF-8";
if (reply != FTPReply.COMMAND_IS_SUPERFLUOUS) {
if (!TextUtils.isEmpty(getTaskWrapper().asFtp().getCharSet())) {
charSet = getTaskWrapper().asFtp().getCharSet();
if (!TextUtils.isEmpty(mTaskOption.getCharSet())) {
charSet = mTaskOption.getCharSet();
}
}
client.setControlEncoding(charSet);
@ -148,8 +149,8 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAP
}
FTPClientConfig clientConfig;
if (mTaskWrapper.asFtp().getClientConfig() != null) {
clientConfig = mTaskWrapper.asFtp().getClientConfig();
if (mTaskOption.getClientConfig() != null) {
clientConfig = mTaskOption.getClientConfig();
} else {
clientConfig = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
clientConfig.setServerLanguageCode("en");
@ -165,7 +166,7 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAP
private FTPClient connect(FTPClient client, InetAddress[] ips, int index, int port) {
try {
client.connect(ips[index], port);
getTaskWrapper().asFtp().getUrlEntity().validAddr = ips[index];
mTaskOption.getUrlEntity().validAddr = ips[index];
return client;
} catch (java.io.IOException e) {
try {
@ -189,3 +190,5 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_WRAP
}
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save