From ce408c0d5cf9fbed0f9f0bdddfc239b7317b3fd1 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Mon, 14 Oct 2019 20:00:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dftp=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aria/ftp/BaseFtpThreadTaskAdapter.java | 2 +- .../arialyy/aria/ftp/FtpDirInfoThread.java | 9 +++- .../aria/ftp/download/FtpDLoaderUtil.java | 7 +-- .../aria/ftp/download/FtpDirDLoaderUtil.java | 22 +++++--- ...LoaderUtil.java => FtpSubDLoaderUtil.java} | 8 ++- .../aria/ftp/upload/FtpULoaderUtil.java | 8 +-- .../aria/http/download/DGroupLoaderUtil.java | 4 +- ...oaderUtil.java => HttpSubDLoaderUtil.java} | 12 ++--- .../arialyy/aria/core/group/AbsGroupUtil.java | 6 +-- .../aria/core/listener/BaseUListener.java | 4 +- .../aria/core/processor/ProxyHandler.java | 50 +++++++++++++++++++ .../aria/core/wrapper/AbsTaskWrapper.java | 4 ++ app/build.gradle | 1 + .../core/download/FtpDownloadActivity.java | 9 ++-- .../core/download/FtpDownloadModule.java | 4 +- .../group/FTPDirDownloadActivity.java | 9 ++-- .../simple/core/upload/FtpUploadActivity.java | 23 +++------ .../simple/core/upload/UploadModule.java | 4 +- 18 files changed, 122 insertions(+), 64 deletions(-) rename FtpComponent/src/main/java/com/arialyy/aria/ftp/download/{SubDLoaderUtil.java => FtpSubDLoaderUtil.java} (86%) rename HttpComponent/src/main/java/com/arialyy/aria/http/download/{SubDLoaderUtil.java => HttpSubDLoaderUtil.java} (86%) create mode 100644 PublicComponent/src/main/java/com/arialyy/aria/core/processor/ProxyHandler.java diff --git a/FtpComponent/src/main/java/com/arialyy/aria/ftp/BaseFtpThreadTaskAdapter.java b/FtpComponent/src/main/java/com/arialyy/aria/ftp/BaseFtpThreadTaskAdapter.java index 6f639932..5c73fefc 100644 --- a/FtpComponent/src/main/java/com/arialyy/aria/ftp/BaseFtpThreadTaskAdapter.java +++ b/FtpComponent/src/main/java/com/arialyy/aria/ftp/BaseFtpThreadTaskAdapter.java @@ -43,7 +43,7 @@ public abstract class BaseFtpThreadTaskAdapter extends AbsThreadTaskAdapter { protected BaseFtpThreadTaskAdapter(SubThreadConfig config) { super(config); - + mTaskOption = (FtpTaskOption) getTaskWrapper().getTaskOption(); } protected void closeClient(FTPClient client) { diff --git a/FtpComponent/src/main/java/com/arialyy/aria/ftp/FtpDirInfoThread.java b/FtpComponent/src/main/java/com/arialyy/aria/ftp/FtpDirInfoThread.java index 2751524f..a355a01b 100644 --- a/FtpComponent/src/main/java/com/arialyy/aria/ftp/FtpDirInfoThread.java +++ b/FtpComponent/src/main/java/com/arialyy/aria/ftp/FtpDirInfoThread.java @@ -91,10 +91,17 @@ public class FtpDirInfoThread extends AbsFtpInfoThread> +public class BaseUListener extends BaseListener> implements IUploadListener { - BaseUListener(AbsTask task, Handler outHandler) { + public BaseUListener(AbsTask task, Handler outHandler) { super(task, outHandler); } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/processor/ProxyHandler.java b/PublicComponent/src/main/java/com/arialyy/aria/core/processor/ProxyHandler.java new file mode 100644 index 00000000..be6d2c10 --- /dev/null +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/processor/ProxyHandler.java @@ -0,0 +1,50 @@ +/* + * 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.processor; + +import com.arialyy.aria.core.inf.IEventHandler; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +/** + * @Author lyy + * @Date 2019-10-7 + * 处理器的动态代理 + */ +public class ProxyHandler implements InvocationHandler { + + private Object mTarget; + + /** + * 绑定代理对象并返回代理类 + */ + public Object bind(Class clazz) { + //绑定该类实现的所有接口,取得代理类 + try { + mTarget = clazz.newInstance(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } + return Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this); + } + + @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + return method.invoke(mTarget, args); + } +} diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/wrapper/AbsTaskWrapper.java b/PublicComponent/src/main/java/com/arialyy/aria/core/wrapper/AbsTaskWrapper.java index b97e8f61..a2b283e9 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/wrapper/AbsTaskWrapper.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/wrapper/AbsTaskWrapper.java @@ -84,6 +84,10 @@ public abstract class AbsTaskWrapper */ private TaskOptionParams optionParams = new TaskOptionParams(); + public void setTaskOption(ITaskOption option) { + this.taskOption = option; + } + public ITaskOption getTaskOption() { return taskOption; } diff --git a/app/build.gradle b/app/build.gradle index 4ffcbf6a..fa553264 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -74,6 +74,7 @@ dependencies { implementation 'com.pddstudio:highlightjs-android:1.5.0' implementation 'org.greenrobot:eventbus:3.1.1' implementation project(path: ':M3U8Component') + implementation project(path: ':FtpComponent') } repositories { mavenCentral() diff --git a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java index 94d3a04e..5e9f8acd 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java @@ -48,7 +48,7 @@ public class FtpDownloadActivity extends BaseActivity getFtpDownloadInfo(Context context) { String url = AppUtil.getConfigValue(context, FTP_URL_KEY, ftpDefUrl); diff --git a/app/src/main/java/com/arialyy/simple/core/download/group/FTPDirDownloadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/group/FTPDirDownloadActivity.java index 755e4b90..b8077dbb 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/group/FTPDirDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/group/FTPDirDownloadActivity.java @@ -35,10 +35,11 @@ import com.arialyy.simple.widget.SubStateLinearLayout; * Created by lyy on 2017/7/6. */ public class FTPDirDownloadActivity extends BaseActivity { - private static final String dir = "ftp://9.9.9.205:2121/upload/测试"; + private static final String dir = "ftp://9.9.9.50:2121/upload/测试"; private SubStateLinearLayout mChildList; private long mTaskId = -1; + private String user = "lao", pwd = "123456"; @Override protected void init(Bundle savedInstanceState) { super.init(savedInstanceState); @@ -78,7 +79,7 @@ public class FTPDirDownloadActivity extends BaseActivity { private String mUrl; private UploadModule mModule; private long mTaskId = -1; + private String user = "lao", pwd = "123456"; @Override protected void init(Bundle savedInstanceState) { setTile("D_FTP 文件上传"); @@ -117,20 +118,8 @@ public class FtpUploadActivity extends BaseActivity { mTaskId = Aria.upload(this) .loadFtp(mFilePath) .setUploadUrl(mUrl) - .setUploadInterceptor( - new IFtpUploadInterceptor() { - - @Override - public FtpInterceptHandler onIntercept(UploadEntity entity, - List fileList) { - FtpInterceptHandler.Builder builder = new FtpInterceptHandler.Builder(); - //builder.coverServerFile(); - builder.resetFileName("test.zip"); - return builder.build(); - } - }) .option() - .login("8L8e", "8guD") + .login(user, pwd) .controller(ControllerType.CREATE_CONTROLLER) .create(); getBinding().setStateStr(getString(R.string.stop)); @@ -143,7 +132,7 @@ public class FtpUploadActivity extends BaseActivity { Aria.upload(this) .loadFtp(mTaskId) .option() - .login("8L8e", "8guD") + .login(user, pwd) .controller(ControllerType.TASK_CONTROLLER) .resume(); getBinding().setStateStr(getString(R.string.stop)); diff --git a/app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java b/app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java index 7c5994c0..e88d07cc 100644 --- a/app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java +++ b/app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java @@ -35,9 +35,9 @@ public class UploadModule extends BaseViewModule { * 获取Ftp上传信息 */ LiveData getFtpInfo(Context context) { - String url = AppUtil.getConfigValue(context, FTP_URL_KEY, "ftp://9.9.9.205:2121/aa/你好"); + String url = AppUtil.getConfigValue(context, FTP_URL_KEY, "ftp://9.9.9.50:2121/aa/你好"); String filePath = AppUtil.getConfigValue(context, FTP_PATH_KEY, - Environment.getExternalStorageDirectory().getPath() + "/AriaPrj.rar"); + Environment.getExternalStorageDirectory().getPath() + "/Download/PaNTFS15562.zip"); UploadEntity entity = Aria.upload(context).getFirstUploadEntity(filePath); if (entity != null) {