pull/617/head 3.7.6
laoyuyu 5 years ago
parent 846e6c0720
commit 1b54bfc4ac
  1. 5
      Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java
  2. 1
      Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java
  3. 5
      DEV_LOG.md
  4. 1
      FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUFileInfoThread.java
  5. 33
      README.md
  6. 58
      SFtpComponent/src/main/java/com/arialyy/aria/sftp/AbsSFtpFileInfoThread.java
  7. 42
      SFtpComponent/src/main/java/com/arialyy/aria/sftp/BaseInfoThreadAdapter.java
  8. 50
      SFtpComponent/src/main/java/com/arialyy/aria/sftp/SFtpInfoThread.java
  9. 31
      SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/DSFtpInfoThreadAdapter.java
  10. 10
      SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDLoaderUtil.java
  11. 8
      app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java
  12. 6
      app/src/main/java/com/arialyy/simple/core/download/group/GroupModule.java
  13. 53
      app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java
  14. 2
      app/src/main/java/com/arialyy/simple/core/upload/UploadModule.java
  15. 4
      build.gradle

@ -170,9 +170,8 @@ public class CheckDGEntityUtil implements ICheckEntityUtil {
if (!newName.equals(entity.getFileName())) {
String oldPath = mEntity.getDirPath() + "/" + entity.getFileName();
String newPath = mEntity.getDirPath() + "/" + newName;
if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=? or isComplete='true'",
newPath)) {
ALog.w(TAG, String.format("更新文件名失败,路径【%s】已存在或文件已下载", newPath));
if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=?", newPath)) {
ALog.w(TAG, String.format("更新文件名失败,路径【%s】被其它任务占用", newPath));
return;
}

@ -35,6 +35,7 @@ public class FtpBuilderTarget extends AbsBuilderTarget<FtpBuilderTarget> {
mConfigHandler = new UNormalConfigHandler<>(this, -1);
mConfigHandler.setFilePath(filePath);
getTaskWrapper().setRequestType(ITaskWrapper.U_FTP);
getTaskWrapper().setNewTask(true);
}
/**

@ -1,5 +1,8 @@
## 开发日志
+ v_3.7.6
+ v_3.7.6 (2019/11/19)
- fix bug https://github.com/AriaLyy/Aria/issues/505
- fix bug https://github.com/AriaLyy/Aria/issues/516
- fix bug https://github.com/AriaLyy/Aria/issues/515
- 增加强制上传的api`forceUpload()`
- 修复for循环上传文件出现的问题
- 移除创建任务的500ms间隔限制

@ -60,6 +60,7 @@ class FtpUFileInfoThread extends AbsFtpInfoThread<UploadEntity, UTaskWrapper> {
@Override protected boolean onInterceptor(FTPClient client, FTPFile[] ftpFiles) {
// 旧任务将不做处理,否则断点续传上传将失效
if (!mTaskWrapper.isNewTask()) {
ALog.d(TAG, "任务是旧任务,忽略该拦截器");
return true;
}
try {

@ -44,20 +44,20 @@ Aria有以下特点:
## 引入库
[![license](http://img.shields.io/badge/license-Apache2.0-brightgreen.svg?style=flat)](https://github.com/AriaLyy/Aria/blob/master/LICENSE)
[![Core](https://img.shields.io/badge/Core-3.7.5-blue)](https://github.com/AriaLyy/Aria)
[![Compiler](https://img.shields.io/badge/Compiler-3.7.5-blue)](https://github.com/AriaLyy/Aria)
[![FtpComponent](https://img.shields.io/badge/FtpComponent-3.7.5-orange)](https://github.com/AriaLyy/Aria)
[![M3U8Component](https://img.shields.io/badge/M3U8Component-3.7.5-orange)](https://github.com/AriaLyy/Aria)
[![Core](https://img.shields.io/badge/Core-3.7.6-blue)](https://github.com/AriaLyy/Aria)
[![Compiler](https://img.shields.io/badge/Compiler-3.7.6-blue)](https://github.com/AriaLyy/Aria)
[![FtpComponent](https://img.shields.io/badge/FtpComponent-3.7.6-orange)](https://github.com/AriaLyy/Aria)
[![M3U8Component](https://img.shields.io/badge/M3U8Component-3.7.6-orange)](https://github.com/AriaLyy/Aria)
```java
implementation 'com.arialyy.aria:core:3.7.5'
annotationProcessor 'com.arialyy.aria:compiler:3.7.5'
implementation 'com.arialyy.aria:ftpComponent:3.7.5' # 如果需要使用ftp,请增加该组件
implementation 'com.arialyy.aria:m3u8Component:3.7.5' # 如果需要使用m3u8下载功能,请增加该组件
implementation 'com.arialyy.aria:core:3.7.6'
annotationProcessor 'com.arialyy.aria:compiler:3.7.6'
implementation 'com.arialyy.aria:ftpComponent:3.7.6' # 如果需要使用ftp,请增加该组件
implementation 'com.arialyy.aria:m3u8Component:3.7.6' # 如果需要使用m3u8下载功能,请增加该组件
```
如果出现android support依赖错误,请将 `compile 'com.arialyy.aria:core:<last-version>'`替换为
```
api('com.arialyy.aria:aria-core:<last-version>'){
api('com.arialyy.aria:core:<last-version>'){
exclude group: 'androidx.appcompat.app'
}
```
@ -65,7 +65,7 @@ api('com.arialyy.aria:aria-core:<last-version>'){
__⚠注意:3.5.4以下版本升级时,需要更新[配置文件](https://aria.laoyuyu.me/aria_doc/start/config.html)!!__
__⚠注意:3.7 以上版本已经适配了AndroidX__
__⚠注意:3.7 以上版本已经适配了AndroidX,如果是使用support库的,可使用[老版本](https://github.com/AriaLyy/Aria/tree/v3.6.6)__
***
## 使用
@ -137,11 +137,14 @@ protected void onCreate(Bundle savedInstanceState) {
### 版本日志
+ v_3.7.5 (2019/11/10)
- fix bug https://github.com/AriaLyy/Aria/issues/500
- fix bug https://github.com/AriaLyy/Aria/issues/508
- fix bug https://github.com/AriaLyy/Aria/issues/503
- 修复m3u8创建索引不成功的问题
+ v_3.7.6 (2019/11/19)
- fix bug https://github.com/AriaLyy/Aria/issues/505
- fix bug https://github.com/AriaLyy/Aria/issues/516
- fix bug https://github.com/AriaLyy/Aria/issues/515
- 增加强制上传的api`forceUpload()`
- 修复for循环上传文件出现的问题
- 移除创建任务的500ms间隔限制
- 修复多线程读写时可能出现的`database is locked`的问题
[更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md)

@ -1,58 +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.sftp;
import com.arialyy.aria.core.inf.OnFileInfoCallback;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSchException;
/**
* 获取sftp文件信息
*
* @author lyy
*/
public class AbsSFtpFileInfoThread<WP extends AbsTaskWrapper> implements Runnable {
private WP mWrapper;
private SFtpUtil mUtil;
private OnFileInfoCallback mCallback;
public AbsSFtpFileInfoThread(SFtpUtil util, WP wrapper, OnFileInfoCallback callback) {
mWrapper = wrapper;
mUtil = util;
mCallback = callback;
}
@Override public void run() {
startFlow();
}
private void startFlow() {
}
private ChannelSftp createChannel() {
ChannelSftp sftp = null;
try {
sftp = (ChannelSftp) mUtil.getSession().openChannel(SFtpUtil.CMD_TYPE_SFTP);
sftp.connect();
} catch (JSchException e) {
e.printStackTrace();
}
return sftp;
}
}

@ -0,0 +1,42 @@
/*
* 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.sftp;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import java.util.Vector;
/**
* sftp文件信息适配器
*/
public abstract class BaseInfoThreadAdapter<WRAPPER extends AbsTaskWrapper> {
private WRAPPER mWrapper;
public BaseInfoThreadAdapter(WRAPPER taskWrapper) {
mWrapper = taskWrapper;
}
public WRAPPER getWrapper() {
return mWrapper;
}
/**
* 处理文件
*
* @return true 处理文件成功false 处理文件失败结束任务
*/
protected abstract boolean handlerFile(Vector vector);
}

@ -16,19 +16,25 @@
package com.arialyy.aria.sftp;
import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.common.AbsNormalEntity;
import com.arialyy.aria.core.inf.OnFileInfoCallback;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.ftp.FtpTaskOption;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.SftpException;
import java.util.Vector;
/**
*
* https://cloud.tencent.com/developer/article/1354612
*
* @author lyy
*/
public class AbsSFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER extends AbsTaskWrapper<ENTITY>>
public class SFtpInfoThread<ENTITY extends AbsNormalEntity, TASK_WRAPPER extends AbsTaskWrapper<ENTITY>>
implements Runnable {
private final String TAG = CommonUtil.getClassName(getClass());
@ -40,8 +46,12 @@ public class AbsSFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER extends Ab
protected long mSize = 0;
protected String charSet = "UTF-8";
private boolean isUpload = false;
private SFtpUtil mSFtpUtil;
private BaseInfoThreadAdapter mAdapter;
public AbsSFtpInfoThread(TASK_WRAPPER taskWrapper, OnFileInfoCallback callback) {
public SFtpInfoThread(SFtpUtil ftpUtil, TASK_WRAPPER taskWrapper,
OnFileInfoCallback callback) {
mSFtpUtil = ftpUtil;
mTaskWrapper = taskWrapper;
mEntity = taskWrapper.getEntity();
mTaskOption = (FtpTaskOption) taskWrapper.getTaskOption();
@ -52,7 +62,39 @@ public class AbsSFtpInfoThread<ENTITY extends AbsEntity, TASK_WRAPPER extends Ab
}
}
public void setAdapter(BaseInfoThreadAdapter adapter) {
mAdapter = adapter;
}
@Override public void run() {
if (mAdapter == null) {
ALog.e(TAG, "adapter为空");
return;
}
try {
ChannelSftp channelSftp =
(ChannelSftp) mSFtpUtil.getSession().openChannel(SFtpUtil.CMD_TYPE_SFTP);
Vector files = channelSftp.ls(getUrlEntity().remotePath);
if (files.isEmpty()) {
ALog.e(TAG, String.format("路径【%s】没有文件", getUrlEntity().remotePath));
mCallback.onFail(mEntity, null, false);
return;
}
if (!mAdapter.handlerFile(files)) {
ALog.e(TAG, "文件处理失败");
mCallback.onFail(mEntity, null, false);
return;
}
} catch (JSchException ex) {
ex.printStackTrace();
} catch (SftpException e) {
e.printStackTrace();
}
}
private FtpUrlEntity getUrlEntity() {
return mTaskOption.getUrlEntity();
}
}

@ -0,0 +1,31 @@
/*
* 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.sftp.download;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.sftp.BaseInfoThreadAdapter;
import java.util.Vector;
final class DSFtpInfoThreadAdapter extends BaseInfoThreadAdapter<DTaskWrapper> {
DSFtpInfoThreadAdapter(DTaskWrapper taskWrapper) {
super(taskWrapper);
}
@Override protected boolean handlerFile(Vector vector) {
return false;
}
}

@ -26,7 +26,7 @@ import com.arialyy.aria.core.loader.NormalLoader;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.ftp.FtpTaskOption;
import com.arialyy.aria.sftp.AbsSFtpFileInfoThread;
import com.arialyy.aria.sftp.SFtpInfoThread;
import com.arialyy.aria.sftp.SFtpUtil;
/**
@ -57,15 +57,19 @@ public class SFtpDLoaderUtil extends AbsNormalLoaderUtil {
}
@Override protected Runnable createInfoThread() {
return new AbsSFtpFileInfoThread<>(mSftpUtil, (DTaskWrapper) getTaskWrapper(), new OnFileInfoCallback() {
DSFtpInfoThreadAdapter adapter = new DSFtpInfoThreadAdapter((DTaskWrapper) getTaskWrapper());
SFtpInfoThread infoThread = new SFtpInfoThread<>(mSftpUtil, (DTaskWrapper) getTaskWrapper(),
new OnFileInfoCallback() {
@Override public void onComplete(String key, CompleteInfo info) {
}
@Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) {
mSftpUtil.logout();
}
});
infoThread.setAdapter(adapter);
return infoThread;
}
}

@ -95,13 +95,13 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
mTaskId = Aria.download(this)
.loadGroup(mUrls)
.setDirPath(
Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_2")
.setGroupAlias("任务组测试")
Environment.getExternalStorageDirectory().getPath() + "/Download/group_imgs")
.setGroupAlias("图片测试")
//.setSubFileName(getModule(GroupModule.class).getSubName2())
.setSubFileName(getModule(GroupModule.class).getSubName())
//.setSubFileName(getModule(GroupModule.class).getSubName())
.unknownSize()
.option(getHttpOption())
.setFileSize(114981416)
//.setFileSize(114981416)
//.updateUrls(temp)
.create();
getBinding().setStateStr(getString(R.string.stop));

@ -32,8 +32,10 @@ public class GroupModule extends BaseModule {
public List<String> getUrls() {
List<String> urls = new ArrayList<>();
String[] str = getContext().getResources().getStringArray(R.array.group_urls_1);
Collections.addAll(urls, str);
urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574141924275&di=a7ea1497a4a2528a45ce7103bf61adf4&imgtype=0&src=http%3A%2F%2Fg.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2Fc2cec3fdfc03924590b2a9b58d94a4c27d1e2500.jpg");
urls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574141924272&di=7861479e7cb3cea98d585eaf108f056f&imgtype=0&src=http%3A%2F%2Fd.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F562c11dfa9ec8a13c0741f5afd03918fa0ecc01a.jpg");
//String[] str = getContext().getResources().getStringArray(R.array.group_urls_1);
//Collections.addAll(urls, str);
return urls;
}

@ -28,6 +28,8 @@ import com.arialyy.annotations.Upload;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.processor.FtpInterceptHandler;
import com.arialyy.aria.core.processor.IFtpUploadInterceptor;
import com.arialyy.aria.core.task.UploadTask;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.util.ALog;
@ -114,26 +116,27 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
//if (mTaskId == -1) {
// mTaskId = Aria.upload(this)
// .loadFtp(mFilePath)
// .setUploadUrl(mUrl)
// .option(getOption())
// .create();
// getBinding().setStateStr(getString(R.string.stop));
// break;
//}
//if (Aria.upload(this).loadFtp(mTaskId).isRunning()) {
// Aria.upload(this).loadFtp(mTaskId).stop();
// getBinding().setStateStr(getString(R.string.resume));
//} else {
// Aria.upload(this)
// .loadFtp(mTaskId)
// .option(getOption())
// .resume();
// getBinding().setStateStr(getString(R.string.stop));
//}
upload();
if (mTaskId == -1) {
mTaskId = Aria.upload(this)
.loadFtp(mFilePath)
.setUploadUrl(mUrl)
.option(getOption())
.forceUpload()
.create();
getBinding().setStateStr(getString(R.string.stop));
break;
}
if (Aria.upload(this).loadFtp(mTaskId).isRunning()) {
Aria.upload(this).loadFtp(mTaskId).stop();
getBinding().setStateStr(getString(R.string.resume));
} else {
Aria.upload(this)
.loadFtp(mTaskId)
.option(getOption())
.resume();
getBinding().setStateStr(getString(R.string.stop));
}
//upload();
break;
case R.id.cancel:
Aria.upload(this).loadFtp(mTaskId).cancel();
@ -168,6 +171,7 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
private FtpOption getOption() {
FtpOption option = new FtpOption();
option.login(user, pwd);
option.setUploadInterceptor(new FtpUploadInterceptor());
return option;
}
@ -236,4 +240,13 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
}
}
}
private static class FtpUploadInterceptor implements IFtpUploadInterceptor {
@Override public FtpInterceptHandler onIntercept(UploadEntity entity, List<String> fileList) {
FtpInterceptHandler.Builder builder = new FtpInterceptHandler.Builder();
//builder.coverServerFile(); // 覆盖远端同名文件
builder.resetFileName("test.zip"); //修改上传到远端服务器的文件名
return builder.build();
}
}
}

@ -37,7 +37,7 @@ public class UploadModule extends BaseViewModule {
LiveData<UploadEntity> getFtpInfo(Context context) {
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() + "/Download/PaNTFS15562.zip");
Environment.getExternalStorageDirectory().getPath() + "/Download/Folx P58.zip");
UploadEntity entity = Aria.upload(context).getFirstUploadEntity(filePath);
if (entity != null) {

@ -44,8 +44,8 @@ task clean(type: Delete) {
}
ext {
versionCode = 375
versionName = '3.7.5'
versionCode = 376
versionName = '3.7.6'
userOrg = 'arialyy'
groupId = 'com.arialyy.aria'
publishVersion = versionName

Loading…
Cancel
Save