修复ftp文件夹下载失败的问题
This commit is contained in:
@@ -23,7 +23,8 @@ import com.arialyy.aria.core.inf.IEntity;
|
|||||||
import com.arialyy.aria.exception.BaseException;
|
import com.arialyy.aria.exception.BaseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Aria.Lao on 2017/7/27. ftp文件夹下载工具
|
* Created by Aria.Lao on 2017/7/27.
|
||||||
|
* ftp文件夹下载工具
|
||||||
*/
|
*/
|
||||||
public class FtpDirDownloadUtil extends AbsGroupUtil {
|
public class FtpDirDownloadUtil extends AbsGroupUtil {
|
||||||
private String TAG = "FtpDirDownloadUtil";
|
private String TAG = "FtpDirDownloadUtil";
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ class FtpDirInfoThread extends AbsFtpInfoThread<DownloadGroupEntity, DGTaskWrapp
|
|||||||
new String(fileName.getBytes(), Charset.forName(mTaskWrapper.asHttp().getCharSet())));
|
new String(fileName.getBytes(), Charset.forName(mTaskWrapper.asHttp().getCharSet())));
|
||||||
entity.setGroupHash(mEntity.getGroupHash());
|
entity.setGroupHash(mEntity.getGroupHash());
|
||||||
entity.setGroupChild(true);
|
entity.setGroupChild(true);
|
||||||
|
entity.setConvertFileSize(CommonUtil.formatFileSize(ftpFile.getSize()));
|
||||||
entity.setFileSize(ftpFile.getSize());
|
entity.setFileSize(ftpFile.getSize());
|
||||||
entity.insert();
|
entity.insert();
|
||||||
|
|
||||||
|
|||||||
@@ -23,13 +23,16 @@ import com.arialyy.aria.core.download.DTaskWrapper;
|
|||||||
import com.arialyy.aria.core.download.DownloadEntity;
|
import com.arialyy.aria.core.download.DownloadEntity;
|
||||||
import com.arialyy.aria.core.download.downloader.Downloader;
|
import com.arialyy.aria.core.download.downloader.Downloader;
|
||||||
import com.arialyy.aria.core.download.downloader.HttpFileInfoThread;
|
import com.arialyy.aria.core.download.downloader.HttpFileInfoThread;
|
||||||
|
import com.arialyy.aria.core.inf.AbsTaskWrapper;
|
||||||
import com.arialyy.aria.core.scheduler.ISchedulers;
|
import com.arialyy.aria.core.scheduler.ISchedulers;
|
||||||
import com.arialyy.aria.exception.BaseException;
|
import com.arialyy.aria.exception.BaseException;
|
||||||
|
import com.arialyy.aria.util.ALog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 子任务下载工具,负责创建{@link Downloader}
|
* 子任务下载器,负责创建{@link Downloader}
|
||||||
*/
|
*/
|
||||||
class SubDownloadLoader implements IUtil {
|
class SubDownloadLoader implements IUtil {
|
||||||
|
private final String TAG = "SubDownloadLoader";
|
||||||
|
|
||||||
private Downloader mDownloader;
|
private Downloader mDownloader;
|
||||||
private DTaskWrapper mWrapper;
|
private DTaskWrapper mWrapper;
|
||||||
@@ -88,17 +91,24 @@ class SubDownloadLoader implements IUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public void start() {
|
@Override public void start() {
|
||||||
new Thread(new HttpFileInfoThread(mWrapper, new OnFileInfoCallback() {
|
if (mWrapper.getRequestType() == AbsTaskWrapper.D_HTTP) {
|
||||||
|
new Thread(new HttpFileInfoThread(mWrapper, new OnFileInfoCallback() {
|
||||||
|
|
||||||
@Override public void onComplete(String url, CompleteInfo info) {
|
@Override public void onComplete(String url, CompleteInfo info) {
|
||||||
mDownloader = new Downloader(mListener, mWrapper);
|
mDownloader = new Downloader(mListener, mWrapper);
|
||||||
mDownloader.start();
|
mDownloader.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onFail(String url, BaseException e, boolean needRetry) {
|
@Override public void onFail(String url, BaseException e, boolean needRetry) {
|
||||||
mSchedulers.obtainMessage(ISchedulers.FAIL, SubDownloadLoader.this);
|
mSchedulers.obtainMessage(ISchedulers.FAIL, SubDownloadLoader.this);
|
||||||
}
|
}
|
||||||
})).start();
|
})).start();
|
||||||
|
} else if (mWrapper.getRequestType() == AbsTaskWrapper.D_FTP) {
|
||||||
|
mDownloader = new Downloader(mListener, mWrapper);
|
||||||
|
mDownloader.start();
|
||||||
|
} else {
|
||||||
|
ALog.w(TAG, String.format("不识别的类型,requestType:%s", mWrapper.getRequestType()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void resume() {
|
@Override public void resume() {
|
||||||
|
|||||||
@@ -25,29 +25,29 @@ public interface ITaskWrapper<ENTITY extends AbsEntity> {
|
|||||||
/**
|
/**
|
||||||
* HTTP单任务载
|
* HTTP单任务载
|
||||||
*/
|
*/
|
||||||
int D_HTTP = 0x11;
|
int D_HTTP = 1;
|
||||||
/**
|
/**
|
||||||
* HTTP任务组下载
|
* HTTP任务组下载
|
||||||
*/
|
*/
|
||||||
int DG_HTTP = 0x12;
|
int DG_HTTP = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FTP单文件下载
|
* FTP单文件下载
|
||||||
*/
|
*/
|
||||||
int D_FTP = 0x13;
|
int D_FTP = 3;
|
||||||
/**
|
/**
|
||||||
* FTP文件夹下载,为避免登录过多,子任务由单线程进行处理
|
* FTP文件夹下载,为避免登录过多,子任务由单线程进行处理
|
||||||
*/
|
*/
|
||||||
int D_FTP_DIR = 0x14;
|
int D_FTP_DIR = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP单文件上传
|
* HTTP单文件上传
|
||||||
*/
|
*/
|
||||||
int U_HTTP = 0xA1;
|
int U_HTTP = 5;
|
||||||
/**
|
/**
|
||||||
* FTP单文件上传
|
* FTP单文件上传
|
||||||
*/
|
*/
|
||||||
int U_FTP = 0xA2;
|
int U_FTP = 6;
|
||||||
|
|
||||||
ENTITY getEntity();
|
ENTITY getEntity();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,7 +141,6 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UTaskWrapper> {
|
|||||||
* 上传
|
* 上传
|
||||||
*
|
*
|
||||||
* @return {@code true}上传成功、{@code false} 上传失败
|
* @return {@code true}上传成功、{@code false} 上传失败
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
private boolean upload(final FTPClient client, final BufferedRandomAccessFile bis)
|
private boolean upload(final FTPClient client, final BufferedRandomAccessFile bis)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
|
|||||||
.setFilePath("/mnt/sdcard/").start();
|
.setFilePath("/mnt/sdcard/").start();
|
||||||
break;
|
break;
|
||||||
case R.id.stop:
|
case R.id.stop:
|
||||||
Aria.download(this).loadFtp(URL);
|
Aria.download(this).loadFtp(URL).stop();
|
||||||
break;
|
break;
|
||||||
case R.id.cancel:
|
case R.id.cancel:
|
||||||
Aria.download(this).loadFtp(URL).cancel();
|
Aria.download(this).loadFtp(URL).cancel();
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import com.arialyy.simple.widget.SubStateLinearLayout;
|
|||||||
* Created by lyy on 2017/7/6.
|
* Created by lyy on 2017/7/6.
|
||||||
*/
|
*/
|
||||||
public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBinding> {
|
public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBinding> {
|
||||||
private static final String dir = "ftp://192.168.1.2:21/upload/测试";
|
private static final String dir = "ftp://9.9.9.50:21/upload/测试";
|
||||||
|
|
||||||
@Bind(R.id.child_list) SubStateLinearLayout mChildList;
|
@Bind(R.id.child_list) SubStateLinearLayout mChildList;
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
|
|||||||
super.init(savedInstanceState);
|
super.init(savedInstanceState);
|
||||||
Aria.upload(this).register();
|
Aria.upload(this).register();
|
||||||
UploadEntity entity = Aria.upload(this).getUploadEntity(FILE_PATH);
|
UploadEntity entity = Aria.upload(this).getUploadEntity(FILE_PATH);
|
||||||
ALog.d(TAG, "pare = >" + entity.getPercent());
|
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
|
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||||
getBinding().setProgress(entity.isComplete() ? 100
|
getBinding().setProgress(entity.isComplete() ? 100
|
||||||
|
|||||||
Reference in New Issue
Block a user