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/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/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..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 @@ -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,19 @@ public abstract class AbsFtpInfoThread 0) { ALog.i(TAG, "路径【" + setRemotePath() + "】下的文件列表 ==================================="); for (FTPFile file : files1) { @@ -89,7 +98,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 b932cf8c..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) { @@ -59,17 +59,29 @@ class FtpThreadTask extends AbsFtpThreadTask + "】"); 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 (!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); - //发送第二次指令时,还需要再做一次判断 - int reply = client.getReplyCode(); + reply = client.getReplyCode(); if (!FTPReply.isPositivePreliminary(reply)) { + fail(mChildCurrentLocation, "获取流失败,错误码为:" + reply + ",msg:" + client.getReplyString(), + null); client.disconnect(); - fail(mChildCurrentLocation, "获取文件信息错误,错误码为:" + reply, 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/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 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/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java index ed15bed1..f5ee778a 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 @@ -35,7 +35,7 @@ import org.apache.commons.net.ftp.OnFtpInputStreamListener; * FTP 单线程上传任务,需要FTP 服务器给用户打开删除和读入IO的权限 */ class FtpThreadTask extends AbsFtpThreadTask { - private final String TAG = "FtpThreadTask"; + private final String TAG = "FtpUploadThreadTask"; private String dir, remotePath; FtpThreadTask(StateConstance constance, IEventListener listener, @@ -64,6 +64,13 @@ class FtpThreadTask extends AbsFtpThreadTask { client.makeDirectory(dir); client.changeWorkingDirectory(dir); client.setRestartOffset(mConfig.START_LOCATION); + int reply = client.getReplyCode(); + if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.FILE_ACTION_OK) { + fail(mChildCurrentLocation, "上传失败,错误码为:" + reply + ",msg:" + client.getReplyString(), null); + client.disconnect(); + return; + } + file = new BufferedRandomAccessFile(mConfig.TEMP_FILE, "rwd", mBufSize); if (mConfig.START_LOCATION != 0) { //file.skipBytes((int) mConfig.START_LOCATION); @@ -82,7 +89,7 @@ class FtpThreadTask extends AbsFtpThreadTask { STATE.isRunning = false; mListener.onComplete(); } - if (STATE.isFail()){ + if (STATE.isFail()) { STATE.isRunning = false; mListener.onFail(false); } @@ -107,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); } @@ -115,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; @@ -141,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/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/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/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/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..8caf37f3 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,5 +1,11 @@ ## 开发日志 - + v_3.3.12 + + 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,会导致重复下载,进度错乱的问题;本版本已修复这个问题 + v_3.3.11 diff --git a/README.md b/README.md index bdb2d7cc..2973c78d 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,14 @@ 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'`替换为 +``` +compile('com.arialyy.aria:aria-core:'){ + exclude group: 'com.android.support' +} ``` 如果你使用的是kotlin,请使用kotlin官方提供的方法配置apt,[kotlin kapt官方配置传送门](https://www.kotlincn.net/docs/reference/kapt.html) @@ -97,12 +103,11 @@ 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.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 1b4827e8..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,10 +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://172.18.104.71:21/upload/AS.zip"; + //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://d:d@dygodj8.com:12311/咖啡风暴HD大陆公映意语中字[飘花www.piaohua.com].mp4"; @Override protected void init(Bundle savedInstanceState) { super.init(savedInstanceState); @@ -61,7 +60,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,12 +232,12 @@ public class SingleTaskActivity extends BaseActivity { //.setRequestMode(RequestEnum.POST) .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk") .resetState() - //.start(); - .add(); + .start(); + //.add(); } @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..368e9131 100644 --- a/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java @@ -23,19 +23,20 @@ import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadTask; import com.arialyy.aria.util.CommonUtil; -import com.arialyy.frame.util.show.L; +import com.arialyy.frame.util.FileUtil; import com.arialyy.frame.util.show.T; import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.databinding.ActivityFtpUploadBinding; +import java.io.File; /** * Created by Aria.Lao on 2017/7/28. * 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 +57,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(); @@ -67,7 +68,7 @@ public class FtpUploadActivity 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 9ebb8d56..92089de2 100644 --- a/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java @@ -17,17 +17,18 @@ package com.arialyy.simple.upload; import android.os.Bundle; -import android.util.Log; import butterknife.Bind; 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. @@ -36,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/gg.zip"; + private static final String FILE_PATH = "/mnt/sdcard/test.txt"; @Override protected int setLayoutId() { return R.layout.activity_upload; @@ -49,10 +50,11 @@ 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") + 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(); } @@ -64,12 +66,11 @@ public class HttpUploadActivity extends BaseActivity { Aria.upload(this).load(FILE_PATH).cancel(); } - @Upload.onPre public void onPre(UploadTask task) { } @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()); } @@ -88,10 +89,12 @@ 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) { 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 下载框架'