Skip to content
Permalink
Browse files

优化ttbuilder

  • Loading branch information
AriaLyy committed Jan 11, 2020
1 parent 36c2267 commit 6f5323580796937f3c5ffafb3fe7de2902b7bc9e
Showing with 931 additions and 456 deletions.
  1. +39 −11 Aria/src/main/java/com/arialyy/aria/core/common/FtpOption.java
  2. +2 −2 Aria/src/main/java/com/arialyy/aria/core/download/CheckFtpDirEntityUtil.java
  3. +2 −0 DEV_LOG.md
  4. +2 −2 FtpComponent/src/main/java/com/arialyy/aria/ftp/AbsFtpInfoTask.java
  5. +2 −2 FtpComponent/src/main/java/com/arialyy/aria/ftp/BaseFtpThreadTaskAdapter.java
  6. +95 −0 FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDLoader.java
  7. +2 −1 FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDLoaderUtil.java
  8. +9 −28 FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDRecordHandler.java
  9. +2 −11 ...nent/src/main/java/com/arialyy/aria/ftp/download/{FtpDTTBuilder.java → FtpDTTBuilderAdapter.java}
  10. +2 −1 FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpSubDLoaderUtil.java
  11. +14 −1 FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpULoaderUtil.java
  12. +0 −41 FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUTTBuilder.java
  13. +14 −1 HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDLoaderUtil.java
  14. +3 −7 ...t/src/main/java/com/arialyy/aria/http/download/{HttpDTTBuilder.java → HttpDTTBuilderAdapter.java}
  15. +2 −1 HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpSubDLoaderUtil.java
  16. +14 −1 HttpComponent/src/main/java/com/arialyy/aria/http/upload/HttpULoaderUtil.java
  17. +0 −41 HttpComponent/src/main/java/com/arialyy/aria/http/upload/HttpUTTBuilder.java
  18. +1 −14 PublicComponent/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java
  19. +47 −0 PublicComponent/src/main/java/com/arialyy/aria/core/IdEntity.java
  20. +2 −0 PublicComponent/src/main/java/com/arialyy/aria/core/common/SubThreadConfig.java
  21. +90 −0 PublicComponent/src/main/java/com/arialyy/aria/core/loader/AbsNormalTTBuilderAdapter.java
  22. +13 −40 ...onent/src/main/java/com/arialyy/aria/core/loader/{AbsNormalTTBuilder.java → NormalTTBuilder.java}
  23. +7 −10 ...adAdapter.java → PublicComponent/src/main/java/com/arialyy/aria/exception/AriaLoginException.java
  24. +2 −0 PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java
  25. +124 −0 SFtpComponent/src/main/java/com/arialyy/aria/sftp/AbsSFtpInfoTask.java
  26. +0 −100 SFtpComponent/src/main/java/com/arialyy/aria/sftp/SFtpInfoThread.java
  27. +98 −0 SFtpComponent/src/main/java/com/arialyy/aria/sftp/SFtpSessionManager.java
  28. +2 −23 ...onent/src/main/java/com/arialyy/aria/sftp/{BaseInfoThreadAdapter.java → SFtpSubThreadCOnfig.java}
  29. +49 −0 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDInfoTask.java
  30. +163 −0 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDLoader.java
  31. +0 −40 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDLoaderAdapter.java
  32. +54 −75 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDLoaderUtil.java
  33. +72 −0 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDTTBuilderAdapter.java
  34. +1 −1 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDThreadTaskAdapter.java
  35. +1 −1 app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  36. +1 −1 app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
@@ -17,6 +17,7 @@

import android.text.TextUtils;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.IdEntity;
import com.arialyy.aria.core.ProtocolType;
import com.arialyy.aria.core.processor.IFtpUploadInterceptor;
import com.arialyy.aria.util.ALog;
@@ -36,7 +37,7 @@
private String charSet, userName, password, account;
private boolean isNeedLogin = false;
private FtpUrlEntity urlEntity;
private String protocol, keyAlias, storePass, storePath;
private String protocol;
private boolean isImplicit = true;
private IFtpUploadInterceptor uploadInterceptor;
private int connMode = FtpConnectionMode.DATA_CONNECTION_MODE_PASV;
@@ -51,6 +52,7 @@
private String serverTimeZoneId = null;
private String systemKey = FTPServerIdentifier.SYST_UNIX;
//---------------- ftp client 配置信息 end
private IdEntity idEntity = new IdEntity();

public FtpOption() {
super();
@@ -98,7 +100,7 @@ public FtpOption setProtocol(String protocol) {
}

/**
* 设置证书别名
* 设置私钥证书别名
*
* @param keyAlias 别名
*/
@@ -107,12 +109,12 @@ public FtpOption setAlias(String keyAlias) {
ALog.e(TAG, "设置证书别名失败,证书别名为空");
return this;
}
this.keyAlias = keyAlias;
idEntity.keyAlias = keyAlias;
return this;
}

/**
* 设置证书密码
* 设置私钥证书密码
*
* @param storePass 私钥密码
*/
@@ -121,12 +123,12 @@ public FtpOption setStorePass(String storePass) {
ALog.e(TAG, "设置证书密码失败,证书密码为空");
return this;
}
this.storePass = storePass;
idEntity.prvPass = storePass;
return this;
}

/**
* 设置证书路径
* 设置私钥证书路径
*
* @param storePath 证书路径
*/
@@ -135,7 +137,35 @@ public FtpOption setStorePath(String storePath) {
ALog.e(TAG, "设置证书路径失败,证书路径为空");
return this;
}
this.storePath = storePath;
idEntity.storePath = storePath;
return this;
}

/**
* 设置私钥证书
*
* @param prvKey 证书内容
*/
public FtpOption setPrvKey(String prvKey) {
if (TextUtils.isEmpty(prvKey)) {
ALog.e(TAG, "设置私钥证书失败,证书内容为空");
return this;
}
idEntity.prvKey = prvKey;
return this;
}

/**
* 设置公钥证书
*
* @param pubKey 公钥证书内容
*/
public FtpOption setPubKey(String pubKey) {
if (TextUtils.isEmpty(pubKey)) {
ALog.e(TAG, "设置公钥失败,证书内容为空");
return this;
}
idEntity.pubKey = pubKey;
return this;
}

@@ -296,12 +326,10 @@ public void setUrlEntity(FtpUrlEntity urlEntity) {
urlEntity.user = userName;
urlEntity.password = password;
urlEntity.account = account;
if (!TextUtils.isEmpty(storePath)) {
if (!TextUtils.isEmpty(idEntity.storePath) || !TextUtils.isEmpty(idEntity.prvKey)) {
urlEntity.isFtps = true;
urlEntity.protocol = protocol;
urlEntity.keyAlias = keyAlias;
urlEntity.storePass = storePass;
urlEntity.storePath = storePath;
urlEntity.idEntity = idEntity;
urlEntity.isImplicit = isImplicit;
}
}
@@ -90,11 +90,11 @@ public boolean checkEntity() {
(FtpUrlEntity) mWrapper.getOptionParams().getParam(IOptionConstant.ftpUrlEntity);
assert urlEntity != null;
if (urlEntity.isFtps) {
if (TextUtils.isEmpty(urlEntity.storePath)) {
if (TextUtils.isEmpty(urlEntity.idEntity.storePath)) {
ALog.e(TAG, "证书路径为空");
return false;
}
if (TextUtils.isEmpty(urlEntity.keyAlias)) {
if (TextUtils.isEmpty(urlEntity.idEntity.keyAlias)) {
ALog.e(TAG, "证书别名为空");
return false;
}
@@ -1,4 +1,6 @@
## 开发日志
+ v_3.8.4
- fix bug https://github.com/AriaLyy/Aria/issues/599
+ v_3.8.3 (2020/1/9)
- fix bug https://github.com/AriaLyy/Aria/issues/573
- android P适配 https://github.com/AriaLyy/Aria/issues/581
@@ -226,8 +226,8 @@ private FTPClient newInstanceClient(FtpUrlEntity urlEntity) {
FTPClient temp;
if (urlEntity.isFtps) {
FTPSClient sClient;
SSLContext sslContext = SSLContextUtil.getSSLContext(urlEntity.keyAlias, urlEntity.storePath,
urlEntity.protocol);
SSLContext sslContext = SSLContextUtil.getSSLContext(
urlEntity.idEntity.keyAlias, urlEntity.idEntity.storePath, urlEntity.protocol);
if (sslContext == null) {
sClient = new FTPSClient(urlEntity.protocol, urlEntity.isImplicit);
} else {
@@ -147,8 +147,8 @@ private FTPClient newInstanceClient(FtpUrlEntity urlEntity) {
FTPClient temp;
if (urlEntity.isFtps) {
FTPSClient sClient;
SSLContext sslContext = SSLContextUtil.getSSLContext(urlEntity.keyAlias, urlEntity.storePath,
urlEntity.protocol);
SSLContext sslContext = SSLContextUtil.getSSLContext(
urlEntity.idEntity.keyAlias, urlEntity.idEntity.storePath, urlEntity.protocol);
if (sslContext == null) {
sClient = new FTPSClient(urlEntity.protocol, urlEntity.isImplicit);
} else {
@@ -0,0 +1,95 @@
///*
// * 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.ftp.download;
//
//import com.arialyy.aria.core.TaskRecord;
//import com.arialyy.aria.core.common.SubThreadConfig;
//import com.arialyy.aria.core.listener.IEventListener;
//import com.arialyy.aria.core.loader.NormalTTBuilder;
//import com.arialyy.aria.core.loader.IRecordHandler;
//import com.arialyy.aria.core.loader.IThreadTaskBuilder;
//import com.arialyy.aria.core.loader.NormalLoader;
//import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
//import com.arialyy.aria.util.ALog;
//import com.arialyy.aria.util.FileUtil;
//import java.io.File;
//import java.lang.reflect.InvocationHandler;
//import java.lang.reflect.Method;
//import java.lang.reflect.Proxy;
//
//final class FtpDLoader extends NormalLoader {
// FtpDLoader(AbsTaskWrapper wrapper, IEventListener listener) {
// super(wrapper, listener);
// }
//
// @Override public void addComponent(IThreadTaskBuilder builder) {
// mTTBuilder = (IThreadTaskBuilder) Proxy.newProxyInstance(getClass().getClassLoader(),
// NormalTTBuilder.class.getInterfaces(), new InvocationHandler() {
// NormalTTBuilder target = new NormalTTBuilder(mTaskWrapper);
// @Override public Object invoke(Object proxy, Method method, Object[] args)
// throws Exception {
// if (method.getDeclaringClass() == Object.class) {
// return method.invoke(this, args);
// }
//
// //if (method.isDefault()) {
// // Constructor<MethodHandles.Lookup>
// // constructor =
// // MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class);
// // constructor.setAccessible(true);
// // return constructor.newInstance(AbsNormalTTBuilder.class, -1 /* trusted */)
// // .unreflectSpecial(method, AbsNormalTTBuilder.class)
// // .bindTo(proxy)
// // .invokeWithArguments(args);
// //}
//
// String methodName = method.getName();
// switch (methodName) {
//
// case "handleNewTask":
// return handleNewTask((TaskRecord) args[0], (int) args[1]);
// case "getAdapter":
// return new FtpDThreadTaskAdapter((SubThreadConfig) args[0]);
// }
//
// return method.invoke(target, args);
// }
// });
// }
//
// /**
// * 处理新任务
// */
// private boolean handleNewTask(TaskRecord record, int totalThreadNum) {
// File temp = new File(getEntity().getFilePath());
// if (!record.isBlock) {
// if (temp.exists()) {
// FileUtil.deleteFile(temp);
// }
// //CommonUtil.createFile(mTempFile.getPath());
// } else {
// for (int i = 0; i < totalThreadNum; i++) {
// File blockFile =
// new File(String.format(IRecordHandler.SUB_PATH, temp.getPath(), i));
// if (blockFile.exists()) {
// ALog.d(TAG, String.format("分块【%s】已经存在,将删除该分块", i));
// FileUtil.deleteFile(blockFile);
// }
// }
// }
// return true;
// }
//}
@@ -21,6 +21,7 @@
import com.arialyy.aria.core.loader.AbsNormalLoaderUtil;
import com.arialyy.aria.core.loader.LoaderStructure;
import com.arialyy.aria.core.loader.NormalLoader;
import com.arialyy.aria.core.loader.NormalTTBuilder;
import com.arialyy.aria.core.loader.NormalThreadStateManager;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.ftp.FtpTaskOption;
@@ -45,7 +46,7 @@ public LoaderStructure BuildLoaderStructure() {
structure.addComponent(new FtpDRecordHandler((DTaskWrapper) getTaskWrapper()))
.addComponent(new NormalThreadStateManager(getListener()))
.addComponent(new FtpDFileInfoTask((DTaskWrapper) getTaskWrapper()))
.addComponent(new FtpDTTBuilder(getTaskWrapper()));
.addComponent(new NormalTTBuilder(getTaskWrapper(), new FtpDTTBuilderAdapter()));
structure.accept(getLoader());
return structure;
}
@@ -21,19 +21,17 @@
import com.arialyy.aria.core.common.RecordHelper;
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.loader.IRecordHandler;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.RecordUtil;
import java.util.ArrayList;

/**
* @Author lyy
* @Date 2019-09-19
*/
final class FtpDRecordHandler extends RecordHandler {
public final class FtpDRecordHandler extends RecordHandler {

FtpDRecordHandler(DTaskWrapper wrapper) {
public FtpDRecordHandler(DTaskWrapper wrapper) {
super(wrapper);
}

@@ -76,35 +74,18 @@ public ThreadRecord createThreadRecord(TaskRecord record, int threadId, long sta
record.filePath = getEntity().getFilePath();
record.threadRecords = new ArrayList<>();
record.threadNum = threadNum;

int requestType = getWrapper().getRequestType();
if (requestType == ITaskWrapper.D_FTP || requestType == ITaskWrapper.D_FTP_DIR) {
record.isBlock = Configuration.getInstance().downloadCfg.isUseBlock();
} else {
record.isBlock = false;
}
record.isBlock = Configuration.getInstance().downloadCfg.isUseBlock();
record.taskType = getWrapper().getEntity().getTaskType();
record.isGroupRecord = getEntity().isGroupChild();
if (record.isGroupRecord) {
if (getEntity() instanceof DownloadEntity) {
record.dGroupHash = ((DownloadEntity) getEntity()).getGroupHash();
}
}
record.isGroupRecord = false;

return record;
}

@Override public int initTaskThreadNum() {
int requestType = getWrapper().getRequestType();
if (requestType == ITaskWrapper.D_FTP || requestType == ITaskWrapper.D_FTP_DIR) {
int threadNum = Configuration.getInstance().downloadCfg.getThreadNum();
return getFileSize() <= IRecordHandler.SUB_LEN
|| getEntity().isGroupChild()
|| threadNum == 1
? 1
: threadNum;
} else {
return 1;
}
int threadNum = Configuration.getInstance().downloadCfg.getThreadNum();
return getFileSize() <= IRecordHandler.SUB_LEN
|| threadNum == 1
? 1
: threadNum;
}
}
@@ -17,23 +17,14 @@

import com.arialyy.aria.core.TaskRecord;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.loader.AbsNormalTTBuilder;
import com.arialyy.aria.core.loader.AbsNormalTTBuilderAdapter;
import com.arialyy.aria.core.loader.IRecordHandler;
import com.arialyy.aria.core.task.IThreadTaskAdapter;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.FileUtil;
import java.io.File;

/**
* @Author lyy
* @Date 2019-09-19
*/
final class FtpDTTBuilder extends AbsNormalTTBuilder {

FtpDTTBuilder(AbsTaskWrapper wrapper) {
super(wrapper);
}
final class FtpDTTBuilderAdapter extends AbsNormalTTBuilderAdapter {

@Override public IThreadTaskAdapter getAdapter(SubThreadConfig config) {
return new FtpDThreadTaskAdapter(config);
@@ -20,6 +20,7 @@
import com.arialyy.aria.core.group.AbsSubDLoadUtil;
import com.arialyy.aria.core.group.SubRecordHandler;
import com.arialyy.aria.core.loader.LoaderStructure;
import com.arialyy.aria.core.loader.NormalTTBuilder;
import com.arialyy.aria.core.loader.SubLoader;

/**
@@ -48,7 +49,7 @@
@Override protected LoaderStructure buildLoaderStructure() {
LoaderStructure structure = new LoaderStructure();
structure.addComponent(new SubRecordHandler(getWrapper()))
.addComponent(new FtpDTTBuilder(getWrapper()))
.addComponent(new NormalTTBuilder(getWrapper(), new FtpDTTBuilderAdapter()))
.addComponent(new FtpDFileInfoTask(getWrapper()));
structure.accept(getLoader());
return structure;

0 comments on commit 6f53235

Please sign in to comment.
You can’t perform that action at this time.