From 88dfa7eedc7eaa0496691afc5784059c33ff4a53 Mon Sep 17 00:00:00 2001 From: e <511455842@qq.com> Date: Thu, 1 Feb 2018 20:06:35 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86ftp?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=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/build.gradle | 4 +- .../com/arialyy/aria/core/AriaManager.java | 2 - .../aria/core/common/AbsFtpInfoThread.java | 23 +++++++--- .../aria/core/common/AbsFtpThreadTask.java | 5 +- .../download/downloader/FtpThreadTask.java | 21 +++++++-- .../core/upload/uploader/FtpThreadTask.java | 25 ++++++++-- .../com/arialyy/aria/util/CommonUtil.java | 3 +- DEV_LOG.md | 2 +- README.md | 16 ++++--- .../simple/download/FtpDownloadActivity.java | 7 +-- .../simple/download/SingleTaskActivity.java | 46 +++++++++---------- 11 files changed, 99 insertions(+), 55 deletions(-) diff --git a/Aria/build.gradle b/Aria/build.gradle index 4d7ee364..f95e9d8f 100644 --- a/Aria/build.gradle +++ b/Aria/build.gradle @@ -23,8 +23,8 @@ dependencies { testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile project(':AriaAnnotations') - compile 'com.arialyy.aria:aria-ftp-plug:1.0.3' +// compile 'com.arialyy.aria:aria-ftp-plug:1.0.3' -// compile project(':AriaFtpPlug') + compile project(':AriaFtpPlug') } apply from: 'bintray-release.gradle' diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index e52c90c8..9f7316c5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -69,8 +69,6 @@ import org.xml.sax.SAXException; public static final String DOWNLOAD_TEMP_DIR = "/Aria/temp/download/"; public static final String UPLOAD_TEMP_DIR = "/Aria/temp/upload/"; - - @SuppressLint("StaticFieldLeak") private static volatile AriaManager INSTANCE = null; private Map mReceivers = new ConcurrentHashMap<>(); public static Context APP; diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java index 18911a09..c118475e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java @@ -23,6 +23,7 @@ import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.Regular; +import java.io.File; import java.io.IOException; import java.net.InetAddress; import java.util.regex.Matcher; @@ -77,11 +78,18 @@ public abstract class AbsFtpInfoThread 0) { ALog.i(TAG, "路径【" + setRemotePath() + "】下的文件列表 ==================================="); for (FTPFile file : files1) { @@ -89,7 +97,7 @@ public abstract class AbsFtpInfoThread + "】"); client = createClient(); if (client == null) return; - client.setRestartOffset(mConfig.START_LOCATION); + if (mConfig.START_LOCATION > 0) { + client.setRestartOffset(mConfig.START_LOCATION); + } + //发送第二次指令时,还需要再做一次判断 + int reply = client.getReplyCode(); + if (reply == FTPReply.SYNTAX_ERROR_IN_ARGUMENTS) { + ALog.e(TAG, "FTP没有打开写权限,断点续传失败,将从0开始读文件"); + } else if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) { + client.disconnect(); + fail(mChildCurrentLocation, "获取文件信息错误,错误码为:" + reply + ",msg:" + client.getReplyString(), + null); + return; + } String remotePath = new String(mTaskEntity.urlEntity.remotePath.getBytes(charSet), SERVER_CHARSET); is = client.retrieveFileStream(remotePath); - //发送第二次指令时,还需要再做一次判断 - int reply = client.getReplyCode(); + reply = client.getReplyCode(); if (!FTPReply.isPositivePreliminary(reply)) { client.disconnect(); - fail(mChildCurrentLocation, "获取文件信息错误,错误码为:" + reply, null); + fail(mChildCurrentLocation, "获取流失败,错误码为:" + reply + ",msg:" + client.getReplyString(), + null); return; } + file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize); file.seek(mConfig.START_LOCATION); byte[] buffer = new byte[mBufSize]; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java index ed15bed1..afc80187 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java @@ -61,9 +61,28 @@ class FtpThreadTask extends AbsFtpThreadTask { client = createClient(); if (client == null) return; initPath(); - client.makeDirectory(dir); - client.changeWorkingDirectory(dir); + if (client.makeDirectory(dir)) { + fail(mChildCurrentLocation, "创建文件夹失败", null); + return; + } + if (client.changeWorkingDirectory(dir)) { + fail(mChildCurrentLocation, "选择工作文件夹失败", null); + return; + } client.setRestartOffset(mConfig.START_LOCATION); + int reply = client.getReplyCode(); + if (reply == FTPReply.SYNTAX_ERROR_IN_ARGUMENTS) { + client.disconnect(); + fail(mChildCurrentLocation, + "上传失败,FTP没有打开写权限,错误码为:" + reply + ",msg:" + client.getReplyString(), null); + return; + } else if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) { + client.disconnect(); + fail(mChildCurrentLocation, + "上传失败,FTP没有打开写权限,错误码为:" + reply + ",msg:" + client.getReplyString(), null); + return; + } + file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize); if (mConfig.START_LOCATION != 0) { //file.skipBytes((int) mConfig.START_LOCATION); @@ -82,7 +101,7 @@ class FtpThreadTask extends AbsFtpThreadTask { STATE.isRunning = false; mListener.onComplete(); } - if (STATE.isFail()){ + if (STATE.isFail()) { STATE.isRunning = false; mListener.onFail(false); } diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index 090f8cd0..ee215f6f 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -103,7 +103,8 @@ public class CommonUtil { entity.hostName = str; } entity.port = m.group(3); - entity.remotePath = TextUtils.isEmpty(m.group(4)) ? "/" : "/" + m.group(4); + //entity.remotePath = TextUtils.isEmpty(m.group(4)) ? "/" : "/" + m.group(4); + entity.remotePath = TextUtils.isEmpty(m.group(4)) ? "/" : m.group(4); } return entity; } diff --git a/DEV_LOG.md b/DEV_LOG.md index 35476cb2..1c40411b 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,5 +1,5 @@ ## 开发日志 - + v_3.3.12 + + v_3.3.13 - 添加`@Download.onWait、@Upload.onWait、@DownloadGroup.onWait`三个新注解,队列已经满了,继续创建新任务,任务处于等待中,将会执行被这三个注解标志的方法 - app被kill,但是还存在等待中的任务A;第二次重新启动,先创建一个新的任务B,Aria会自动把B放进等待队列中,这时再次创建任务A,会导致重复下载,进度错乱的问题;本版本已修复这个问题 + v_3.3.11 diff --git a/README.md b/README.md index 7b80914a..5227aad2 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ Aria有以下特点: compile 'com.arialyy.aria:aria-core:3.3.13' annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.13' ``` +如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:3.3.13'`替换为 +``` +compile('com.arialyy.aria:'){ + exclude group: 'com.android.support' +} +``` 如果你使用的是kotlin,请使用kotlin官方提供的方法配置apt,[kotlin kapt官方配置传送门](https://www.kotlincn.net/docs/reference/kapt.html) *** @@ -97,12 +103,10 @@ protected void onCreate(Bundle savedInstanceState) { ### [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki) ### 版本日志 -+ v_3.3.11 - - 添加进度更新间隔api,在`aria_config.xml`配置``或在代码中调用 - `AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setUpdateInterval(3000)`便可以改变进度刷新间隔 - - 修复下载过程中kill进程可能出现的文件错误的问题 https://github.com/AriaLyy/Aria/issues/192 - - 修复http上传的空指针问题 https://github.com/AriaLyy/Aria/issues/193 - - 修复下载地址中含有`'`导致的崩溃问题 https://github.com/AriaLyy/Aria/issues/194 ++ v_3.3.13 + - 添加`@Download.onWait、@Upload.onWait、@DownloadGroup.onWait`三个新注解,队列已经满了,继续创建新任务,任务处于等待中,将会执行被这三个注解标志的方法 + - app被kill,但是还存在等待中的任务A;第二次重新启动,先创建一个新的任务B,Aria会自动把B放进等待队列中,这时再次创建任务A,会导致重复下载,进度错乱的问题;本版本已修复这个问题 + [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java index 1b4827e8..500995ae 100644 --- a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java @@ -38,7 +38,8 @@ public class FtpDownloadActivity extends BaseActivity { //"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe"; //"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; //"http://sitcac.daxincf.cn/wp-content/uploads/swift_vido/01/element.mp4_1"; - //"http://120.25.196.56:8000/filereq?id=15692406294&ipncid=105635&client=android&filename=20170819185541.avi"; - //"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt"; - //"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815"; - //"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk"; - //"http://oqcpqqvuf.bkt.clouddn.com/ceshi.txt"; - //"http://down8.androidgame-store.com/201706122321/97967927DD4E53D9905ECAA7874C8128/new/game1/19/45319/com.neuralprisma-2.5.2.174-2000174_1494784835.apk?f=web_1"; - //不支持断点的链接 - //"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-"; - //"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk"; - //"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2"; - "https://bogoe-res.mytbz.com/tbzengsong/If You're Happy.mp3"; + //"http://120.25.196.56:8000/filereq?id=15692406294&ipncid=105635&client=android&filename=20170819185541.avi"; + //"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt"; + //"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815"; + //"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk"; + //"http://oqcpqqvuf.bkt.clouddn.com/ceshi.txt"; + //"http://down8.androidgame-store.com/201706122321/97967927DD4E53D9905ECAA7874C8128/new/game1/19/45319/com.neuralprisma-2.5.2.174-2000174_1494784835.apk?f=web_1"; + //不支持断点的链接 + //"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-"; + //"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk"; + //"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2"; + //"https://bogoe-res.mytbz.com/tbzengsong/If You're Happy.mp3"; + "http://ozr0ucjs5.bkt.clouddn.com/51_box-104_20180131202610.apk"; @Bind(R.id.start) Button mStart; @Bind(R.id.stop) Button mStop; @Bind(R.id.cancel) Button mCancel; @@ -122,7 +118,7 @@ public class SingleTaskActivity extends BaseActivity { return true; } - @Download.onWait void onWait(DownloadTask task){ + @Download.onWait void onWait(DownloadTask task) { Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName()); } @@ -177,12 +173,12 @@ public class SingleTaskActivity extends BaseActivity { mCancel.setEnabled(false); setBtState(true); getBinding().setSpeed(""); + L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath()); L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath()))); L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL)); } - @Download.onNoSupportBreakPoint - public void onNoSupportBreakPoint(DownloadTask task) { + @Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) { T.showShort(SingleTaskActivity.this, "该下载链接不支持断点"); } @@ -221,12 +217,14 @@ public class SingleTaskActivity extends BaseActivity { } } - private void startD(){ + private void startD() { //Aria.get(this).setLogLevel(ALog.LOG_CLOSE); //Aria.download(this).load("aaaa.apk"); Map map = new HashMap<>(); - map.put("User-Agent", "Mozilla/5.0 (Linux; Android 4.4.4; Nexus 5 Build/KTU84P; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 Mobile MQQBrowser/6.2 TBS/043722 Safari/537.36"); - map.put("Cookie", "BAIDUID=DFC7EF42C60AD1ACF0BA94389AA67F13:FG=1; H_WISE_SIDS=121192_104493_114745_121434_119046_100098_120212_121140_118882_118858_118850_118820_118792_121254_121534_121214_117588_117242_117431_119974_120597_121043_121422_120943_121175_121272_117552_120482_121013_119962_119145_120851_120841_120034_121325_116407_121109_120654_110085_120708; PSINO=7; BDORZ=AE84CDB3A529C0F8A2B9DCDD1D18B695"); + map.put("User-Agent", + "Mozilla/5.0 (Linux; Android 4.4.4; Nexus 5 Build/KTU84P; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 Mobile MQQBrowser/6.2 TBS/043722 Safari/537.36"); + map.put("Cookie", + "BAIDUID=DFC7EF42C60AD1ACF0BA94389AA67F13:FG=1; H_WISE_SIDS=121192_104493_114745_121434_119046_100098_120212_121140_118882_118858_118850_118820_118792_121254_121534_121214_117588_117242_117431_119974_120597_121043_121422_120943_121175_121272_117552_120482_121013_119962_119145_120851_120841_120034_121325_116407_121109_120654_110085_120708; PSINO=7; BDORZ=AE84CDB3A529C0F8A2B9DCDD1D18B695"); Aria.download(SingleTaskActivity.this) .load(DOWNLOAD_URL) //.addHeader("groupName", "value") @@ -234,8 +232,8 @@ public class SingleTaskActivity extends BaseActivity { //.setRequestMode(RequestEnum.POST) .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk") .resetState() - //.start(); - .add(); + .start(); + //.add(); } @Override protected void onDestroy() { From 516fe9e5981fad2a0f3686941a0896abc67c2a1e Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Thu, 1 Feb 2018 22:26:46 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=9F=90=E4=BA=9Bftp?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=EF=BC=8C=E8=87=AA=E5=8A=A8=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Durl=E4=B8=AD=E7=9A=84//?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria/build.gradle | 4 +-- .../aria/core/common/AbsFtpInfoThread.java | 2 +- .../aria/core/download/DownloadReceiver.java | 10 +++--- .../download/downloader/FtpThreadTask.java | 11 +++---- .../downloader/HttpFileInfoThread.java | 6 ++-- .../aria/core/inf/AbsUploadTarget.java | 2 +- .../aria/core/upload/FtpUploadTarget.java | 16 ++++++++-- .../core/upload/uploader/FtpThreadTask.java | 31 +++++++------------ .../java/com/arialyy/aria/util/CheckUtil.java | 19 +++++++++--- DEV_LOG.md | 3 ++ README.md | 2 +- .../simple/download/FtpDownloadActivity.java | 9 ++++-- .../simple/download/SingleTaskActivity.java | 2 +- .../simple/upload/FtpUploadActivity.java | 6 ++-- 14 files changed, 72 insertions(+), 51 deletions(-) diff --git a/Aria/build.gradle b/Aria/build.gradle index f95e9d8f..f45db0b2 100644 --- a/Aria/build.gradle +++ b/Aria/build.gradle @@ -22,8 +22,8 @@ dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' - compile project(':AriaAnnotations') -// compile 'com.arialyy.aria:aria-ftp-plug:1.0.3' +// compile project(':AriaAnnotations') + compile 'com.arialyy.aria:aria-ftp-plug:1.0.3' compile project(':AriaFtpPlug') } diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java index c118475e..7275ebd8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java @@ -79,7 +79,7 @@ public abstract class AbsFtpInfoThread */ @Deprecated public DownloadTarget load(@NonNull String url, boolean refreshInfo) { - CheckUtil.checkUrl(url); + url = CheckUtil.checkUrl(url); return new DownloadTarget(url, targetName, refreshInfo); } @@ -165,7 +165,7 @@ public class DownloadReceiver extends AbsReceiver { * @param refreshInfo 是否刷新下载信息 */ public FtpDownloadTarget loadFtp(@NonNull String url, boolean refreshInfo) { - CheckUtil.checkUrl(url); + url = CheckUtil.checkUrl(url); return new FtpDownloadTarget(url, targetName, refreshInfo); } @@ -183,7 +183,7 @@ public class DownloadReceiver extends AbsReceiver { * 加载ftp文件夹下载地址 */ public FtpDirDownloadTarget loadFtpDir(@NonNull String dirUrl) { - CheckUtil.checkUrl(dirUrl); + dirUrl = CheckUtil.checkUrl(dirUrl); return new FtpDirDownloadTarget(dirUrl, targetName); } @@ -239,7 +239,7 @@ public class DownloadReceiver extends AbsReceiver { * 通过下载链接获取下载实体 */ public DownloadEntity getDownloadEntity(String downloadUrl) { - CheckUtil.checkUrl(downloadUrl); + downloadUrl = CheckUtil.checkUrl(downloadUrl); return DbEntity.findFirst(DownloadEntity.class, "url=? and isGroupChild='false'", downloadUrl); } @@ -247,7 +247,7 @@ public class DownloadReceiver extends AbsReceiver { * 通过下载链接获取保存在数据库的下载任务实体 */ public DownloadTaskEntity getDownloadTask(String downloadUrl) { - CheckUtil.checkUrl(downloadUrl); + downloadUrl = CheckUtil.checkUrl(downloadUrl); DownloadEntity entity = getDownloadEntity(downloadUrl); if (entity == null || TextUtils.isEmpty(entity.getDownloadPath())) return null; return DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'", diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java index 4539e82e..48fb66f8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java @@ -34,7 +34,7 @@ import org.apache.commons.net.ftp.FTPReply; * Ftp下载任务 */ class FtpThreadTask extends AbsFtpThreadTask { - private final String TAG = "FtpThreadTask"; + private final String TAG = "FtpDownloadThreadTask"; FtpThreadTask(StateConstance constance, IDownloadListener listener, SubThreadConfig downloadInfo) { @@ -64,22 +64,21 @@ class FtpThreadTask extends AbsFtpThreadTask } //发送第二次指令时,还需要再做一次判断 int reply = client.getReplyCode(); - if (reply == FTPReply.SYNTAX_ERROR_IN_ARGUMENTS) { - ALog.e(TAG, "FTP没有打开写权限,断点续传失败,将从0开始读文件"); - } else if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) { - client.disconnect(); + if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) { fail(mChildCurrentLocation, "获取文件信息错误,错误码为:" + reply + ",msg:" + client.getReplyString(), null); + client.disconnect(); return; } String remotePath = new String(mTaskEntity.urlEntity.remotePath.getBytes(charSet), SERVER_CHARSET); + ALog.i(TAG, "remotePath【" + remotePath + "】"); is = client.retrieveFileStream(remotePath); reply = client.getReplyCode(); if (!FTPReply.isPositivePreliminary(reply)) { - client.disconnect(); fail(mChildCurrentLocation, "获取流失败,错误码为:" + reply + ",msg:" + client.getReplyString(), null); + client.disconnect(); return; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java index 64aa80ca..c2cdafd0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java @@ -16,12 +16,12 @@ package com.arialyy.aria.core.download.downloader; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.util.ALog; +import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; import java.io.IOException; import java.net.HttpURLConnection; @@ -130,12 +130,14 @@ class HttpFileInfoThread implements Runnable { private void handle302Turn(HttpURLConnection conn) throws IOException { String newUrl = conn.getHeaderField(mTaskEntity.redirectUrlKey); ALog.d(TAG, "30x跳转,location【 " + mTaskEntity.redirectUrlKey + "】" + "新url为【" + newUrl + "】"); - if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null")) { + if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null") || !newUrl.startsWith( + "http")) { if (onFileInfoListener != null) { onFileInfoListener.onFail(mEntity.getUrl(), "获取重定向链接失败", false); } return; } + newUrl = CheckUtil.checkUrl(newUrl); String cookies = conn.getHeaderField("Set-Cookie"); conn = (HttpURLConnection) new URL(newUrl).openConnection(); conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsUploadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsUploadTarget.java index bfa627e9..be6541f1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsUploadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsUploadTarget.java @@ -35,7 +35,7 @@ public abstract class AbsUploadTarget { - private final String TAG = "FtpThreadTask"; + private final String TAG = "FtpUploadThreadTask"; private String dir, remotePath; FtpThreadTask(StateConstance constance, IEventListener listener, @@ -61,25 +61,13 @@ class FtpThreadTask extends AbsFtpThreadTask { client = createClient(); if (client == null) return; initPath(); - if (client.makeDirectory(dir)) { - fail(mChildCurrentLocation, "创建文件夹失败", null); - return; - } - if (client.changeWorkingDirectory(dir)) { - fail(mChildCurrentLocation, "选择工作文件夹失败", null); - return; - } + client.makeDirectory(dir); + client.changeWorkingDirectory(dir); client.setRestartOffset(mConfig.START_LOCATION); int reply = client.getReplyCode(); - if (reply == FTPReply.SYNTAX_ERROR_IN_ARGUMENTS) { + if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.FILE_ACTION_OK) { + fail(mChildCurrentLocation, "上传失败,错误码为:" + reply + ",msg:" + client.getReplyString(), null); client.disconnect(); - fail(mChildCurrentLocation, - "上传失败,FTP没有打开写权限,错误码为:" + reply + ",msg:" + client.getReplyString(), null); - return; - } else if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) { - client.disconnect(); - fail(mChildCurrentLocation, - "上传失败,FTP没有打开写权限,错误码为:" + reply + ",msg:" + client.getReplyString(), null); return; } @@ -126,7 +114,7 @@ class FtpThreadTask extends AbsFtpThreadTask { private void initPath() throws UnsupportedEncodingException { dir = new String(mTaskEntity.urlEntity.remotePath.getBytes(charSet), SERVER_CHARSET); remotePath = new String( - (mTaskEntity.urlEntity.remotePath + "/" + mEntity.getFileName()).getBytes(charSet), + ("/" + mTaskEntity.urlEntity.remotePath + mEntity.getFileName()).getBytes(charSet), SERVER_CHARSET); } @@ -134,6 +122,7 @@ class FtpThreadTask extends AbsFtpThreadTask { throws IOException { try { + ALog.d(TAG, "remotePath【" + remotePath + "】"); client.storeFile(remotePath, new FtpFISAdapter(bis), new OnFtpInputStreamListener() { boolean isStoped = false; @@ -160,11 +149,13 @@ class FtpThreadTask extends AbsFtpThreadTask { int reply = client.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { + if (reply != FTPReply.TRANSFER_ABORTED) { + fail(mChildCurrentLocation, "上传文件错误,错误码为:" + reply + ",msg:" + client.getReplyString(), + null); + } if (client.isConnected()) { client.disconnect(); } - if (reply == FTPReply.TRANSFER_ABORTED) return; - fail(mChildCurrentLocation, "上传文件错误,错误码为:" + reply, null); } } diff --git a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java index 93eed2b9..103a5153 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java @@ -74,7 +74,7 @@ public class CheckUtil { * 检查下载实体 */ public static void checkDownloadEntity(DownloadEntity entity) { - checkUrl(entity.getUrl()); + entity.setUrl(checkUrl(entity.getUrl())); checkPath(entity.getDownloadPath()); } @@ -88,14 +88,25 @@ public class CheckUtil { } /** - * 检测下载链接是否为null + * 检测下载链接是否合法,如果地址中path是"//"而不是"/"将会改为"/"; */ - public static void checkUrl(String url) { + public static String checkUrl(String url) { if (TextUtils.isEmpty(url)) { - throw new IllegalArgumentException("下载链接不能为null"); + throw new IllegalArgumentException("url不能为null"); } else if (!url.startsWith("http") && !url.startsWith("ftp")) { throw new IllegalArgumentException("url错误"); } + int index = url.indexOf("://"); + if (index == -1) { + throw new IllegalArgumentException("url不合法"); + } + String temp = url.substring(index + 3, url.length()); + if (temp.contains("//")) { + temp = url.substring(0, index + 3) + temp.replaceAll("//", "/"); + ALog.w(TAG, "url中含有//,//将转换为/,转换后的url为:" + temp); + return temp; + } + return url; } /** diff --git a/DEV_LOG.md b/DEV_LOG.md index 1c40411b..26aed643 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,4 +1,7 @@ ## 开发日志 + + v_3.3.14 + - 修复ftp上传和下载的兼容性问题 + - 如果url中的path有"//"将替换为"/" + v_3.3.13 - 添加`@Download.onWait、@Upload.onWait、@DownloadGroup.onWait`三个新注解,队列已经满了,继续创建新任务,任务处于等待中,将会执行被这三个注解标志的方法 - app被kill,但是还存在等待中的任务A;第二次重新启动,先创建一个新的任务B,Aria会自动把B放进等待队列中,这时再次创建任务A,会导致重复下载,进度错乱的问题;本版本已修复这个问题 diff --git a/README.md b/README.md index 5227aad2..743a102d 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.13' ``` 如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:3.3.13'`替换为 ``` -compile('com.arialyy.aria:'){ +compile('com.arialyy.aria:aria-core:'){ exclude group: 'com.android.support' } ``` diff --git a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java index 500995ae..6cf598ba 100644 --- a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java @@ -39,8 +39,10 @@ public class FtpDownloadActivity extends BaseActivity { @Override protected void onDestroy() { super.onDestroy(); - Aria.download(this).unRegister(); + //Aria.download(this).unRegister(); } } \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java b/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java index 8b34f75a..0cb66b11 100644 --- a/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java @@ -34,8 +34,8 @@ import com.arialyy.simple.databinding.ActivityFtpUploadBinding; * Ftp 文件上传demo */ public class FtpUploadActivity extends BaseActivity { - private final String FILE_PATH = "/mnt/sdcard/gg.zip"; - private final String URL = "ftp://192.168.1.2:21/upload/测试"; + private final String FILE_PATH = "/mnt/sdcard/AriaPrj.zip"; + private final String URL = "ftp://192.168.1.6:21/aa/你好"; @Override protected void init(Bundle savedInstanceState) { setTile("D_FTP 文件上传"); @@ -56,7 +56,7 @@ public class FtpUploadActivity extends BaseActivity { public void onClick(View view) { switch (view.getId()) { case R.id.start: - Aria.upload(this).loadFtp(FILE_PATH).setUploadUrl(URL).login("lao", "123456").add(); + Aria.upload(this).loadFtp(FILE_PATH).setUploadUrl(URL).login("lao", "123456").start(); break; case R.id.stop: Aria.upload(this).loadFtp(FILE_PATH).stop(); From 1cfcfb90b89d16ae4a75fba02816e6439addf6c6 Mon Sep 17 00:00:00 2001 From: e <511455842@qq.com> Date: Fri, 2 Feb 2018 20:10:53 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=8F=8C=E5=BC=95?= =?UTF-8?q?=E5=8F=B7=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria/build.gradle | 4 +-- .../main/java/com/arialyy/aria/core/Aria.java | 6 ---- .../java/com/arialyy/aria/orm/SqlHelper.java | 34 +++++++++++-------- .../simple/download/SingleTaskActivity.java | 4 +-- .../simple/upload/HttpUploadActivity.java | 11 +++--- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Aria/build.gradle b/Aria/build.gradle index f45db0b2..f95e9d8f 100644 --- a/Aria/build.gradle +++ b/Aria/build.gradle @@ -22,8 +22,8 @@ dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' -// compile project(':AriaAnnotations') - compile 'com.arialyy.aria:aria-ftp-plug:1.0.3' + compile project(':AriaAnnotations') +// compile 'com.arialyy.aria:aria-ftp-plug:1.0.3' compile project(':AriaFtpPlug') } diff --git a/Aria/src/main/java/com/arialyy/aria/core/Aria.java b/Aria/src/main/java/com/arialyy/aria/core/Aria.java index 011086ad..d6d681b7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/Aria.java +++ b/Aria/src/main/java/com/arialyy/aria/core/Aria.java @@ -26,14 +26,8 @@ import android.app.Service; import android.content.Context; import android.os.Build; import android.widget.PopupWindow; -import com.arialyy.annotations.Download; -import com.arialyy.annotations.Upload; import com.arialyy.aria.core.download.DownloadReceiver; -import com.arialyy.aria.core.scheduler.IDownloadSchedulerListener; -import com.arialyy.aria.core.scheduler.ISchedulerListener; -import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.upload.UploadReceiver; -import com.arialyy.aria.core.upload.UploadTask; /** * Created by lyy on 2016/12/1. diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java index 3b75d256..72be07c5 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -23,20 +23,19 @@ import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import android.support.v4.util.LruCache; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; import java.lang.reflect.Field; import java.lang.reflect.Type; +import java.net.URLDecoder; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Date; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; /** * Created by lyy on 2015/11/2. @@ -204,7 +203,7 @@ final class SqlHelper extends SQLiteOpenHelper { sql = sql.replace("?", "%s"); Object[] params = new String[expression.length - 1]; for (int i = 0, len = params.length; i < len; i++) { - params[i] = "\"" + expression[i + 1] + "\""; + params[i] = "'" + expression[i + 1] + "'"; } sql = String.format(sql, params); print(FIND_DATA, sql); @@ -227,7 +226,7 @@ final class SqlHelper extends SQLiteOpenHelper { sql = sql.replace("?", "%s"); Object[] params = new String[expression.length - 1]; for (int i = 0, len = params.length; i < len; i++) { - params[i] = "\"" + expression[i + 1] + "\""; + params[i] = "'" + checkValue(expression[i + 1]) + "'"; } sql = String.format(sql, params); print(FIND_DATA, sql); @@ -269,7 +268,7 @@ final class SqlHelper extends SQLiteOpenHelper { sb.append("SELECT rowid, * FROM ").append(CommonUtil.getClassName(clazz)).append(" where "); int i = 0; for (Object where : wheres) { - sb.append(where).append("=").append("\"").append(values[i]).append("\""); + sb.append(where).append("=").append("'").append(checkValue(values[i])).append("'"); sb.append(i >= wheres.length - 1 ? "" : " AND "); i++; } @@ -281,6 +280,13 @@ final class SqlHelper extends SQLiteOpenHelper { return data; } + private static String checkValue(String value) { + if (value.contains("'")) { + return URLEncoder.encode(value); + } + return value; + } + /** * 查找表的所有数据 */ @@ -319,7 +325,7 @@ final class SqlHelper extends SQLiteOpenHelper { sql = sql.replace("?", "%s"); Object[] params = new String[expression.length - 1]; for (int i = 0, len = params.length; i < len; i++) { - params[i] = "\"" + expression[i + 1] + "\""; + params[i] = "'" + expression[i + 1] + "'"; } sql = String.format(sql, params); SqlHelper.print(DEL_DATA, sql); @@ -362,7 +368,7 @@ final class SqlHelper extends SQLiteOpenHelper { //sb.append(field.getName()).append("='"); String value; prams.append(i > 0 ? ", " : ""); - prams.append(field.getName()).append("=\""); + prams.append(field.getName()).append("='"); Type type = field.getType(); if (type == Map.class) { value = SqlUtil.map2Str((Map) field.get(dbEntity)); @@ -376,13 +382,13 @@ final class SqlHelper extends SQLiteOpenHelper { value = SqlUtil.getOneToOneParams(field); } else { Object obj = field.get(dbEntity); - value = obj == null ? "" : obj.toString(); + value = obj == null ? "" : checkValue(obj.toString()); } //sb.append(value == null ? "" : value); //sb.append("'"); prams.append(TextUtils.isEmpty(value) ? "" : value); - prams.append("\""); + prams.append("'"); } catch (IllegalAccessException e) { e.printStackTrace(); } @@ -432,7 +438,7 @@ final class SqlHelper extends SQLiteOpenHelper { continue; } sb.append(i > 0 ? ", " : ""); - sb.append("\""); + sb.append("'"); Type type = field.getType(); if (type == Map.class) { sb.append(SqlUtil.map2Str((Map) field.get(dbEntity))); @@ -445,9 +451,9 @@ final class SqlHelper extends SQLiteOpenHelper { } else if (SqlUtil.isOneToOne(field)) { sb.append(SqlUtil.getOneToOneParams(field)); } else { - sb.append(field.get(dbEntity)); + sb.append(checkValue(field.get(dbEntity).toString())); } - sb.append("\""); + sb.append("'"); i++; } } catch (IllegalAccessException e) { @@ -639,7 +645,7 @@ final class SqlHelper extends SQLiteOpenHelper { int column = cursor.getColumnIndex(field.getName()); if (column == -1) continue; if (type == String.class) { - field.set(entity, cursor.getString(column)); + field.set(entity, URLDecoder.decode(cursor.getString(column))); } else if (type == int.class || type == Integer.class) { field.setInt(entity, cursor.getInt(column)); } else if (type == float.class || type == Float.class) { diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index 275f83c2..18123af9 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -58,8 +58,8 @@ public class SingleTaskActivity extends BaseActivity { //"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-"; //"http://gdown.baidu.com/data/wisegame/0904344dee4a2d92/QQ_718.apk"; //"http://qudao.5535.cn/one/game.html?game=531&cpsuser=xiaoeryu2"; - //"https://bogoe-res.mytbz.com/tbzengsong/If You're Happy.mp3"; - "http://ozr0ucjs5.bkt.clouddn.com/51_box-104_20180131202610.apk"; + "https://bogoe-res.mytbz.com/tbzengsong/If You're Happy.mp3"; + //"http://ozr0ucjs5.bkt.clouddn.com/51_box-104_20180131202610.apk"; @Bind(R.id.start) Button mStart; @Bind(R.id.stop) Button mStop; @Bind(R.id.cancel) Button mCancel; diff --git a/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java b/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java index 9ebb8d56..2cd63cc8 100644 --- a/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java @@ -17,7 +17,6 @@ package com.arialyy.simple.upload; import android.os.Bundle; -import android.util.Log; import butterknife.Bind; import butterknife.OnClick; import com.arialyy.annotations.Upload; @@ -36,7 +35,7 @@ public class HttpUploadActivity extends BaseActivity { private static final String TAG = "HttpUploadActivity"; @Bind(R.id.pb) HorizontalProgressBarWithNumber mPb; - private static final String FILE_PATH = "/mnt/sdcard/gg.zip"; + private static final String FILE_PATH = "/mnt/sdcard/360sicheck.txt"; @Override protected int setLayoutId() { return R.layout.activity_upload; @@ -51,8 +50,10 @@ public class HttpUploadActivity extends BaseActivity { @OnClick(R.id.upload) void upload() { Aria.upload(HttpUploadActivity.this) .load(FILE_PATH) - .setUploadUrl("http://192.168.1.9:8080/upload/") - .setAttachment("serveFile") + .setUploadUrl( + "http://lib-test.xzxyun.com:8042/Api/upload?data={\"type\":\"1\",\"fileType\":\".txt\"}") + .setAttachment("file") + .addHeader("iplanetdirectorypro", "") .start(); } @@ -64,7 +65,6 @@ public class HttpUploadActivity extends BaseActivity { Aria.upload(this).load(FILE_PATH).cancel(); } - @Upload.onPre public void onPre(UploadTask task) { } @@ -88,6 +88,7 @@ public class HttpUploadActivity extends BaseActivity { @Upload.onTaskRunning public void taskRunning(UploadTask task) { getBinding().setSpeed(task.getConvertSpeed()); getBinding().setProgress(task.getPercent()); + L.d(TAG, "P => " + task.getPercent()); } @Upload.onTaskComplete public void taskComplete(UploadTask task) { From ebddc510ca4bfec67c2d690af7d806d78af0f880 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Sat, 3 Feb 2018 12:57:55 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhttp=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E5=90=8E=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E6=B2=A1=E6=9C=89=E8=AE=BE=E7=BD=AE=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=A0=81=E5=AF=BC=E8=87=B4=E4=B8=8A=E4=BC=A0=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aria/core/common/AbsFtpInfoThread.java | 3 ++- .../aria/core/common/AbsThreadTask.java | 6 +++++- .../arialyy/aria/core/upload/UploadEntity.java | 15 ++++++++++++++- .../upload/uploader/FtpFileInfoThread.java | 15 +++++++++++++-- .../core/upload/uploader/HttpThreadTask.java | 10 +++++----- .../java/com/arialyy/aria/orm/DBConfig.java | 2 +- DEV_LOG.md | 3 +++ README.md | 13 +++++++------ .../simple/download/FtpDownloadActivity.java | 10 +++------- .../simple/upload/FtpUploadActivity.java | 7 ++++--- .../simple/upload/HttpUploadActivity.java | 18 ++++++++++-------- build.gradle | 2 +- 12 files changed, 68 insertions(+), 36 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java index 7275ebd8..7b88e0d5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java @@ -82,7 +82,8 @@ public abstract class AbsFtpInfoThread { + private static final String TAG = "FtpUploadFtpFileInfoThread"; static final int CODE_COMPLETE = 0xab1; private boolean isComplete = false; @@ -56,12 +58,21 @@ class FtpFileInfoThread extends AbsFtpInfoThread if (ftpFile.getSize() == mEntity.getFileSize()) { isComplete = true; } else { + ALog.w(TAG, "FTP服务器已存在未完成的文件【" + + ftpFile.getName() + + ",size: " + + ftpFile.getSize() + + "】" + + "尝试从位置:" + + ftpFile.getSize() + + "开始上传"); File configFile = new File(CommonUtil.getFileConfigPath(false, mEntity.getFileName())); Properties pro = CommonUtil.loadConfig(configFile); String key = mEntity.getFileName() + "_record_" + 0; + mTaskEntity.isNewTask = false; long oldRecord = Long.parseLong(pro.getProperty(key, "0")); - if (oldRecord != 0) { - //修改本地保存的停止地址为服务器上的真实地址 + if (oldRecord == 0) { + //修改本地保存的停止地址为服务器上对应文件的大小 pro.setProperty(key, ftpFile.getSize() + ""); CommonUtil.saveConfig(configFile, pro); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java index 3e108dcd..8783aaeb 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java @@ -89,7 +89,8 @@ class HttpThreadTask extends AbsThreadTask { addFormField(writer, key, mTaskEntity.formFields.get(key)); } uploadFile(writer, mTaskEntity.attachment, uploadFile); - finish(writer); + mTaskEntity.getEntity().setResponseStr(finish(writer)); + mListener.onComplete(); } catch (Exception e) { e.printStackTrace(); fail(); @@ -167,7 +168,6 @@ class HttpThreadTask extends AbsThreadTask { STATE.isRunning = false; return; } - mListener.onComplete(); STATE.isRunning = false; } @@ -184,6 +184,7 @@ class HttpThreadTask extends AbsThreadTask { writer.close(); int status = mHttpConn.getResponseCode(); + if (status == HttpURLConnection.HTTP_OK) { BufferedReader reader = new BufferedReader(new InputStreamReader(mHttpConn.getInputStream())); String line; @@ -193,10 +194,9 @@ class HttpThreadTask extends AbsThreadTask { reader.close(); mHttpConn.disconnect(); } else { - ALog.w(TAG, "state_code = " + status); - fail(); + ALog.e(TAG, "response msg: " + mHttpConn.getResponseMessage() + ",code: " + status); + // fail(); } - writer.flush(); writer.close(); mOutputStream.close(); diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java index bb485a4c..5196af1b 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -34,7 +34,7 @@ import java.util.Map; class DBConfig { static Map mapping = new HashMap<>(); static String DB_NAME; - static int VERSION = 22; + static int VERSION = 23; static { if (TextUtils.isEmpty(DB_NAME)) { diff --git a/DEV_LOG.md b/DEV_LOG.md index 26aed643..8caf37f3 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -2,6 +2,9 @@ + v_3.3.14 - 修复ftp上传和下载的兼容性问题 - 如果url中的path有"//"将替换为"/" + - 修复http上传成功后,如果服务器没有设置返回码导致上传失败的问题 + - 上传实体UploadEntity增加responseStr字段,http上传完成后,在被`@Upload.onComplete`注解的方法中,可通过`task.getEntity().getResponseStr())`获取服务器返回的数据 + - 如果服务器存在已上传了一部分的文件,用户执行删除该FTP上传任务,再次重新上传,会出现550,权限错误;本版本已修复该问题 + v_3.3.13 - 添加`@Download.onWait、@Upload.onWait、@DownloadGroup.onWait`三个新注解,队列已经满了,继续创建新任务,任务处于等待中,将会执行被这三个注解标志的方法 - app被kill,但是还存在等待中的任务A;第二次重新启动,先创建一个新的任务B,Aria会自动把B放进等待队列中,这时再次创建任务A,会导致重复下载,进度错乱的问题;本版本已修复这个问题 diff --git a/README.md b/README.md index 743a102d..f86ca21f 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Aria有以下特点: [![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) ```java -compile 'com.arialyy.aria:aria-core:3.3.13' -annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.13' +compile 'com.arialyy.aria:aria-core:3.3.14' +annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.14' ``` 如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:3.3.13'`替换为 ``` @@ -103,10 +103,11 @@ protected void onCreate(Bundle savedInstanceState) { ### [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki) ### 版本日志 -+ v_3.3.13 - - 添加`@Download.onWait、@Upload.onWait、@DownloadGroup.onWait`三个新注解,队列已经满了,继续创建新任务,任务处于等待中,将会执行被这三个注解标志的方法 - - app被kill,但是还存在等待中的任务A;第二次重新启动,先创建一个新的任务B,Aria会自动把B放进等待队列中,这时再次创建任务A,会导致重复下载,进度错乱的问题;本版本已修复这个问题 - + + v_3.3.14 + - 修复ftp上传和下载的兼容性问题 + - 如果url中的path有"//"将替换为"/" + - 修复http上传成功后,如果服务器没有设置返回码导致上传失败的问题 + - 上传实体UploadEntity增加responseStr字段,http上传完成后,在被`@Upload.onComplete`注解的方法中,可通过`task.getEntity().getResponseStr())`获取服务器返回的数据 [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java index 6cf598ba..9fc20cc0 100644 --- a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java @@ -36,13 +36,9 @@ import java.io.File; */ public class FtpDownloadActivity extends BaseActivity { //private final String URL = "ftp://192.168.1.9:21/下载/AriaPrj.zip"; - //private final String URL = "ftp://192.168.1.9:21/下载/[电影天堂www.dy2018.com]赛车总动员3BD中英双字.mp4"; - //private final String URL = "ftp://h:h@tv.dl1234.com:2199/付岩洞复仇者们05.mkv"; - //private final String URL = "ftp://z:z@dygod18.com:21211/[破晓电影www.poxiao.com]情遇曼哈顿HD国语中字.mkv"; //private final String URL = "ftp://182.92.180.213:21/video/572fed5c2ad48_1024.jpg"; - //private final String URL = "ftp://192.168.1.6:21/download/AriaPrj.zip"; - //private final String URL = "ftp://172.18.104.71:21/upload/AS.zip"; - private final String URL = "ftp://d:d@dygodj8.com:12311/[电影天堂www.dy2018.com]脑火BD中字.mp4"; + private final String URL = "ftp://192.168.1.6:21/download/AriaPrj.zip"; + //private final String URL = "ftp://d:d@dygodj8.com:12311/咖啡风暴HD大陆公映意语中字[飘花www.piaohua.com].mp4"; @Override protected void init(Bundle savedInstanceState) { super.init(savedInstanceState); @@ -65,7 +61,7 @@ public class FtpDownloadActivity extends BaseActivity { } } - @Upload.onWait void onWait(UploadTask task){ + @Upload.onWait void onWait(UploadTask task) { Log.d(TAG, task.getTaskName() + "_wait"); } @@ -76,7 +77,7 @@ public class FtpUploadActivity extends BaseActivity { } @Upload.onTaskStart public void taskStart(UploadTask task) { - Log.d(TAG, "开始上传"); + Log.d(TAG, "开始上传,md5:" + FileUtil.getFileMD5(new File(task.getEntity().getFilePath()))); } @Upload.onTaskResume public void taskResume(UploadTask task) { diff --git a/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java b/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java index 2cd63cc8..92089de2 100644 --- a/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java @@ -22,11 +22,13 @@ import butterknife.OnClick; import com.arialyy.annotations.Upload; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.upload.UploadTask; +import com.arialyy.frame.util.FileUtil; import com.arialyy.frame.util.show.L; import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.databinding.ActivityUploadBinding; import com.arialyy.simple.widget.HorizontalProgressBarWithNumber; +import java.io.File; /** * Created by Aria.Lao on 2017/2/9. @@ -35,7 +37,7 @@ public class HttpUploadActivity extends BaseActivity { private static final String TAG = "HttpUploadActivity"; @Bind(R.id.pb) HorizontalProgressBarWithNumber mPb; - private static final String FILE_PATH = "/mnt/sdcard/360sicheck.txt"; + private static final String FILE_PATH = "/mnt/sdcard/test.txt"; @Override protected int setLayoutId() { return R.layout.activity_upload; @@ -48,12 +50,11 @@ public class HttpUploadActivity extends BaseActivity { } @OnClick(R.id.upload) void upload() { - Aria.upload(HttpUploadActivity.this) - .load(FILE_PATH) - .setUploadUrl( - "http://lib-test.xzxyun.com:8042/Api/upload?data={\"type\":\"1\",\"fileType\":\".txt\"}") - .setAttachment("file") - .addHeader("iplanetdirectorypro", "") + Aria.upload(HttpUploadActivity.this).load(FILE_PATH) + //.setUploadUrl( + // "http://lib-test.xzxyun.com:8042/Api/upload?data={\"type\":\"1\",\"fileType\":\".txt\"}") + .setUploadUrl("http://192.168.1.6:8080/upload/sign_file/").setAttachment("file") + //.addHeader("iplanetdirectorypro", "11a09102fb934ad0bc206f9c611d7933") .start(); } @@ -69,7 +70,7 @@ public class HttpUploadActivity extends BaseActivity { } @Upload.onTaskStart public void taskStart(UploadTask task) { - L.d(TAG, "upload start"); + L.d(TAG, "upload start,md5:" + FileUtil.getFileMD5(new File(task.getEntity().getFilePath()))); getBinding().setFileSize(task.getConvertFileSize()); } @@ -93,6 +94,7 @@ public class HttpUploadActivity extends BaseActivity { @Upload.onTaskComplete public void taskComplete(UploadTask task) { L.d(TAG, "上传完成"); + L.d(TAG, "上传成功返回数据(如果有的话):" + task.getEntity().getResponseStr()); getBinding().setSpeed(""); getBinding().setProgress(100); } diff --git a/build.gradle b/build.gradle index 707f22c5..40de7a5e 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.3.13' + publishVersion = '3.3.14' // publishVersion = '1.0.3' //FTP插件 repoName='maven' desc = 'android 下载框架'