修复了字符串中有特殊字符导致的路径冲突问题;修复ftp分块下载失败问题

pull/330/head
laoyuyu 7 years ago
parent 0a85477da3
commit 1d116f71b7
  1. 2
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java
  2. 5
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  3. 2
      Aria/src/main/java/com/arialyy/aria/core/common/StateConstance.java
  4. 9
      Aria/src/main/java/com/arialyy/aria/core/download/BaseNormalTarget.java
  5. 88
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  6. 13
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  7. 15
      Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java
  8. 10
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java
  9. 2
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  10. 24
      Aria/src/main/java/com/arialyy/aria/orm/AbsDelegate.java
  11. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  12. 4
      Aria/src/main/java/com/arialyy/aria/orm/DelegateCommon.java
  13. 4
      Aria/src/main/java/com/arialyy/aria/orm/DelegateFind.java
  14. 12
      Aria/src/main/java/com/arialyy/aria/orm/DelegateUpdate.java
  15. 2
      app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java
  16. 30
      app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java
  17. 42
      app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java
  18. 2
      build.gradle

@ -489,7 +489,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
} }
if (mConstance.CURRENT_LOCATION != 0 if (mConstance.CURRENT_LOCATION != 0
&& mConstance.CURRENT_LOCATION != mEntity.getCurrentProgress()) { && mConstance.CURRENT_LOCATION != mEntity.getCurrentProgress()) {
ALog.d(TAG, "进度修正"); ALog.d(TAG, String.format("进度修正,当前进度:%s", mConstance.CURRENT_LOCATION));
mEntity.setCurrentProgress(mConstance.CURRENT_LOCATION); mEntity.setCurrentProgress(mConstance.CURRENT_LOCATION);
} }
saveRecord(); saveRecord();

@ -49,6 +49,9 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
*/ */
private final int RETRY_INTERVAL = 5000; private final int RETRY_INTERVAL = 5000;
private final String TAG = "AbsThreadTask"; private final String TAG = "AbsThreadTask";
/**
* 当前子线程的下载位置
*/
protected long mChildCurrentLocation = 0, mSleepTime = 0; protected long mChildCurrentLocation = 0, mSleepTime = 0;
protected int mBufSize; protected int mBufSize;
protected IEventListener mListener; protected IEventListener mListener;
@ -185,6 +188,8 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
protected void progress(long len) { protected void progress(long len) {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
if (STATE.CURRENT_LOCATION > mEntity.getFileSize()) { if (STATE.CURRENT_LOCATION > mEntity.getFileSize()) {
ALog.d(TAG, String.format("currentLocation=%s, fileSize=%s", STATE.CURRENT_LOCATION,
mEntity.getFileSize()));
taskBreak = true; taskBreak = true;
fail(mChildCurrentLocation, "下载失败,下载长度超出文件大小", null, false); fail(mChildCurrentLocation, "下载失败,下载长度超出文件大小", null, false);
return; return;

@ -60,7 +60,7 @@ public class StateConstance {
ALog.d(TAG, String.format("fail_num=%s; start_thread_num=%s, complete_num=%s", FAIL_NUM, ALog.d(TAG, String.format("fail_num=%s; start_thread_num=%s, complete_num=%s", FAIL_NUM,
START_THREAD_NUM, COMPLETE_THREAD_NUM)); START_THREAD_NUM, COMPLETE_THREAD_NUM));
return COMPLETE_THREAD_NUM != START_THREAD_NUM return COMPLETE_THREAD_NUM != START_THREAD_NUM
&& FAIL_NUM == START_THREAD_NUM; && (FAIL_NUM == START_THREAD_NUM || FAIL_NUM + COMPLETE_THREAD_NUM == START_THREAD_NUM);
} }
/** /**

@ -37,12 +37,12 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
/** /**
* 通过地址初始化target * 通过地址初始化target
*/ */
void initTarget(String url, String targetName, boolean refreshInfo) { void initTarget(String url, String targetName) {
this.url = url; this.url = url;
mTargetName = targetName; mTargetName = targetName;
mTaskEntity = TEManager.getInstance().getTEntity(DownloadTaskEntity.class, url); mTaskEntity = TEManager.getInstance().getTEntity(DownloadTaskEntity.class, url);
mEntity = mTaskEntity.getEntity(); mEntity = mTaskEntity.getEntity();
mTaskEntity.setRefreshInfo(refreshInfo);
if (mEntity != null) { if (mEntity != null) {
mTempFilePath = mEntity.getDownloadPath(); mTempFilePath = mEntity.getDownloadPath();
} }
@ -63,6 +63,7 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
return (TARGET) this; return (TARGET) this;
} }
this.newUrl = newUrl; this.newUrl = newUrl;
mTaskEntity.setRefreshInfo(true);
return (TARGET) this; return (TARGET) this;
} }
@ -199,6 +200,10 @@ abstract class BaseNormalTarget<TARGET extends BaseNormalTarget>
ALog.e(TAG, "下载失败,url【" + url + "】不合法"); ALog.e(TAG, "下载失败,url【" + url + "】不合法");
return false; return false;
} }
if (!TextUtils.isEmpty(newUrl)){
mEntity.setUrl(newUrl);
mTaskEntity.setUrl(newUrl);
}
return true; return true;
} }
} }

@ -18,7 +18,6 @@ package com.arialyy.aria.core.download;
import android.support.annotation.CheckResult; import android.support.annotation.CheckResult;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.ICmd; import com.arialyy.aria.core.command.ICmd;
import com.arialyy.aria.core.command.normal.CancelAllCmd; import com.arialyy.aria.core.command.normal.CancelAllCmd;
@ -27,7 +26,6 @@ import com.arialyy.aria.core.common.ProxyHelper;
import com.arialyy.aria.core.download.wrapper.DGEWrapper; import com.arialyy.aria.core.download.wrapper.DGEWrapper;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsReceiver; import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.ReceiverType; import com.arialyy.aria.core.inf.ReceiverType;
import com.arialyy.aria.core.manager.TEManager; import com.arialyy.aria.core.manager.TEManager;
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers; import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
@ -64,28 +62,7 @@ public class DownloadReceiver extends AbsReceiver {
*/ */
@CheckResult @CheckResult
public DownloadTarget load(DownloadEntity entity) { public DownloadTarget load(DownloadEntity entity) {
return load(entity, false); return new DownloadTarget(entity, targetName);
}
/**
* 使用下载实体执行下载操作
*
* @param refreshInfo 是否刷新下载信息
* @deprecated 请使用 {@link AbsTarget#resetState()}
* <pre>
* <code>
* Aria.download(this)
* .load(URL)
* .setDownloadPath(PATH)
* .resetState()
* .start();
* </code>
* </pre>
*/
@CheckResult
@Deprecated public DownloadTarget load(DownloadEntity entity, boolean refreshInfo) {
CheckUtil.checkDownloadEntity(entity);
return new DownloadTarget(entity, targetName, refreshInfo);
} }
/** /**
@ -95,29 +72,7 @@ public class DownloadReceiver extends AbsReceiver {
*/ */
@CheckResult @CheckResult
public DownloadTarget load(@NonNull String url) { public DownloadTarget load(@NonNull String url) {
return load(url, false); return new DownloadTarget(url, targetName);
}
/**
* 加载Httphttps单任务下载地址
*
* @param url 下载地址
* @param refreshInfo 是否刷新下载信息当下载地址改变而保存路径不变则需要设置该参数为{@code true}
* @deprecated 请使用 {@link AbsTarget#resetState()}
* <pre>
* <code>
* Aria.download(this)
* .load(URL)
* .setDownloadPath(PATH)
* .resetState()
* .start();
* </code>
* </pre>
*/
@CheckResult
@Deprecated public DownloadTarget load(@NonNull String url, boolean refreshInfo) {
CheckUtil.checkUrlInvalidThrow(url);
return new DownloadTarget(url, targetName, refreshInfo);
} }
/** /**
@ -148,31 +103,7 @@ public class DownloadReceiver extends AbsReceiver {
*/ */
@CheckResult @CheckResult
public FtpDownloadTarget loadFtp(DownloadEntity entity) { public FtpDownloadTarget loadFtp(DownloadEntity entity) {
return loadFtp(entity, false); return new FtpDownloadTarget(entity, targetName);
}
/**
* 使用下载实体执行下载操作
*
* @param refreshInfo 是否刷新下载信息当下载地址改变而保存路径不变则需要设置该参数为{@code true}
* @deprecated 请使用 {@link AbsTarget#resetState()}
* <pre>
* <code>
* Aria.download(this)
* .load(URL)
* .setDownloadPath(PATH)
* .resetState()
* .start();
* </code>
* </pre>
*/
@CheckResult
@Deprecated public FtpDownloadTarget loadFtp(DownloadEntity entity, boolean refreshInfo) {
CheckUtil.checkDownloadEntity(entity);
if (!entity.getUrl().startsWith("ftp")) {
throw new IllegalArgumentException("非FTP请求不能使用该方法");
}
return new FtpDownloadTarget(entity, targetName, refreshInfo);
} }
/** /**
@ -180,18 +111,7 @@ public class DownloadReceiver extends AbsReceiver {
*/ */
@CheckResult @CheckResult
public FtpDownloadTarget loadFtp(@NonNull String url) { public FtpDownloadTarget loadFtp(@NonNull String url) {
return loadFtp(url, false); return new FtpDownloadTarget(url, targetName);
}
/**
* 加载ftp单任务下载地址
*
* @param refreshInfo 是否刷新下载信息
*/
@CheckResult
public FtpDownloadTarget loadFtp(@NonNull String url, boolean refreshInfo) {
CheckUtil.checkUrlInvalidThrow(url);
return new FtpDownloadTarget(url, targetName, refreshInfo);
} }
/** /**

@ -31,20 +31,13 @@ public class DownloadTarget extends BaseNormalTarget<DownloadTarget>
implements IHttpHeaderTarget<DownloadTarget> { implements IHttpHeaderTarget<DownloadTarget> {
private HttpHeaderDelegate<DownloadTarget, DownloadEntity, DownloadTaskEntity> mDelegate; private HttpHeaderDelegate<DownloadTarget, DownloadEntity, DownloadTaskEntity> mDelegate;
public DownloadTarget(DownloadEntity entity, String targetName) {
this(entity, targetName, false);
}
DownloadTarget(DownloadEntity entity, String targetName, boolean refreshInfo) { DownloadTarget(DownloadEntity entity, String targetName) {
this(entity.getUrl(), targetName, refreshInfo); this(entity.getUrl(), targetName);
} }
DownloadTarget(String url, String targetName) { DownloadTarget(String url, String targetName) {
this(url, targetName, false); initTarget(url, targetName);
}
DownloadTarget(String url, String targetName, boolean refreshInfo) {
initTarget(url, targetName, refreshInfo);
mDelegate = new HttpHeaderDelegate<>(this, mTaskEntity); mDelegate = new HttpHeaderDelegate<>(this, mTaskEntity);
} }

@ -30,24 +30,19 @@ public class FtpDownloadTarget extends BaseNormalTarget<FtpDownloadTarget>
implements IFtpTarget<FtpDownloadTarget> { implements IFtpTarget<FtpDownloadTarget> {
private FtpDelegate<FtpDownloadTarget, DownloadEntity, DownloadTaskEntity> mDelegate; private FtpDelegate<FtpDownloadTarget, DownloadEntity, DownloadTaskEntity> mDelegate;
public FtpDownloadTarget(DownloadEntity entity, String targetName, boolean refreshInfo) { public FtpDownloadTarget(DownloadEntity entity, String targetName) {
this(entity.getUrl(), targetName, refreshInfo); this(entity.getUrl(), targetName);
} }
FtpDownloadTarget(String url, String targetName) { FtpDownloadTarget(String url, String targetName) {
this(url, targetName, false); initTarget(url, targetName);
init();
} }
FtpDownloadTarget(String url, String targetName, boolean refreshInfo) { private void init() {
initTarget(url, targetName, refreshInfo);
init(refreshInfo);
}
private void init(boolean refreshInfo) {
int lastIndex = url.lastIndexOf("/"); int lastIndex = url.lastIndexOf("/");
mEntity.setFileName(url.substring(lastIndex + 1, url.length())); mEntity.setFileName(url.substring(lastIndex + 1, url.length()));
mTaskEntity.setUrlEntity(CommonUtil.getFtpUrlInfo(url)); mTaskEntity.setUrlEntity(CommonUtil.getFtpUrlInfo(url));
mTaskEntity.setRefreshInfo(refreshInfo);
mTaskEntity.setRequestType(AbsTaskEntity.D_FTP); mTaskEntity.setRequestType(AbsTaskEntity.D_FTP);
mDelegate = new FtpDelegate<>(this, mTaskEntity); mDelegate = new FtpDelegate<>(this, mTaskEntity);

@ -61,7 +61,6 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
handleComplete(); handleComplete();
return; return;
} }
//当前子线程的下载位置
mChildCurrentLocation = mConfig.START_LOCATION; mChildCurrentLocation = mConfig.START_LOCATION;
FTPClient client = null; FTPClient client = null;
InputStream is = null; InputStream is = null;
@ -172,11 +171,20 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
if (mSleepTime > 0) { if (mSleepTime > 0) {
Thread.sleep(mSleepTime); Thread.sleep(mSleepTime);
} }
if (mChildCurrentLocation + len >= mConfig.END_LOCATION) {
len = (int) (mConfig.END_LOCATION - mChildCurrentLocation);
bf.flip();
fos.write(bf.array(), 0, len);
bf.compact();
progress(len);
break;
} else {
bf.flip(); bf.flip();
foc.write(bf); foc.write(bf);
bf.compact(); bf.compact();
progress(len); progress(len);
} }
}
handleComplete(); handleComplete();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();

@ -56,7 +56,7 @@ class HttpFileInfoThread implements Runnable {
URL url = new URL(CommonUtil.convertUrl(mEntity.getUrl())); URL url = new URL(CommonUtil.convertUrl(mEntity.getUrl()));
conn = ConnectionHelp.handleConnection(url, mTaskEntity); conn = ConnectionHelp.handleConnection(url, mTaskEntity);
conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); conn = ConnectionHelp.setConnectParam(mTaskEntity, conn);
//conn.setRequestProperty("Range", "bytes=" + 0 + "-"); conn.setRequestProperty("Range", "bytes=" + 0 + "-");
conn.setConnectTimeout(mConnectTimeOut); conn.setConnectTimeout(mConnectTimeOut);
//conn.setChunkedStreamingMode(0); //conn.setChunkedStreamingMode(0);
conn.connect(); conn.connect();

@ -88,6 +88,17 @@ abstract class AbsDelegate {
return dbEntity.getClass().getName() + "_" + dbEntity.rowID; return dbEntity.getClass().getName() + "_" + dbEntity.rowID;
} }
/**
* URL编码字符串
*
* @param str 原始字符串
* @return 编码后的字符串
*/
String encodeStr(String str) {
str = str.replaceAll("\\\\+", "%2B");
return URLEncoder.encode(str);
}
/** /**
* 检查list参数是否合法list只能是{@code List<String>} * 检查list参数是否合法list只能是{@code List<String>}
* *
@ -122,19 +133,6 @@ abstract class AbsDelegate {
} }
} }
/**
* 为了防止特殊字符串导致存储失败需要使用URL编码保存的字符串
*
* @param value 需要保存的内容
* @return 转换后的内容
*/
String convertValue(String value) {
if (!TextUtils.isEmpty(value) && value.contains("'")) {
return URLEncoder.encode(value);
}
return value;
}
void closeCursor(Cursor cursor) { void closeCursor(Cursor cursor) {
if (cursor != null && !cursor.isClosed()) { if (cursor != null && !cursor.isClosed()) {
try { try {

@ -35,7 +35,7 @@ class DBConfig {
/*adb pull /mnt/sdcard/Android/data/com.arialyy.simple/files/DB/AriaLyyDb d:/db*/ /*adb pull /mnt/sdcard/Android/data/com.arialyy.simple/files/DB/AriaLyyDb d:/db*/
static Map<String, Class> mapping = new HashMap<>(); static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME; static String DB_NAME;
static int VERSION = 35; static int VERSION = 39;
/** /**
* 是否将数据库保存在Sd卡{@code true} * 是否将数据库保存在Sd卡{@code true}

@ -76,7 +76,7 @@ class DelegateCommon extends AbsDelegate {
Cursor cursor = null; Cursor cursor = null;
try { try {
String sql = String sql =
String.format("SELECT name FROM sqlite_master WHERE type='table' AND name='%s'", String.format("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='%s'",
tableName); tableName);
print(TABLE_EXISTS, sql); print(TABLE_EXISTS, sql);
cursor = db.rawQuery(sql, null); cursor = db.rawQuery(sql, null);
@ -109,7 +109,7 @@ class DelegateCommon extends AbsDelegate {
sql = sql.replace("?", "%s"); sql = sql.replace("?", "%s");
Object[] params = new String[expression.length - 1]; Object[] params = new String[expression.length - 1];
for (int i = 0, len = params.length; i < len; i++) { for (int i = 0, len = params.length; i < len; i++) {
params[i] = "'" + expression[i + 1] + "'"; params[i] = String.format("'%s'", encodeStr(expression[i + 1]));
} }
sql = String.format(sql, params); sql = String.format(sql, params);
print(FIND_DATA, sql); print(FIND_DATA, sql);

@ -169,7 +169,7 @@ class DelegateFind extends AbsDelegate {
sql = sql.replace("?", "%s"); sql = sql.replace("?", "%s");
Object[] params = new String[expression.length - 1]; Object[] params = new String[expression.length - 1];
for (int i = 0, len = params.length; i < len; i++) { for (int i = 0, len = params.length; i < len; i++) {
params[i] = "'" + convertValue(expression[i + 1]) + "'"; params[i] = String.format("'%s'", encodeStr(expression[i + 1]));
} }
sql = String.format(sql, params); sql = String.format(sql, params);
} else { } else {
@ -344,7 +344,7 @@ class DelegateFind extends AbsDelegate {
sql = sql.replace("?", "%s"); sql = sql.replace("?", "%s");
Object[] params = new String[expression.length - 1]; Object[] params = new String[expression.length - 1];
for (int i = 0, len = params.length; i < len; i++) { for (int i = 0, len = params.length; i < len; i++) {
params[i] = "'" + convertValue(expression[i + 1]) + "'"; params[i] = String.format("'%s'", encodeStr(expression[i + 1]));
} }
sql = String.format(sql, params); sql = String.format(sql, params);
print(FIND_DATA, sql); print(FIND_DATA, sql);

@ -24,7 +24,6 @@ import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -91,7 +90,7 @@ class DelegateUpdate extends AbsDelegate {
sql = sql.replace("?", "%s"); sql = sql.replace("?", "%s");
Object[] params = new String[expression.length - 1]; Object[] params = new String[expression.length - 1];
for (int i = 0, len = params.length; i < len; i++) { for (int i = 0, len = params.length; i < len; i++) {
params[i] = "'" + expression[i + 1] + "'"; params[i] = String.format("'%s'", encodeStr(expression[i + 1]));
} }
sql = String.format(sql, params); sql = String.format(sql, params);
print(DEL_DATA, sql); print(DEL_DATA, sql);
@ -122,7 +121,7 @@ class DelegateUpdate extends AbsDelegate {
value = SqlUtil.list2Str(dbEntity, field); value = SqlUtil.list2Str(dbEntity, field);
} else { } else {
Object obj = field.get(dbEntity); Object obj = field.get(dbEntity);
value = obj == null ? "" : convertValue(obj.toString()); value = obj == null ? "" : obj.toString();
} }
values.put(field.getName(), encodeStr(value)); values.put(field.getName(), encodeStr(value));
} }
@ -163,7 +162,7 @@ class DelegateUpdate extends AbsDelegate {
} else { } else {
Object obj = field.get(dbEntity); Object obj = field.get(dbEntity);
if (obj != null) { if (obj != null) {
value = convertValue(field.get(dbEntity).toString()); value = field.get(dbEntity).toString();
} }
} }
values.put(field.getName(), encodeStr(value)); values.put(field.getName(), encodeStr(value));
@ -176,11 +175,6 @@ class DelegateUpdate extends AbsDelegate {
close(db); close(db);
} }
private String encodeStr(String str) {
str = str.replaceAll("\\\\+", "%2B");
return URLEncoder.encode(str);
}
/** /**
* {@code true}自动增长的主键和需要忽略的字段 * {@code true}自动增长的主键和需要忽略的字段
*/ */

@ -59,7 +59,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
Aria.download(this).loadFtp(URL, true) Aria.download(this).loadFtp(URL)
.login("sxf", "B34VdGsJ") .login("sxf", "B34VdGsJ")
//.login("lao", "123456") //.login("lao", "123456")
.login("lao", "123456") .login("lao", "123456")

@ -1,6 +1,7 @@
package com.arialyy.simple.test; package com.arialyy.simple.test;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
@ -26,10 +27,10 @@ public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
//String URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; //String URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
//private final String URL = "ftp://192.168.29.140:21/download/AriaPrj.rar"; //private final String URL = "ftp://192.168.29.140:21/download/AriaPrj.rar";
//String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe"; //String URL = "https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
//String URL = "ftp://192.168.29.140:21/download/SDK_Demo-release.apk"; String URL = "ftp://192.168.29.140:21/download/SDK_Demo-release.apk";
//String URL = "ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]猩球崛起3:终极之战BD国英双语中英双字.mkv"; //String URL = "ftp://z:z@dygod18.com:21211/[电影天堂www.dy2018.com]猩球崛起3:终极之战BD国英双语中英双字.mkv";
//private String URL = "https://www.bilibili.com/bangumi/play/ep77693"; //private String URL = "https://www.bilibili.com/bangumi/play/ep77693";
private String URL = "http://cn-hbsjz-cmcc-v-03.acgvideo.com/upgcxcode/63/82/5108263/5108263-1-80.flv?expires=1530178500&platform=pc&ssig=vr7gLl0duyqWqSMnIpzaDA&oi=3746029570&nfa=BpfiWF+i4mNW8KzjZFHzBQ==&dynamic=1&hfa=2030547937&hfb=Yjk5ZmZjM2M1YzY4ZjAwYTMzMTIzYmIyNWY4ODJkNWI=&trid=3476be01a9254115b15f8cc7198600fe&nfc=1"; //private String URL = "http://cn-hbsjz-cmcc-v-03.acgvideo.com/upgcxcode/63/82/5108263/5108263-1-80.flv?expires=1530178500&platform=pc&ssig=vr7gLl0duyqWqSMnIpzaDA&oi=3746029570&nfa=BpfiWF+i4mNW8KzjZFHzBQ==&dynamic=1&hfa=2030547937&hfb=Yjk5ZmZjM2M1YzY4ZjAwYTMzMTIzYmIyNWY4ODJkNWI=&trid=3476be01a9254115b15f8cc7198600fe&nfc=1";
@Override protected int setLayoutId() { @Override protected int setLayoutId() {
return R.layout.activity_test; return R.layout.activity_test;
@ -48,28 +49,21 @@ public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
//module.start(); //module.start(URL);
//if (index < urls.length) { module.startFtp(URL);
// module.start(urls[index]);
// index++;
//}
//for (int i = 0; i < 10; i++) {
//module.startFtp(URL);
module.start(URL);
//}
//List<AbsEntity> list = Aria.download(this).getTotalTaskList();
//ALog.d(TAG, "size ==> " + list.size());
break; break;
case R.id.stop: case R.id.stop:
//List<AbsEntity> list = Aria.download(this).getTotalTaskList();
//
module.stop(URL); module.stop(URL);
break; break;
case R.id.cancel: case R.id.cancel:
module.cancel(URL); module.cancel(URL);
//module.cancel(); //String newUrl = "ftp://192.168.29.140:21/download/11SDK_Demo-release.apk";
//Aria.download(this)
// .loadFtp(URL)
// .updateUrl(newUrl)
// .login("lao", "123456")
// .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/")
// .start();
break; break;
} }
} }

@ -66,36 +66,12 @@ public class AnyRunnModule {
void start(String url) { void start(String url) {
mUrl = url; mUrl = url;
String path = Environment.getExternalStorageDirectory().getPath() + "/aaas.apk"; String path = Environment.getExternalStorageDirectory().getPath() + "/aaas.apk";
//File file = new File(path);
//if (file.exists()) {
// file.delete();
//}
Aria.download(this) Aria.download(this)
.load(url) .load(url)
//.addHeader("Accept-Encoding", "gzip")
.addHeader("Referer", "http://www.bilibili.com/")
.addHeader("user-agent", "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36")
.setRequestMode(RequestEnum.GET) .setRequestMode(RequestEnum.GET)
//.setUrlProxy(Proxy.NO_PROXY)
.setFilePath(path) .setFilePath(path)
.resetState() .resetState()
.start(); .start();
//String[] urls = new String[] {
// "http://cdn-s1.touchfound.net/1526449199142_3617.png",
// "http://cdn-s1.touchfound.net/mtVmResources/1526287158571.zip",
// "http://cdn-s1.touchfound.net/1526450206960_2186.png",
// "http://cdn-s1.touchfound.net/1526449199025_1476.png"
//};
//for (int i = 0, len = urls.length; i < len; i++){
//
// Aria.download(this)
// .load(urls[i])
// //.addHeader("Accept-Encoding", "gzip")
// .setRequestMode(RequestEnum.GET)
// .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg123456.apk" + i)
// //.resetState()
// .start();
//}
} }
void startFtp(String url) { void startFtp(String url) {
@ -103,26 +79,8 @@ public class AnyRunnModule {
Aria.download(this) Aria.download(this)
.loadFtp(url) .loadFtp(url)
.login("lao", "123456") .login("lao", "123456")
//.addHeader("Accept-Encoding", "gzip")
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/") .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/")
//.resetState()
.start(); .start();
//String[] urls = new String[] {
// "http://cdn-s1.touchfound.net/1526449199142_3617.png",
// "http://cdn-s1.touchfound.net/mtVmResources/1526287158571.zip",
// "http://cdn-s1.touchfound.net/1526450206960_2186.png",
// "http://cdn-s1.touchfound.net/1526449199025_1476.png"
//};
//for (int i = 0, len = urls.length; i < len; i++){
//
// Aria.download(this)
// .load(urls[i])
// //.addHeader("Accept-Encoding", "gzip")
// .setRequestMode(RequestEnum.GET)
// .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg123456.apk" + i)
// //.resetState()
// .start();
//}
} }
void stop(String url) { void stop(String url) {

@ -39,7 +39,7 @@ task clean(type: Delete) {
ext { ext {
userOrg = 'arialyy' userOrg = 'arialyy'
groupId = 'com.arialyy.aria' groupId = 'com.arialyy.aria'
publishVersion = '3.4.4' publishVersion = '3.4.5'
// publishVersion = '1.0.3' //FTP插件 // publishVersion = '1.0.3' //FTP插件
repoName='maven' repoName='maven'
desc = 'android 下载框架' desc = 'android 下载框架'

Loading…
Cancel
Save