v3.6.6
laoyuyu 6 years ago
parent 0b095b9b11
commit 66b36b355a
  1. 32
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  2. 7
      Aria/src/main/java/com/arialyy/aria/core/common/BaseListener.java
  3. 6
      Aria/src/main/java/com/arialyy/aria/core/common/OnFileInfoCallback.java
  4. 41
      Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java
  5. 15
      Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpThreadTask.java
  6. 6
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java
  7. 11
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  8. 11
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java
  9. 18
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java
  10. 7
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirDownloadUtil.java
  11. 6
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpFileInfoThread.java
  12. 32
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java
  13. 35
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java
  14. 27
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  15. 3
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadGroupListener.java
  16. 16
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/SimpleDownloadUtil.java
  17. 3
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java
  18. 31
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java
  19. 7
      Aria/src/main/java/com/arialyy/aria/core/inf/IEventListener.java
  20. 9
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java
  21. 7
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  22. 10
      Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulerListener.java
  23. 3
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadListener.java
  24. 27
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java
  25. 14
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java
  26. 6
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/SimpleUploadUtil.java
  27. 28
      Aria/src/main/java/com/arialyy/aria/exception/AriaIOException.java
  28. 35
      Aria/src/main/java/com/arialyy/aria/exception/BaseException.java
  29. 31
      Aria/src/main/java/com/arialyy/aria/exception/TaskException.java
  30. 4
      Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java
  31. 10
      Aria/src/main/java/com/arialyy/aria/util/ErrorHelp.java
  32. 53
      AriaCompiler/src/main/java/com/arialyy/compiler/EventProxyFiler.java
  33. 27
      AriaCompiler/src/main/java/com/arialyy/compiler/MethodInfo.java
  34. 89
      AriaCompiler/src/main/java/com/arialyy/compiler/ParamObtainUtil.java
  35. 2
      AriaCompiler/src/main/java/com/arialyy/compiler/ProxyClassParam.java
  36. 9
      DEV_LOG.md
  37. 11
      app/src/main/AndroidManifest.xml
  38. 148
      app/src/main/java/com/arialyy/simple/download/KotlinDownloadActivity.kt
  39. 5
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  40. 7
      app/src/main/java/com/arialyy/simple/test/AnyRunActivity.java
  41. 8
      app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java
  42. 12
      aria/src/main/java/com/arialyy/aria/exception/FileException.java
  43. 4
      gradle.properties

@ -21,6 +21,9 @@ import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEventListener; import com.arialyy.aria.core.inf.IEventListener;
import com.arialyy.aria.core.manager.ThreadTaskManager; import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.FileException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.ErrorHelp; import com.arialyy.aria.util.ErrorHelp;
import com.arialyy.aria.util.FileUtil; import com.arialyy.aria.util.FileUtil;
@ -94,6 +97,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
/** /**
* 设置线程是否中断 * 设置线程是否中断
*
* @param isInterrupted {@code true} 中断 * @param isInterrupted {@code true} 中断
*/ */
public void setInterrupted(boolean isInterrupted) { public void setInterrupted(boolean isInterrupted) {
@ -102,9 +106,10 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
/** /**
* 线程是否存活 * 线程是否存活
*
* @return {@code true}存活 * @return {@code true}存活
*/ */
protected boolean isLive(){ protected boolean isLive() {
Thread t = Thread.currentThread(); Thread t = Thread.currentThread();
return !t.isInterrupted() && !isInterrupted; return !t.isInterrupted() && !isInterrupted;
} }
@ -265,10 +270,11 @@ 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, String errorMsg =
mEntity.getFileSize())); String.format("下载失败,下载长度超出文件大;currentLocation=%s, fileSize=%s", STATE.CURRENT_LOCATION,
mEntity.getFileSize());
taskBreak = true; taskBreak = true;
fail(mChildCurrentLocation, "下载失败,下载长度超出文件大小", null, false); fail(mChildCurrentLocation, new FileException(TAG, errorMsg), false);
return; return;
} }
mChildCurrentLocation += len; mChildCurrentLocation += len;
@ -312,11 +318,10 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
* 线程任务失败 * 线程任务失败
* *
* @param subCurrentLocation 当前线程下载进度 * @param subCurrentLocation 当前线程下载进度
* @param msg 自定义信息
* @param ex 异常信息 * @param ex 异常信息
*/ */
protected void fail(final long subCurrentLocation, String msg, Exception ex) { protected void fail(final long subCurrentLocation, BaseException ex) {
fail(subCurrentLocation, msg, ex, true); fail(subCurrentLocation, ex, true);
} }
/** /**
@ -324,19 +329,17 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
* *
* @param subCurrentLocation 当前子线程进度 * @param subCurrentLocation 当前子线程进度
*/ */
protected void fail(final long subCurrentLocation, String msg, Exception ex, boolean needRetry) { protected void fail(final long subCurrentLocation, BaseException ex, boolean needRetry) {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
if (ex != null) { if (ex != null) {
ALog.e(TAG, msg + "\n" + ALog.getExceptionString(ex)); ALog.e(TAG, ALog.getExceptionString(ex));
} else {
ALog.e(TAG, msg);
} }
if (mConfig.SUPPORT_BP) { if (mConfig.SUPPORT_BP) {
writeConfig(false, subCurrentLocation); writeConfig(false, subCurrentLocation);
retryThis(needRetry && STATE.START_THREAD_NUM != 1); retryThis(needRetry && STATE.START_THREAD_NUM != 1);
} else { } else {
ALog.e(TAG, String.format("任务【%s】执行失败", mConfig.TEMP_FILE.getName())); ALog.e(TAG, String.format("任务【%s】执行失败", mConfig.TEMP_FILE.getName()));
mListener.onFail(true); mListener.onFail(true, ex);
ErrorHelp.saveError(TAG, "", ALog.getExceptionString(ex)); ErrorHelp.saveError(TAG, "", ALog.getExceptionString(ex));
} }
} }
@ -424,8 +427,9 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
STATE.isRunning = false; STATE.isRunning = false;
// 手动停止不进行fail回调 // 手动停止不进行fail回调
if (!STATE.isStop) { if (!STATE.isStop) {
ALog.e(TAG, String.format("任务【%s】执行失败", mConfig.TEMP_FILE.getName())); String errorMsg = String.format("任务【%s】执行失败", mConfig.TEMP_FILE.getName());
mListener.onFail(taskNeedReTry); //ALog.e(TAG, errorMsg);
mListener.onFail(taskNeedReTry, new TaskException(TAG, errorMsg));
} }
} }
} }

@ -24,7 +24,10 @@ import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.IEventListener; import com.arialyy.aria.core.inf.IEventListener;
import com.arialyy.aria.core.inf.TaskSchedulerType; import com.arialyy.aria.core.inf.TaskSchedulerType;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ErrorHelp;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
public abstract class BaseListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>, TASK extends AbsTask<ENTITY, TASK_ENTITY>> public abstract class BaseListener<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>, TASK extends AbsTask<ENTITY, TASK_ENTITY>>
@ -103,12 +106,14 @@ public abstract class BaseListener<ENTITY extends AbsEntity, TASK_ENTITY extends
sendInState2Target(ISchedulers.CANCEL); sendInState2Target(ISchedulers.CANCEL);
} }
@Override public void onFail(boolean needRetry) { @Override public void onFail(boolean needRetry, BaseException e) {
mEntity.setFailNum(mEntity.getFailNum() + 1); mEntity.setFailNum(mEntity.getFailNum() + 1);
saveData(IEntity.STATE_FAIL, mEntity.getCurrentProgress()); saveData(IEntity.STATE_FAIL, mEntity.getCurrentProgress());
handleSpeed(0); handleSpeed(0);
mTask.needRetry = needRetry; mTask.needRetry = needRetry;
sendInState2Target(ISchedulers.FAIL); sendInState2Target(ISchedulers.FAIL);
e.printStackTrace();
ErrorHelp.saveError(e.getTag(), "", ALog.getExceptionString(e));
} }
private void handleSpeed(long speed) { private void handleSpeed(long speed) {

@ -15,6 +15,8 @@
*/ */
package com.arialyy.aria.core.common; package com.arialyy.aria.core.common;
import com.arialyy.aria.exception.BaseException;
public interface OnFileInfoCallback { public interface OnFileInfoCallback {
/** /**
* 处理完成 * 处理完成
@ -26,7 +28,7 @@ public interface OnFileInfoCallback {
/** /**
* 请求失败 * 请求失败
* *
* @param errorMsg 错误信息 * @param e 错误信息
*/ */
void onFail(String url, String errorMsg, boolean needRetry); void onFail(String url, BaseException e, boolean needRetry);
} }

@ -23,6 +23,10 @@ import com.arialyy.aria.core.common.ProtocolType;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.FileException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.Regular; import com.arialyy.aria.util.Regular;
import com.arialyy.aria.util.SSLContextUtil; import com.arialyy.aria.util.SSLContextUtil;
@ -90,8 +94,9 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
FTPFile[] files = client.listFiles(remotePath); FTPFile[] files = client.listFiles(remotePath);
boolean isExist = files.length != 0; boolean isExist = files.length != 0;
if (!isExist && !isUpload) { if (!isExist && !isUpload) {
failDownload(String.format("文件不存在,任务链接【%s】,remotePath:%s", mTaskEntity.getUrlEntity().url, failDownload(new FileException(TAG,
remotePath), false); String.format("文件不存在,url: %s, remotePath:%s", mTaskEntity.getUrlEntity().url,
remotePath)), false);
int i = remotePath.lastIndexOf(File.separator); int i = remotePath.lastIndexOf(File.separator);
FTPFile[] files1; FTPFile[] files1;
if (i == -1) { if (i == -1) {
@ -122,8 +127,9 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
mTaskEntity.setNewTask(true); mTaskEntity.setNewTask(true);
} else { } else {
client.disconnect(); client.disconnect();
failDownload(String.format("获取文件信息错误,错误码为:%s,msg:%s", reply, client.getReplyString()), failDownload(new AriaIOException(TAG,
true); String.format("获取文件信息错误,url: %s, errorCode:%s, errorMsg:%s",
mTaskEntity.getUrlEntity().url, reply, client.getReplyString())), true);
return; return;
} }
} }
@ -134,10 +140,9 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
mTaskEntity.update(); mTaskEntity.update();
onPreComplete(reply); onPreComplete(reply);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); failDownload(new AriaIOException(TAG,
ALog.e(TAG, String.format("FTP错误信息,code:%s,msg:%s", client.getReplyCode(), client.getReplyString()),
String.format("FTP错误信息,code:%s,msg:%s", client.getReplyCode(), client.getReplyString())); e), true);
failDownload(e.getMessage(), true);
} finally { } finally {
closeClient(client); closeClient(client);
} }
@ -195,7 +200,8 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
} }
if (client == null) { if (client == null) {
failDownload("链接失败", false); failDownload(new AriaIOException(TAG,
String.format("链接失败, url: %s", mTaskEntity.getUrlEntity().url)), false);
return null; return null;
} }
@ -208,15 +214,17 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
loginSuccess = client.login(urlEntity.user, urlEntity.password, urlEntity.account); loginSuccess = client.login(urlEntity.user, urlEntity.password, urlEntity.account);
} }
} catch (IOException e) { } catch (IOException e) {
ALog.e(TAG, String.format("登录失败,错误码为:%s, msg:%s", client.getReplyCode(), ALog.e(TAG,
client.getReplyString())); new TaskException(TAG, String.format("登录失败,错误码为:%s, msg:%s", client.getReplyCode(),
client.getReplyString()), e));
return null; return null;
} }
} }
if (!loginSuccess) { if (!loginSuccess) {
failDownload( failDownload(
String.format("登录失败,错误码为:%s, msg:%s", client.getReplyCode(), client.getReplyString()), new TaskException(TAG, String.format("登录失败,错误码为:%s, msg:%s", client.getReplyCode(),
client.getReplyString())),
false); false);
client.disconnect(); client.disconnect();
return null; return null;
@ -225,7 +233,9 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
int reply = client.getReplyCode(); int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) { if (!FTPReply.isPositiveCompletion(reply)) {
client.disconnect(); client.disconnect();
failDownload(String.format("无法连接到ftp服务器,错误码为:%s,msg:%s", reply, client.getReplyString()), failDownload(new AriaIOException(TAG,
String.format("无法连接到ftp服务器,filePath: %s, url: %s, errorCode: %s, errorMsg:%s",
mEntity.getKey(), mTaskEntity.getUrlEntity().url, reply, client.getReplyString())),
true); true);
return null; return null;
} }
@ -353,10 +363,9 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
protected void handleFile(String remotePath, FTPFile ftpFile) { protected void handleFile(String remotePath, FTPFile ftpFile) {
} }
private void failDownload(String errorMsg, boolean needRetry) { private void failDownload(BaseException e, boolean needRetry) {
ALog.e(TAG, errorMsg);
if (mCallback != null) { if (mCallback != null) {
mCallback.onFail(mEntity.getKey(), errorMsg, needRetry); mCallback.onFail(mEntity.getKey(), e, needRetry);
} }
} }

@ -16,7 +16,6 @@
package com.arialyy.aria.core.common.ftp; package com.arialyy.aria.core.common.ftp;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.common.AbsThreadTask; import com.arialyy.aria.core.common.AbsThreadTask;
import com.arialyy.aria.core.common.ProtocolType; import com.arialyy.aria.core.common.ProtocolType;
@ -25,9 +24,9 @@ import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.inf.AbsNormalEntity; import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEventListener; import com.arialyy.aria.core.inf.IEventListener;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.SSLContextUtil; import com.arialyy.aria.util.SSLContextUtil;
import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
@ -74,7 +73,7 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTI
client = newInstanceClient(urlEntity); client = newInstanceClient(urlEntity);
try { try {
client.connect(urlEntity.validAddr, Integer.parseInt(urlEntity.port)); client.connect(urlEntity.validAddr, Integer.parseInt(urlEntity.port));
} catch (IOException e) { } catch (java.io.IOException e) {
ALog.e(TAG, ALog.getExceptionString(e)); ALog.e(TAG, ALog.getExceptionString(e));
return null; return null;
} }
@ -101,8 +100,8 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTI
int reply = client.getReplyCode(); int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) { if (!FTPReply.isPositiveCompletion(reply)) {
client.disconnect(); client.disconnect();
fail(mChildCurrentLocation, fail(mChildCurrentLocation, new AriaIOException(TAG,
String.format("无法连接到ftp服务器,错误码为:%s,msg:%s", reply, client.getReplyString()), null); String.format("无法连接到ftp服务器,错误码为:%s,msg:%s", reply, client.getReplyString())), false);
return null; return null;
} }
// 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码 // 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码
@ -121,7 +120,7 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTI
if (mTaskEntity.getUrlEntity().isFtps) { if (mTaskEntity.getUrlEntity().isFtps) {
((FTPSClient) client).execPROT("P"); ((FTPSClient) client).execPROT("P");
} }
} catch (IOException e) { } catch (java.io.IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return client; return client;
@ -154,12 +153,12 @@ public abstract class AbsFtpThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTI
client.connect(ips[index], port); client.connect(ips[index], port);
mTaskEntity.getUrlEntity().validAddr = ips[index]; mTaskEntity.getUrlEntity().validAddr = ips[index];
return client; return client;
} catch (IOException e) { } catch (java.io.IOException e) {
try { try {
if (client.isConnected()) { if (client.isConnected()) {
client.disconnect(); client.disconnect();
} }
} catch (IOException e1) { } catch (java.io.IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
if (index + 1 >= ips.length) { if (index + 1 >= ips.length) {

@ -21,8 +21,10 @@ import com.arialyy.aria.core.download.downloader.IDownloadGroupListener;
import com.arialyy.aria.core.inf.GroupSendParams; import com.arialyy.aria.core.inf.GroupSendParams;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.scheduler.ISchedulers;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ErrorHelp;
/** /**
* Created by Aria.Lao on 2017/7/20. * Created by Aria.Lao on 2017/7/20.
@ -64,9 +66,11 @@ class DownloadGroupListener
sendInState2Target(ISchedulers.SUB_COMPLETE, subEntity); sendInState2Target(ISchedulers.SUB_COMPLETE, subEntity);
} }
@Override public void onSubFail(DownloadEntity subEntity) { @Override public void onSubFail(DownloadEntity subEntity, BaseException e) {
saveCurrentLocation(); saveCurrentLocation();
sendInState2Target(ISchedulers.SUB_FAIL, subEntity); sendInState2Target(ISchedulers.SUB_FAIL, subEntity);
e.printStackTrace();
ErrorHelp.saveError(e.getTag(), "", ALog.getExceptionString(e));
} }
@Override public void onSubCancel(DownloadEntity subEntity) { @Override public void onSubCancel(DownloadEntity subEntity) {

@ -22,6 +22,8 @@ import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.NetUtils; import com.arialyy.aria.util.NetUtils;
@ -482,7 +484,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
} }
} }
@Override public void onFail(boolean needRetry) { @Override public void onFail(boolean needRetry, BaseException e) {
subEntity.setFailNum(subEntity.getFailNum() + 1); subEntity.setFailNum(subEntity.getFailNum() + 1);
saveData(IEntity.STATE_FAIL, lastLen); saveData(IEntity.STATE_FAIL, lastLen);
handleSpeed(0); handleSpeed(0);
@ -504,12 +506,15 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
reStartTask(dt); reStartTask(dt);
} else { } else {
mFailMap.put(subTaskEntity.getUrl(), subTaskEntity); mFailMap.put(subTaskEntity.getUrl(), subTaskEntity);
mListener.onSubFail(subEntity); mListener.onSubFail(subEntity, new TaskException(TAG,
String.format("任务组子任务【%s】下载失败,下载地址【%s】", subEntity.getFileName(),
subEntity.getUrl())));
if (mFailMap.size() == mExeMap.size() || mFailMap.size() + mCompleteNum == mGroupSize) { if (mFailMap.size() == mExeMap.size() || mFailMap.size() + mCompleteNum == mGroupSize) {
closeTimer(); closeTimer();
} }
if (mFailMap.size() == mGroupSize) { if (mFailMap.size() == mGroupSize) {
mListener.onFail(true); mListener.onFail(true, new TaskException(TAG,
String.format("任务组【%s】下载失败", mGTEntity.getEntity().getGroupName())));
} else if (mFailMap.size() + mCompleteNum >= mExeMap.size()) { } else if (mFailMap.size() + mCompleteNum >= mExeMap.size()) {
mListener.onStop(mCurrentLocation); mListener.onStop(mCurrentLocation);
} }

@ -22,6 +22,8 @@ import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -85,8 +87,8 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
} }
if (mExeMap.size() == 0) { if (mExeMap.size() == 0) {
ALog.e(TAG, "任务组无可执行任务"); mListener.onFail(false, new TaskException(TAG,
mListener.onFail(false); String.format("任务组【%s】无可执行任务", mGTEntity.getEntity().getGroupName())));
return; return;
} }
Set<String> keys = mExeMap.keySet(); Set<String> keys = mExeMap.keySet();
@ -133,7 +135,7 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
checkStartFlow(); checkStartFlow();
} }
@Override public void onFail(String url, String errorMsg, boolean needRetry) { @Override public void onFail(String url, BaseException e, boolean needRetry) {
if (isStop) return; if (isStop) return;
ALog.e(TAG, String.format("任务【%s】初始化失败", url)); ALog.e(TAG, String.format("任务【%s】初始化失败", url));
DownloadTaskEntity te = mExeMap.get(url); DownloadTaskEntity te = mExeMap.get(url);
@ -169,7 +171,8 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil {
} }
if (mInitFailNum == mExeNum) { if (mInitFailNum == mExeNum) {
closeTimer(); closeTimer();
mListener.onFail(true); mListener.onFail(true, new TaskException(TAG,
String.format("任务组【%s】初始化失败", mGTEntity.getEntity().getGroupName())));
} }
if (!isStart && mInitCompleteNum + mInitFailNum == mExeNum || !isNeedLoadFileSize) { if (!isStart && mInitCompleteNum + mInitFailNum == mExeNum || !isNeedLoadFileSize) {
startRunningFlow(); startRunningFlow();

@ -23,10 +23,9 @@ import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.BufferedRandomAccessFile;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ErrorHelp;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -58,7 +57,7 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
@Override protected boolean handleNewTask() { @Override protected boolean handleNewTask() {
if (!mRecord.isBlock) { if (!mRecord.isBlock) {
if (mTempFile.exists()){ if (mTempFile.exists()) {
mTempFile.delete(); mTempFile.delete();
} }
//CommonUtil.createFile(mTempFile.getPath()); //CommonUtil.createFile(mTempFile.getPath());
@ -72,8 +71,9 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
} }
return true; return true;
} catch (IOException e) { } catch (IOException e) {
failDownload(String.format("下载失败【downloadUrl:%s】;【filePath:%s】\n %S", mEntity.getUrl(), failDownload(new TaskException(TAG,
mEntity.getDownloadPath(), ALog.getExceptionString(e))); String.format("下载失败,filePath: %s, url: %s", mEntity.getDownloadPath(),
mEntity.getUrl()), e));
} finally { } finally {
if (file != null) { if (file != null) {
try { try {
@ -106,11 +106,9 @@ class Downloader extends AbsFileer<DownloadEntity, DownloadTaskEntity> {
return null; return null;
} }
private void failDownload(String errorMsg) { private void failDownload(BaseException e) {
closeTimer(); closeTimer();
ALog.e(TAG, errorMsg);
mConstance.isRunning = false; mConstance.isRunning = false;
mListener.onFail(false); mListener.onFail(false, e);
ErrorHelp.saveError(TAG, "", errorMsg);
} }
} }

@ -19,6 +19,8 @@ import com.arialyy.aria.core.common.CompleteInfo;
import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ErrorHelp; import com.arialyy.aria.util.ErrorHelp;
import java.util.Set; import java.util.Set;
@ -51,14 +53,13 @@ public class FtpDirDownloadUtil extends AbsGroupUtil {
} }
} }
@Override public void onFail(String url, String errorMsg, boolean needRetry) { @Override public void onFail(String url, BaseException e, boolean needRetry) {
DownloadTaskEntity te = mExeMap.get(url); DownloadTaskEntity te = mExeMap.get(url);
if (te != null) { if (te != null) {
mFailMap.put(url, te); mFailMap.put(url, te);
mExeMap.remove(url); mExeMap.remove(url);
} }
mListener.onFail(needRetry); mListener.onFail(needRetry, e);
ErrorHelp.saveError(TAG, "", errorMsg);
} }
}).start(); }).start();
} }

@ -20,6 +20,7 @@ import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.common.ftp.AbsFtpInfoThread; import com.arialyy.aria.core.common.ftp.AbsFtpInfoThread;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPFile;
@ -28,6 +29,7 @@ import org.apache.commons.net.ftp.FTPFile;
* 获取ftp文件信息 * 获取ftp文件信息
*/ */
class FtpFileInfoThread extends AbsFtpInfoThread<DownloadEntity, DownloadTaskEntity> { class FtpFileInfoThread extends AbsFtpInfoThread<DownloadEntity, DownloadTaskEntity> {
private final String TAG = "FtpFileInfoThread";
FtpFileInfoThread(DownloadTaskEntity taskEntity, OnFileInfoCallback callback) { FtpFileInfoThread(DownloadTaskEntity taskEntity, OnFileInfoCallback callback) {
super(taskEntity, callback); super(taskEntity, callback);
@ -36,7 +38,9 @@ class FtpFileInfoThread extends AbsFtpInfoThread<DownloadEntity, DownloadTaskEnt
@Override protected void handleFile(String remotePath, FTPFile ftpFile) { @Override protected void handleFile(String remotePath, FTPFile ftpFile) {
super.handleFile(remotePath, ftpFile); super.handleFile(remotePath, ftpFile);
if (!CommonUtil.checkSDMemorySpace(mEntity.getDownloadPath(), ftpFile.getSize())) { if (!CommonUtil.checkSDMemorySpace(mEntity.getDownloadPath(), ftpFile.getSize())) {
mCallback.onFail(mEntity.getUrl(), String.format("路径【%s】内存空间不足", mEntity.getDownloadPath()), mCallback.onFail(mEntity.getUrl(),
new AriaIOException(TAG,
String.format("获取ftp文件信息失败,内存空间不足, filePath: %s", mEntity.getDownloadPath())),
false); false);
} }
} }

@ -21,6 +21,8 @@ import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.BufferedRandomAccessFile;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -69,7 +71,7 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
mConfig.THREAD_ID, mConfig.START_LOCATION, mConfig.END_LOCATION)); mConfig.THREAD_ID, mConfig.START_LOCATION, mConfig.END_LOCATION));
client = createClient(); client = createClient();
if (client == null) { if (client == null) {
fail(mChildCurrentLocation, "ftp client 创建失败", null); fail(mChildCurrentLocation, new TaskException(TAG, "ftp client 创建失败"));
return this; return this;
} }
if (mConfig.START_LOCATION > 0) { if (mConfig.START_LOCATION > 0) {
@ -79,8 +81,8 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
int reply = client.getReplyCode(); int reply = client.getReplyCode();
if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) { if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) {
fail(mChildCurrentLocation, fail(mChildCurrentLocation,
String.format("获取文件信息错误,错误码为:%s,msg:%s", reply, client.getReplyString()), new AriaIOException(TAG,
null); String.format("获取文件信息错误,错误码为:%s,msg:%s", reply, client.getReplyString())));
client.disconnect(); client.disconnect();
return this; return this;
} }
@ -91,8 +93,8 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
reply = client.getReplyCode(); reply = client.getReplyCode();
if (!FTPReply.isPositivePreliminary(reply)) { if (!FTPReply.isPositivePreliminary(reply)) {
fail(mChildCurrentLocation, fail(mChildCurrentLocation,
String.format("获取流失败,错误码为:%s,msg:%s", reply, client.getReplyString()), new AriaIOException(TAG,
null); String.format("获取流失败,错误码为:%s,msg:%s", reply, client.getReplyString())));
client.disconnect(); client.disconnect();
return this; return this;
} }
@ -104,9 +106,11 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
handleComplete(); handleComplete();
} }
} catch (IOException e) { } catch (IOException e) {
fail(mChildCurrentLocation, String.format("下载失败【%s】", mConfig.URL), e); fail(mChildCurrentLocation,
new AriaIOException(TAG, String.format("下载失败【%s】", mConfig.URL), e));
} catch (Exception e) { } catch (Exception e) {
fail(mChildCurrentLocation, "获取流失败", e); fail(mChildCurrentLocation,
new AriaIOException(TAG, String.format("下载失败【%s】", mConfig.URL), e));
} finally { } finally {
try { try {
if (is != null) { if (is != null) {
@ -137,9 +141,10 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
if (isBlock) { if (isBlock) {
boolean success = mergeFile(); boolean success = mergeFile();
if (!success) { if (!success) {
ALog.e(TAG, String.format("任务【%s】分块文件合并失败", mConfig.TEMP_FILE.getName())); //ALog.e(TAG, String.format("任务【%s】分块文件合并失败", mConfig.TEMP_FILE.getName()));
STATE.isRunning = false; STATE.isRunning = false;
mListener.onFail(false); mListener.onFail(false,
new TaskException(TAG, String.format("任务【%s】分块文件合并失败", mConfig.TEMP_FILE.getName())));
return; return;
} }
} }
@ -149,7 +154,8 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
} }
if (STATE.isFail()) { if (STATE.isFail()) {
STATE.isRunning = false; STATE.isRunning = false;
mListener.onFail(false); mListener.onFail(false,
new TaskException(TAG, String.format("任务【%s】下载失败", mConfig.TEMP_FILE.getName())));
} }
} }
@ -189,7 +195,8 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
} }
handleComplete(); handleComplete();
} catch (IOException e) { } catch (IOException e) {
fail(mChildCurrentLocation, String.format("下载失败【%s】", mConfig.URL), e); fail(mChildCurrentLocation,
new AriaIOException(TAG, String.format("下载失败【%s】", mConfig.URL), e));
} finally { } finally {
try { try {
if (fos != null) { if (fos != null) {
@ -235,7 +242,8 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
} }
} }
} catch (IOException e) { } catch (IOException e) {
fail(mChildCurrentLocation, String.format("下载失败【%s】", mConfig.URL), e); fail(mChildCurrentLocation,
new AriaIOException(TAG, String.format("下载失败【%s】", mConfig.URL), e));
} finally { } finally {
try { try {
if (file != null) { if (file != null) {

@ -22,6 +22,9 @@ import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -67,12 +70,9 @@ class HttpFileInfoThread implements Runnable {
conn.connect(); conn.connect();
handleConnect(conn); handleConnect(conn);
} catch (IOException e) { } catch (IOException e) {
failDownload("下载失败【downloadUrl:" failDownload(new AriaIOException(TAG,
+ mEntity.getUrl() String.format("下载失败,filePath: %s, url: %s", mEntity.getDownloadPath(), mEntity.getUrl())),
+ "】\n【filePath:" true);
+ mEntity.getDownloadPath()
+ "】\n"
+ ALog.getExceptionString(e), true);
} finally { } finally {
if (conn != null) { if (conn != null) {
conn.disconnect(); conn.disconnect();
@ -116,7 +116,9 @@ class HttpFileInfoThread implements Runnable {
} }
if (!CommonUtil.checkSDMemorySpace(mEntity.getDownloadPath(), len)) { if (!CommonUtil.checkSDMemorySpace(mEntity.getDownloadPath(), len)) {
failDownload(String.format("路径【%s】内存空间不足", mEntity.getDownloadPath()), false); failDownload(new TaskException(TAG,
String.format("下载失败,内存空间不足;filePath: %s, url: %s", mEntity.getDownloadPath(),
mEntity.getUrl())), false);
return; return;
} }
@ -184,14 +186,16 @@ class HttpFileInfoThread implements Runnable {
mTaskEntity.setSupportBP(false); mTaskEntity.setSupportBP(false);
end = true; end = true;
} else if (code == HttpURLConnection.HTTP_NOT_FOUND) { } else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
failDownload("任务【" + mEntity.getUrl() + "】下载失败,错误码:404", true); failDownload(new AriaIOException(TAG,
String.format("任务下载失败,errorCode:404, url: %s", mEntity.getUrl())), true);
} else if (code == HttpURLConnection.HTTP_MOVED_TEMP } else if (code == HttpURLConnection.HTTP_MOVED_TEMP
|| code == HttpURLConnection.HTTP_MOVED_PERM || code == HttpURLConnection.HTTP_MOVED_PERM
|| code == HttpURLConnection.HTTP_SEE_OTHER || code == HttpURLConnection.HTTP_SEE_OTHER
|| code == 307) { || code == 307) {
handleUrlReTurn(conn, conn.getHeaderField("Location")); handleUrlReTurn(conn, conn.getHeaderField("Location"));
} else { } else {
failDownload("任务【" + mEntity.getUrl() + "】下载失败,错误码:" + code, true); failDownload(new AriaIOException(TAG,
String.format("任务下载失败,errorCode:%s, url: %s", code, mEntity.getUrl())), true);
} }
if (end) { if (end) {
mTaskEntity.setChunked(isChunked); mTaskEntity.setChunked(isChunked);
@ -229,12 +233,12 @@ class HttpFileInfoThread implements Runnable {
if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null") || !newUrl.startsWith( if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null") || !newUrl.startsWith(
"http")) { "http")) {
if (onFileInfoCallback != null) { if (onFileInfoCallback != null) {
onFileInfoCallback.onFail(mEntity.getUrl(), "获取重定向链接失败", false); onFileInfoCallback.onFail(mEntity.getUrl(), new TaskException(TAG, "获取重定向链接失败"), false);
} }
return; return;
} }
if (!CheckUtil.checkUrl(newUrl)) { if (!CheckUtil.checkUrl(newUrl)) {
failDownload("下载失败,重定向url错误", false); failDownload(new TaskException(TAG, "下载失败,重定向url错误"), false);
return; return;
} }
mTaskEntity.setRedirectUrl(newUrl); mTaskEntity.setRedirectUrl(newUrl);
@ -263,16 +267,17 @@ class HttpFileInfoThread implements Runnable {
mTaskEntity.setNewTask(true); mTaskEntity.setNewTask(true);
} }
if (len < 0) { if (len < 0) {
failDownload("任务【" + mEntity.getUrl() + "】下载失败,文件长度小于0", true); failDownload(
new AriaIOException(TAG, String.format("任务下载失败,文件长度小于0, url: %s", mEntity.getUrl())),
true);
return false; return false;
} }
return true; return true;
} }
private void failDownload(String errorMsg, boolean needRetry) { private void failDownload(BaseException e, boolean needRetry) {
ALog.e(TAG, errorMsg);
if (onFileInfoCallback != null) { if (onFileInfoCallback != null) {
onFileInfoCallback.onFail(mEntity.getUrl(), errorMsg, needRetry); onFileInfoCallback.onFail(mEntity.getUrl(), e, needRetry);
} }
} }
} }

@ -22,6 +22,8 @@ import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.BufferedRandomAccessFile;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -121,11 +123,17 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
handleComplete(); handleComplete();
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
fail(mChildCurrentLocation, "下载链接异常", e); fail(mChildCurrentLocation, new TaskException(TAG,
String.format("任务【%s】下载失败,filePath: %s, url: %s", mConfig.TEMP_FILE.getName(),
mEntity.getDownloadPath(), mEntity.getUrl()), e));
} catch (IOException e) { } catch (IOException e) {
fail(mChildCurrentLocation, String.format("下载失败【%s】", mConfig.URL), e); fail(mChildCurrentLocation, new TaskException(TAG,
String.format("任务【%s】下载失败,filePath: %s, url: %s", mConfig.TEMP_FILE.getName(),
mEntity.getDownloadPath(), mEntity.getUrl()), e));
} catch (Exception e) { } catch (Exception e) {
fail(mChildCurrentLocation, "获取流失败", e); fail(mChildCurrentLocation, new TaskException(TAG,
String.format("任务【%s】下载失败,filePath: %s, url: %s", mConfig.TEMP_FILE.getName(),
mEntity.getDownloadPath(), mEntity.getUrl()), e));
} finally { } finally {
try { try {
if (file != null) { if (file != null) {
@ -182,7 +190,9 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
} }
handleComplete(); handleComplete();
} catch (IOException e) { } catch (IOException e) {
fail(mChildCurrentLocation, String.format("下载失败【%s】", mConfig.URL), e); fail(mChildCurrentLocation, new AriaIOException(TAG,
String.format("文件下载失败,savePath: %s, url: %s", mEntity.getDownloadPath(), mConfig.URL),
e));
} finally { } finally {
try { try {
if (fos != null) { if (fos != null) {
@ -249,9 +259,9 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
if (isBlock) { if (isBlock) {
boolean success = mergeFile(); boolean success = mergeFile();
if (!success) { if (!success) {
ALog.e(TAG, String.format("任务【%s】分块文件合并失败", mConfig.TEMP_FILE.getName()));
STATE.isRunning = false; STATE.isRunning = false;
mListener.onFail(false); mListener.onFail(false, new TaskException(TAG,
String.format("任务【%s】分块文件合并失败", mConfig.TEMP_FILE.getName())));
return; return;
} }
} }
@ -261,7 +271,10 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
} }
if (STATE.isFail()) { if (STATE.isFail()) {
STATE.isRunning = false; STATE.isRunning = false;
mListener.onFail(false); mListener.onFail(false,
new TaskException(TAG,
String.format("任务【%s】下载失败,filePath: %s, url: %s", mConfig.TEMP_FILE.getName(),
mEntity.getDownloadPath(), mEntity.getUrl())));
} }
} else { } else {
ALog.i(TAG, "任务下载完成"); ALog.i(TAG, "任务下载完成");

@ -17,6 +17,7 @@ package com.arialyy.aria.core.download.downloader;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.exception.BaseException;
/** /**
* Created by Aria.Lao on 2017/7/20. * Created by Aria.Lao on 2017/7/20.
@ -54,7 +55,7 @@ public interface IDownloadGroupListener extends IDownloadListener {
/** /**
* 子任务下载失败 * 子任务下载失败
*/ */
void onSubFail(DownloadEntity subEntity); void onSubFail(DownloadEntity subEntity, BaseException e);
/** /**
* 子任务取消下载 * 子任务取消下载

@ -23,7 +23,8 @@ import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IDownloadListener;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.ErrorHelp; import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException;
/** /**
* Created by lyy on 2015/8/25. * Created by lyy on 2015/8/25.
@ -91,12 +92,11 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
mDownloader.setMaxSpeed(speed); mDownloader.setMaxSpeed(speed);
} }
private void failDownload(String msg, boolean needRetry) { private void failDownload(BaseException e, boolean needRetry) {
if (isStop || isCancel) { if (isStop || isCancel) {
return; return;
} }
mListener.onFail(needRetry); mListener.onFail(needRetry, e);
ErrorHelp.saveError(TAG, msg, "");
} }
@Override public void run() { @Override public void run() {
@ -125,8 +125,8 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
mDownloader.start(); mDownloader.start();
} }
@Override public void onFail(String url, String errorMsg, boolean needRetry) { @Override public void onFail(String url, BaseException e, boolean needRetry) {
failDownload(errorMsg, needRetry); failDownload(e, needRetry);
} }
}); });
case AbsTaskEntity.D_HTTP: case AbsTaskEntity.D_HTTP:
@ -135,8 +135,8 @@ public class SimpleDownloadUtil implements IUtil, Runnable {
mDownloader.start(); mDownloader.start();
} }
@Override public void onFail(String url, String errorMsg, boolean needRetry) { @Override public void onFail(String url, BaseException e, boolean needRetry) {
failDownload(errorMsg, needRetry); failDownload(e, needRetry);
} }
}); });
} }

@ -19,11 +19,12 @@ import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.annotation.Ignore; import com.arialyy.aria.orm.annotation.Ignore;
import java.io.Serializable;
/** /**
* Created by AriaL on 2017/6/29. * Created by AriaL on 2017/6/29.
*/ */
public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable { public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable, Serializable {
/** /**
* 速度 * 速度
*/ */

@ -17,15 +17,20 @@ package com.arialyy.aria.core.inf;
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
import android.text.TextUtils;
import com.arialyy.aria.core.common.IUtil; import com.arialyy.aria.core.common.IUtil;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.util.HashMap;
import java.util.Map;
/** /**
* Created by AriaL on 2017/6/29. * Created by AriaL on 2017/6/29.
*/ */
public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity> public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity>
implements ITask<TASK_ENTITY> { implements ITask<TASK_ENTITY> {
public static final String ERROR_INFO_KEY = "ERROR_INFO_KEY";
/** /**
* 是否需要重试默认为true * 是否需要重试默认为true
*/ */
@ -36,6 +41,10 @@ public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsT
boolean isHeighestTask = false; boolean isHeighestTask = false;
private boolean isCancel = false, isStop = false; private boolean isCancel = false, isStop = false;
protected IUtil mUtil; protected IUtil mUtil;
/**
* 扩展信息
*/
private Map<String, Object> mExpand = new HashMap<>();
/** /**
* 该任务的调度类型 * 该任务的调度类型
*/ */
@ -53,6 +62,28 @@ public abstract class AbsTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsT
return mOutHandler; return mOutHandler;
} }
/**
* 添加扩展数据
* 读取扩展数据{@link #getExpand(String)}
*/
public void putExpand(String key, Object obj) {
if (TextUtils.isEmpty(key)) {
ALog.e(TAG, "key 为空");
return;
} else if (obj == null) {
ALog.e(TAG, "扩展数据为空");
return;
}
mExpand.put(key, obj);
}
/**
* 读取扩展数据
*/
public Object getExpand(String key) {
return mExpand.get(key);
}
/** /**
* 设置最大下载/上传速度 * 设置最大下载/上传速度
* *

@ -15,6 +15,8 @@
*/ */
package com.arialyy.aria.core.inf; package com.arialyy.aria.core.inf;
import com.arialyy.aria.exception.BaseException;
/** /**
* Created by Aria.Lao on 2017/7/18. * Created by Aria.Lao on 2017/7/18.
* 基础事件 * 基础事件
@ -58,8 +60,9 @@ public interface IEventListener {
/** /**
* 下载失败 * 下载失败
*
* @param needRetry 是否需要重试{@code true} 需要 * @param needRetry 是否需要重试{@code true} 需要
* @param e 失败信息
*/ */
void onFail(boolean needRetry); void onFail(boolean needRetry, BaseException e);
} }

@ -56,6 +56,10 @@ public class AbsSchedulerListener<TASK extends ITask, SUB_ENTITY extends AbsNorm
} }
@Override public void onTaskFail(TASK task, Exception e) {
}
@Override public void onTaskComplete(TASK task) { @Override public void onTaskComplete(TASK task) {
} }
@ -92,10 +96,15 @@ public class AbsSchedulerListener<TASK extends ITask, SUB_ENTITY extends AbsNorm
} }
@Deprecated
public void onSubTaskFail(TASK task, SUB_ENTITY subTask) { public void onSubTaskFail(TASK task, SUB_ENTITY subTask) {
} }
public void onSubTaskFail(TASK task, SUB_ENTITY subTask, Exception e) {
}
public void onSubTaskRunning(TASK task, SUB_ENTITY subTask) { public void onSubTaskRunning(TASK task, SUB_ENTITY subTask) {
} }

@ -140,7 +140,8 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
listener.onSubTaskStop((TASK) params.groupTask, params.entity); listener.onSubTaskStop((TASK) params.groupTask, params.entity);
break; break;
case SUB_FAIL: case SUB_FAIL:
listener.onSubTaskFail((TASK) params.groupTask, params.entity); listener.onSubTaskFail((TASK) params.groupTask, params.entity,
(Exception) (params.groupTask).getExpand(AbsTask.ERROR_INFO_KEY));
break; break;
case SUB_RUNNING: case SUB_RUNNING:
listener.onSubTaskRunning((TASK) params.groupTask, params.entity); listener.onSubTaskRunning((TASK) params.groupTask, params.entity);
@ -244,7 +245,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
listener.onTaskComplete(task); listener.onTaskComplete(task);
break; break;
case FAIL: case FAIL:
listener.onTaskFail(task); listener.onTaskFail(task, (Exception) task.getExpand(AbsTask.ERROR_INFO_KEY));
break; break;
case SUPPORT_BREAK_POINT: case SUPPORT_BREAK_POINT:
listener.onNoSupportBreakPoint(task); listener.onNoSupportBreakPoint(task);
@ -317,7 +318,7 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
* 启动下一个任务条件任务停止取消下载任务完成 * 启动下一个任务条件任务停止取消下载任务完成
*/ */
private void startNextTask(TASK oldTask) { private void startNextTask(TASK oldTask) {
if (oldTask.getSchedulerType() == TaskSchedulerType.TYPE_STOP_NOT_NEXT){ if (oldTask.getSchedulerType() == TaskSchedulerType.TYPE_STOP_NOT_NEXT) {
return; return;
} }
TASK newTask = mQueue.getNextTask(); TASK newTask = mQueue.getNextTask();

@ -59,10 +59,18 @@ public interface ISchedulerListener<TASK extends ITask> {
void onTaskCancel(TASK task); void onTaskCancel(TASK task);
/** /**
* 任务下载失败 * 任务失败
*
* @deprecated @see{{@link #onTaskFail(ITask, Exception)}}
*/ */
@Deprecated
void onTaskFail(TASK task); void onTaskFail(TASK task);
/**
* 任务失败
*/
void onTaskFail(TASK task, Exception e);
/** /**
* 任务完成 * 任务完成
*/ */

@ -16,6 +16,7 @@
package com.arialyy.aria.core.upload; package com.arialyy.aria.core.upload;
import com.arialyy.aria.core.inf.IUploadListener; import com.arialyy.aria.core.inf.IUploadListener;
import com.arialyy.aria.exception.BaseException;
/** /**
* Created by lyy on 2017/2/23. * Created by lyy on 2017/2/23.
@ -49,7 +50,7 @@ class UploadListener implements IUploadListener {
} }
@Override public void onFail(boolean needRetry) { @Override public void onFail(boolean needRetry, BaseException e) {
} }
} }

@ -21,6 +21,8 @@ import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask;
import com.arialyy.aria.core.inf.IEventListener; import com.arialyy.aria.core.inf.IEventListener;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.BufferedRandomAccessFile;
import java.io.IOException; import java.io.IOException;
@ -70,7 +72,10 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
client.setRestartOffset(mConfig.START_LOCATION); client.setRestartOffset(mConfig.START_LOCATION);
int reply = client.getReplyCode(); int reply = client.getReplyCode();
if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.FILE_ACTION_OK) { if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.FILE_ACTION_OK) {
fail(mChildCurrentLocation, "上传失败,错误码为:" + reply + ",msg:" + client.getReplyString(), null); fail(mChildCurrentLocation,
new AriaIOException(TAG,
String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply,
client.getReplyString(), mEntity.getFilePath())));
client.disconnect(); client.disconnect();
return this; return this;
} }
@ -95,12 +100,14 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
} }
if (STATE.isFail()) { if (STATE.isFail()) {
STATE.isRunning = false; STATE.isRunning = false;
mListener.onFail(false); mListener.onFail(false, new TaskException(TAG,
String.format("上传失败,filePath: %s, uploadUrl: %s", mEntity.getFilePath(), mConfig.URL)));
} }
} catch (IOException e) { } catch (IOException e) {
fail(mChildCurrentLocation, String.format("上传失败【%s】", mConfig.URL), e); fail(mChildCurrentLocation, new AriaIOException(TAG,
String.format("上传失败,filePath: %s, uploadUrl: %s", mEntity.getFilePath(), mConfig.URL)));
} catch (Exception e) { } catch (Exception e) {
fail(mChildCurrentLocation, "获取流失败", e); fail(mChildCurrentLocation, new AriaIOException(TAG, null, e));
} finally { } finally {
try { try {
if (file != null) { if (file != null) {
@ -128,7 +135,7 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
throws IOException { throws IOException {
try { try {
ALog.d(TAG, String.format("remotePath【%s】", remotePath)); ALog.d(TAG, String.format("remotePath: %s", remotePath));
client.storeFile(remotePath, new FtpFISAdapter(bis), new OnFtpInputStreamListener() { client.storeFile(remotePath, new FtpFISAdapter(bis), new OnFtpInputStreamListener() {
boolean isStoped = false; boolean isStoped = false;
@ -149,10 +156,11 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
} }
}); });
} catch (IOException e) { } catch (IOException e) {
if (e.getMessage().contains("IOException caught while copying")) { if (e.getMessage().contains("AriaIOException caught while copying")) {
e.printStackTrace(); e.printStackTrace();
} else { } else {
fail(mChildCurrentLocation, "上传失败", e); fail(mChildCurrentLocation,
new AriaIOException(TAG, String.format("上传失败,filePath: %s", mEntity.getFilePath()), e));
} }
} }
@ -160,8 +168,9 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
if (!FTPReply.isPositiveCompletion(reply)) { if (!FTPReply.isPositiveCompletion(reply)) {
if (reply != FTPReply.TRANSFER_ABORTED) { if (reply != FTPReply.TRANSFER_ABORTED) {
fail(mChildCurrentLocation, fail(mChildCurrentLocation,
String.format("上传文件错误,错误码为:%s,msg:%s", reply, client.getReplyString()), new AriaIOException(TAG,
null); String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply,
client.getReplyString(), mEntity.getFilePath())));
} }
if (client.isConnected()) { if (client.isConnected()) {
client.disconnect(); client.disconnect();

@ -21,6 +21,8 @@ import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.inf.IUploadListener; import com.arialyy.aria.core.inf.IUploadListener;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -61,8 +63,9 @@ class HttpThreadTask extends AbsThreadTask<UploadEntity, UploadTaskEntity> {
super.call(); super.call();
File uploadFile = new File(mEntity.getFilePath()); File uploadFile = new File(mEntity.getFilePath());
if (!uploadFile.exists()) { if (!uploadFile.exists()) {
ALog.e(TAG, String.format("【%s】,文件不存在。", mEntity.getFilePath())); fail(new TaskException(TAG,
fail(); String.format("上传失败,文件不存在;filePath: %s, url: %s", mEntity.getFilePath(),
mEntity.getUrl())));
return this; return this;
} }
mListener.onPre(); mListener.onPre();
@ -102,14 +105,15 @@ class HttpThreadTask extends AbsThreadTask<UploadEntity, UploadTaskEntity> {
mListener.onComplete(); mListener.onComplete();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
fail(); fail(new TaskException(TAG,
String.format("上传失败,filePath: %s, url: %s", mEntity.getFilePath(), mEntity.getUrl()), e));
} }
return this; return this;
} }
private void fail() { private void fail(BaseException e1) {
try { try {
mListener.onFail(true); mListener.onFail(true, e1);
STATE.isRunning = false; STATE.isRunning = false;
if (mOutputStream != null) { if (mOutputStream != null) {
mOutputStream.close(); mOutputStream.close();

@ -22,6 +22,8 @@ import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IUploadListener; import com.arialyy.aria.core.inf.IUploadListener;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
/** /**
@ -60,8 +62,8 @@ public class SimpleUploadUtil implements IUtil, Runnable {
} }
} }
@Override public void onFail(String url, String errorMsg, boolean needRetry) { @Override public void onFail(String url, BaseException e, boolean needRetry) {
mListener.onFail(needRetry); mListener.onFail(needRetry, e);
} }
}).start(); }).start();
break; break;

@ -0,0 +1,28 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.exception;
public class AriaIOException extends BaseException{
private static final String ARIA_NET_EXCEPTION = "Aria Net Exception:";
public AriaIOException(String tag, String message) {
super(tag, String.format("%s%s", ARIA_NET_EXCEPTION, message));
}
public AriaIOException(String tag, String message, Exception e){
super(tag, message, e);
}
}

@ -0,0 +1,35 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.exception;
public abstract class BaseException extends Exception {
private String tag;
public BaseException(String tag, String message) {
super(message);
this.tag = tag;
}
public BaseException(String tag, String message, Exception e) {
super(String.format("%s\n%s", message == null ? "" : message, e == null ? "" : e.getMessage()));
this.tag = tag;
}
public String getTag() {
return tag;
}
}

@ -0,0 +1,31 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.exception;
/**
* 任务异常
*/
public class TaskException extends BaseException {
private static final String ARIA_TASK_EXCEPTION = "Aria Task Exception:";
public TaskException(String tag, String detailMessage) {
super(tag, String.format("%s, %s", ARIA_TASK_EXCEPTION, detailMessage));
}
public TaskException(String tag, String message, Exception e){
super(tag, message, e);
}
}

@ -222,9 +222,9 @@ public class CheckUtil {
} else if (TextUtils.isEmpty(entity.getUrl())) { } else if (TextUtils.isEmpty(entity.getUrl())) {
throw new IllegalArgumentException("下载链接不能为空"); throw new IllegalArgumentException("下载链接不能为空");
} else if (TextUtils.isEmpty(entity.getFileName())) { } else if (TextUtils.isEmpty(entity.getFileName())) {
throw new FileException("文件名不能为null"); throw new NullPointerException("文件名不能为null");
} else if (TextUtils.isEmpty(entity.getDownloadPath())) { } else if (TextUtils.isEmpty(entity.getDownloadPath())) {
throw new FileException("文件保存路径不能为null"); throw new NullPointerException("文件保存路径不能为null");
} }
} }
} }

@ -16,7 +16,6 @@
package com.arialyy.aria.util; package com.arialyy.aria.util;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@ -38,8 +37,7 @@ public class ErrorHelp {
* @param ex 异常 * @param ex 异常
*/ */
public static void saveError(String tag, String msg, String ex) { public static void saveError(String tag, String msg, String ex) {
String message = "\nmsg【" + msg + "】\nException:" + ex; writeLogToFile(tag, String.format("\nmsg【%s】\nException:%s", msg, ex));
writeLogToFile(tag, message);
} }
/** /**
@ -48,10 +46,8 @@ public class ErrorHelp {
* @return "/mnt/sdcard/Android/data/{package_name}/files/log/*" * @return "/mnt/sdcard/Android/data/{package_name}/files/log/*"
*/ */
private static String getLogPath() { private static String getLogPath() {
String path = CommonUtil.getAppPath(AriaManager.APP) String path = String.format("%slog/AriaCrash_%s.log", CommonUtil.getAppPath(AriaManager.APP),
+ "log/AriaCrash_" getData("yyyy-MM-dd_HH:mm:ss"));
+ getData("yyyy-MM-dd_HH:mm:ss")
+ ".log";
File log = new File(path); File log = new File(path);
if (!log.getParentFile().exists()) { if (!log.getParentFile().exists()) {

@ -16,6 +16,7 @@
package com.arialyy.compiler; package com.arialyy.compiler;
import com.arialyy.annotations.Download; import com.arialyy.annotations.Download;
import com.arialyy.annotations.DownloadGroup;
import com.arialyy.annotations.Upload; import com.arialyy.annotations.Upload;
import com.squareup.javapoet.ClassName; import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock; import com.squareup.javapoet.CodeBlock;
@ -91,33 +92,54 @@ final class EventProxyFiler {
* *
* @param taskEnum 任务类型枚举{@link TaskEnum} * @param taskEnum 任务类型枚举{@link TaskEnum}
* @param annotation {@link Download}{@link Upload} * @param annotation {@link Download}{@link Upload}
* @param methodName 被代理类注解的方法名 * @param methodInfo 被代理类注解的方法信息
*/ */
private MethodSpec createProxyMethod(TaskEnum taskEnum, Class<? extends Annotation> annotation, private MethodSpec createProxyMethod(TaskEnum taskEnum, Class<? extends Annotation> annotation,
String methodName) { MethodInfo methodInfo) {
ClassName task = ClassName.get(taskEnum.getPkg(), taskEnum.getClassName()); ClassName task = ClassName.get(taskEnum.getPkg(), taskEnum.getClassName());
ParameterSpec taskParam = ParameterSpec taskParam =
ParameterSpec.builder(task, "task").addModifiers(Modifier.FINAL).build(); ParameterSpec.builder(task, "task").addModifiers(Modifier.FINAL).build();
String callCode; String callCode;
if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) { if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) {
callCode = "task, subEntity"; if (methodInfo.params.get(methodInfo.params.size() - 1)
.asType()
.toString()
.equals(Exception.class.getName())
&& annotation == DownloadGroup.onSubTaskFail.class) {
callCode = "task, subEntity, e";
} else {
callCode = "task, subEntity";
}
} else { } else {
callCode = "task"; if (methodInfo.params.get(methodInfo.params.size() - 1)
.asType()
.toString()
.equals(Exception.class.getName())
&& (annotation == Download.onTaskFail.class
|| annotation == Upload.onTaskFail.class
|| annotation == DownloadGroup.onTaskFail.class)) {
callCode = "task, e";
} else {
callCode = "task";
}
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Set<String> keys = keyMapping.get(\"").append(methodName).append("\");\n"); sb.append("Set<String> keys = keyMapping.get(\"")
.append(methodInfo.methodName)
.append("\");\n");
sb.append("if (keys != null) {\n\tif (keys.contains(task.getKey())) {\n") sb.append("if (keys != null) {\n\tif (keys.contains(task.getKey())) {\n")
.append("\t\tobj.") .append("\t\tobj.")
.append(methodName) .append(methodInfo.methodName)
.append("((") .append("((")
.append(taskEnum.getClassName()) .append(taskEnum.getClassName())
.append(")") .append(")")
.append(callCode) .append(callCode)
.append(");\n\t}\n} else {\n") .append(");\n\t}\n} else {\n")
.append("\tobj.") .append("\tobj.")
.append(methodName) .append(methodInfo.methodName)
.append("((") .append("((")
.append(taskEnum.getClassName()) .append(taskEnum.getClassName())
.append(")") .append(")")
@ -140,6 +162,15 @@ final class EventProxyFiler {
builder.addParameter(subTaskParam); builder.addParameter(subTaskParam);
} }
if (annotation == Download.onTaskFail.class
|| annotation == Upload.onTaskFail.class
|| annotation == DownloadGroup.onTaskFail.class
|| annotation == DownloadGroup.onSubTaskFail.class) {
ParameterSpec exception = ParameterSpec.builder(Exception.class, "e").build();
builder.addParameter(exception);
}
return builder.build(); return builder.build();
} }
@ -165,7 +196,7 @@ final class EventProxyFiler {
//Set<Integer> type = new HashSet<>(); //Set<Integer> type = new HashSet<>();
//添加注解方法 //添加注解方法
for (TaskEnum te : entity.methods.keySet()) { for (TaskEnum te : entity.methods.keySet()) {
Map<Class<? extends Annotation>, String> temp = entity.methods.get(te); Map<Class<? extends Annotation>, MethodInfo> methodInfoMap = entity.methods.get(te);
//if (entity.proxyClassName.contains(TaskEnum.DOWNLOAD.proxySuffix)) { //if (entity.proxyClassName.contains(TaskEnum.DOWNLOAD.proxySuffix)) {
// type.add(1); // type.add(1);
//} else if (entity.proxyClassName.contains(TaskEnum.DOWNLOAD_GROUP.proxySuffix)) { //} else if (entity.proxyClassName.contains(TaskEnum.DOWNLOAD_GROUP.proxySuffix)) {
@ -175,9 +206,9 @@ final class EventProxyFiler {
//} else if (entity.proxyClassName.contains(TaskEnum.UPLOAD_GROUP.proxySuffix)) { //} else if (entity.proxyClassName.contains(TaskEnum.UPLOAD_GROUP.proxySuffix)) {
// type.add(4); // type.add(4);
//} //}
if (temp != null) { if (methodInfoMap != null) {
for (Class<? extends Annotation> annotation : temp.keySet()) { for (Class<? extends Annotation> annotation : methodInfoMap.keySet()) {
MethodSpec method = createProxyMethod(te, annotation, temp.get(annotation)); MethodSpec method = createProxyMethod(te, annotation, methodInfoMap.get(annotation));
builder.addMethod(method); builder.addMethod(method);
} }
} }

@ -0,0 +1,27 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.compiler;
import java.util.List;
import javax.lang.model.element.VariableElement;
/**
* 方法信息
*/
final class MethodInfo {
String methodName;
List<VariableElement> params;
}

@ -15,6 +15,9 @@
*/ */
package com.arialyy.compiler; package com.arialyy.compiler;
import com.arialyy.annotations.Download;
import com.arialyy.annotations.DownloadGroup;
import com.arialyy.annotations.Upload;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -70,11 +73,15 @@ class ParamObtainUtil {
ExecutableElement method = (ExecutableElement) element; ExecutableElement method = (ExecutableElement) element;
TypeElement classElement = (TypeElement) method.getEnclosingElement(); TypeElement classElement = (TypeElement) method.getEnclosingElement();
PackageElement packageElement = mElementUtil.getPackageOf(classElement); PackageElement packageElement = mElementUtil.getPackageOf(classElement);
checkDownloadMethod(taskEnum, method);
String methodName = method.getSimpleName().toString(); String methodName = method.getSimpleName().toString();
String className = method.getEnclosingElement().toString(); //全类名\ String className = method.getEnclosingElement().toString(); //全类名\
String key = className + taskEnum.proxySuffix; String key = className + taskEnum.proxySuffix;
ProxyClassParam proxyEntity = mMethodParams.get(key); ProxyClassParam proxyEntity = mMethodParams.get(key);
MethodInfo methodInfo = new MethodInfo();
methodInfo.methodName = methodName;
methodInfo.params = (List<VariableElement>) method.getParameters();
checkMethod(taskEnum, method, annotationClazz, methodInfo.params);
if (proxyEntity == null) { if (proxyEntity == null) {
proxyEntity = new ProxyClassParam(); proxyEntity = new ProxyClassParam();
@ -90,9 +97,10 @@ class ParamObtainUtil {
} }
proxyEntity.taskEnums.add(taskEnum); proxyEntity.taskEnums.add(taskEnum);
if (proxyEntity.methods.get(taskEnum) == null) { if (proxyEntity.methods.get(taskEnum) == null) {
proxyEntity.methods.put(taskEnum, new HashMap<Class<? extends Annotation>, String>()); proxyEntity.methods.put(taskEnum, new HashMap<Class<? extends Annotation>, MethodInfo>());
} }
proxyEntity.methods.get(taskEnum).put(annotationClazz, methodName);
proxyEntity.methods.get(taskEnum).put(annotationClazz, methodInfo);
proxyEntity.keyMappings.put(methodName, getValues(taskEnum, method, annotationType)); proxyEntity.keyMappings.put(methodName, getValues(taskEnum, method, annotationType));
} }
} }
@ -144,52 +152,71 @@ class ParamObtainUtil {
/** /**
* 检查和下载相关的方法如果被注解的方法为private或参数不合法则抛异常 * 检查和下载相关的方法如果被注解的方法为private或参数不合法则抛异常
*/ */
private void checkDownloadMethod(TaskEnum taskEnum, ExecutableElement method) { private void checkMethod(TaskEnum taskEnum, ExecutableElement method,
Class<? extends Annotation> annotationClazz, List<VariableElement> params) {
String methodName = method.getSimpleName().toString(); String methodName = method.getSimpleName().toString();
String className = method.getEnclosingElement().toString(); String className = method.getEnclosingElement().toString();
Set<Modifier> modifiers = method.getModifiers(); Set<Modifier> modifiers = method.getModifiers();
if (modifiers.contains(Modifier.PRIVATE)) { if (modifiers.contains(Modifier.PRIVATE)) {
throw new IllegalAccessError(className + "." + methodName + "不能为private方法"); throw new IllegalAccessError(String.format("%s.%s, 不能为private方法", className, methodName));
} }
List<VariableElement> params = (List<VariableElement>) method.getParameters();
if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) { if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) {
if (params.size() != 2) { if (isFailAnnotation(annotationClazz)) {
throw new IllegalArgumentException(className if (params.size() != 3 && params.size() != 2) {
+ "." throw new IllegalArgumentException(
+ methodName String.format("%s.%s参数错误, 参数只能是两个或三个,第一个参数是:%s,第二个参数是:%s,第三个参数(可选)是:%s", className,
+ "参数错误, 参数只有两个,且第一个参数必须是" methodName,
+ getCheckParams(taskEnum) getCheckParams(taskEnum), getCheckSubParams(taskEnum),
+ ",第二个参数必须是" Exception.class.getSimpleName()));
+ getCheckSubParams(taskEnum)); }
} else {
if (params.size() != 2) {
throw new IllegalArgumentException(
String.format("%s.%s参数错误, 参数只能是两个,第一个参数是:%s,第二个参数是:%s", className, methodName,
getCheckParams(taskEnum), getCheckSubParams(taskEnum)));
}
} }
} else { } else {
if (params.size() != 1) { if (isFailAnnotation(annotationClazz)) {
throw new IllegalArgumentException( if (params.size() != 1 && params.size() != 2) {
className + "." + methodName + "参数错误, 参数只能有一个,且参数必须是" + getCheckParams(taskEnum)); throw new IllegalArgumentException(
String.format("%s.%s参数错误, 参数只能有一个或两个,第一个参数是:%s,第二个参(可选)数是:%s", className, methodName,
getCheckParams(taskEnum), Exception.class.getSimpleName()));
}
} else {
if (params.size() != 1) {
throw new IllegalArgumentException(
String.format("%s.%s参数错误, 参数只能有一个,且参数必须是:%s", className, methodName,
getCheckParams(taskEnum)));
}
} }
} }
if (!params.get(0).asType().toString().equals(getCheckParams(taskEnum))) { if (!params.get(0).asType().toString().equals(getCheckParams(taskEnum))) {
throw new IllegalArgumentException(className throw new IllegalArgumentException(
+ "." String.format("%s.%s参数【%s】类型错误,参数必须是:%s", className, methodName,
+ methodName params.get(0).getSimpleName(), getCheckParams(taskEnum)));
+ "参数【"
+ params.get(0).getSimpleName()
+ "】类型错误,参数必须是"
+ getCheckParams(taskEnum));
} }
if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) { if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) {
if (!params.get(1).asType().toString().equals(getCheckSubParams(taskEnum))) { if (!params.get(1).asType().toString().equals(getCheckSubParams(taskEnum))) {
throw new IllegalArgumentException(className throw new IllegalArgumentException(
+ "." String.format("%s.%s参数【%s】类型错误,参数必须是:%s", className, methodName,
+ methodName params.get(0).getSimpleName(), getCheckSubParams(taskEnum)));
+ "参数【"
+ params.get(0).getSimpleName()
+ "】类型错误,参数必须是"
+ getCheckSubParams(taskEnum));
} }
} }
} }
/**
* 判断是否是任务失败的回调注解
*
* @return @code true是任务失败的回调注解
*/
private boolean isFailAnnotation(Class<? extends Annotation> annotationClazz) {
return annotationClazz == Download.onTaskFail.class
|| annotationClazz == DownloadGroup.onTaskFail.class
|| annotationClazz == DownloadGroup.onSubTaskFail.class
|| annotationClazz == Upload.onTaskFail.class;
}
/** /**
* 字符串数组转set * 字符串数组转set
* *

@ -48,5 +48,5 @@ class ProxyClassParam {
Set<TaskEnum> taskEnums; Set<TaskEnum> taskEnums;
Map<String, Set<String>> keyMappings = new HashMap<>(); Map<String, Set<String>> keyMappings = new HashMap<>();
Map<TaskEnum, Map<Class<? extends Annotation>, String>> methods = new HashMap<>(); Map<TaskEnum, Map<Class<? extends Annotation>, MethodInfo>> methods = new HashMap<>();
} }

@ -1,4 +1,13 @@
## 开发日志 ## 开发日志
+ v_3.5.2
- 添加Serializable接口支持 https://github.com/AriaLyy/Aria/issues/320
- 失败回调增加错误原因 https://github.com/AriaLyy/Aria/issues/310
```
@Download.onTaskFail void taskFail(DownloadTask task, Exception e) {
e.getMessage();
...
}
```
+ v_3.5.1 + v_3.5.1
- 优化`taskExists`方法 - 优化`taskExists`方法
- 添加`post`参数请求支持 - 添加`post`参数请求支持

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.arialyy.simple"> package="com.arialyy.simple">
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
@ -12,14 +13,16 @@
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar"
tools:ignore="GoogleAppIndexingWarning">
<!--android:name=".test.TestFTPDirActivity"--> <!--android:name=".test.TestFTPDirActivity"-->
<!--android:name=".test.AnyRunActivity"-->
<!--android:name=".test.TestFTPActivity"--> <!--android:name=".test.TestFTPActivity"-->
<!--android:name=".download.group.DownloadGroupActivity"--> <!--android:name=".download.group.DownloadGroupActivity"-->
<!--android:name=".download.SingleTaskActivity"--> <!--android:name=".download.SingleTaskActivity"-->
<!--android:name=".MainActivity"-->
<!--android:name=".test.AnyRunActivity"-->
<activity <activity
android:name=".MainActivity" android:name=".download.SingleTaskActivity"
android:label="@string/app_name"> android:label="@string/app_name">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
@ -29,7 +32,7 @@
</activity> </activity>
<activity android:name=".download.DownloadActivity"/> <activity android:name=".download.DownloadActivity"/>
<activity android:name=".download.SingleTaskActivity"/> <!--<activity android:name=".download.SingleTaskActivity"/>-->
<activity android:name=".download.multi_download.MultiTaskActivity"/> <activity android:name=".download.multi_download.MultiTaskActivity"/>
<activity android:name=".download.fragment_download.FragmentActivity"/> <activity android:name=".download.fragment_download.FragmentActivity"/>
<activity android:name=".download.multi_download.MultiDownloadActivity"/> <activity android:name=".download.multi_download.MultiDownloadActivity"/>

@ -1,75 +1,75 @@
package com.arialyy.simple.download //package com.arialyy.simple.download
//
import android.os.Bundle //import android.os.Bundle
import android.os.Environment //import android.os.Environment
import android.support.v7.app.AppCompatActivity //import android.support.v7.app.AppCompatActivity
import android.util.Log //import android.util.Log
import android.view.View //import android.view.View
import com.arialyy.annotations.Download //import com.arialyy.annotations.Download
import com.arialyy.aria.core.Aria //import com.arialyy.aria.core.Aria
import com.arialyy.aria.core.download.DownloadTask //import com.arialyy.aria.core.download.DownloadTask
import com.arialyy.simple.R //import com.arialyy.simple.R
import com.arialyy.simple.base.BaseActivity //import com.arialyy.simple.base.BaseActivity
//
/** ///**
* Created by lyy on 2017/10/23. // * Created by lyy on 2017/10/23.
*/ // */
class KotlinDownloadActivity : AppCompatActivity() { //class KotlinDownloadActivity : AppCompatActivity() {
//
private val DOWNLOAD_URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk" // private val DOWNLOAD_URL = "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"
//
private val TAG = "KotlinDownloadActivity"; // private val TAG = "KotlinDownloadActivity";
//
override fun onCreate(savedInstanceState: Bundle?) { // override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) // super.onCreate(savedInstanceState)
setContentView(setLayoutId()) // setContentView(setLayoutId())
} // }
//
fun setLayoutId(): Int { // fun setLayoutId(): Int {
return R.layout.activity_single // return R.layout.activity_single
} // }
//
fun init(savedInstanceState: Bundle?) { // fun init(savedInstanceState: Bundle?) {
title = "单任务下载" // title = "单任务下载"
// val target = Aria.download(this).load(DOWNLOAD_URL) //// val target = Aria.download(this).load(DOWNLOAD_URL)
// binding.progress = target.getPercent() //// binding.progress = target.getPercent()
// if (target.getTaskState() == IEntity.STATE_STOP) { //// if (target.getTaskState() == IEntity.STATE_STOP) {
// mStart.setText("恢复") //// mStart.setText("恢复")
// mStart.setTextColor(resources.getColor(android.R.color.holo_blue_light)) //// mStart.setTextColor(resources.getColor(android.R.color.holo_blue_light))
// setBtState(true) //// setBtState(true)
// } else if (target.isDownloading()) { //// } else if (target.isDownloading()) {
// setBtState(false) //// setBtState(false)
//// }
//// binding.fileSize = target.getConvertFileSize()
// Aria.get(this).downloadConfig.maxTaskNum = 2
// Aria.download(this).register()
// }
//
// @Download.onTaskRunning
// protected fun running(task: DownloadTask) {
// Log.d(TAG, task.percent.toString() + "")
//// val len = task.fileSize
//// if (len == 0L) {
//// binding.progress = 0
//// } else {
//// binding.progress = task.percent
//// }
//// binding.speed = task.convertSpeed
// }
//
// fun onClick(view: View) {
// when (view.id) {
// R.id.start -> startD()
// R.id.stop -> Aria.download(this).load(DOWNLOAD_URL).stop()
// R.id.cancel -> Aria.download(this).load(DOWNLOAD_URL).cancel()
// } // }
// binding.fileSize = target.getConvertFileSize() // }
Aria.get(this).downloadConfig.maxTaskNum = 2 //
Aria.download(this).register() // private fun startD() {
} // Aria.download(this)
// .load(DOWNLOAD_URL)
@Download.onTaskRunning // .addHeader("groupName", "value")
protected fun running(task: DownloadTask) { // .setDownloadPath(Environment.getExternalStorageDirectory().path + "/hhhhhhhh.apk")
Log.d(TAG, task.percent.toString() + "") // .start()
// val len = task.fileSize // }
// if (len == 0L) { //}
// binding.progress = 0
// } else {
// binding.progress = task.percent
// }
// binding.speed = task.convertSpeed
}
fun onClick(view: View) {
when (view.id) {
R.id.start -> startD()
R.id.stop -> Aria.download(this).load(DOWNLOAD_URL).stop()
R.id.cancel -> Aria.download(this).load(DOWNLOAD_URL).cancel()
}
}
private fun startD() {
Aria.download(this)
.load(DOWNLOAD_URL)
.addHeader("groupName", "value")
.setDownloadPath(Environment.getExternalStorageDirectory().path + "/hhhhhhhh.apk")
.start()
}
}

@ -16,6 +16,7 @@
package com.arialyy.simple.download; package com.arialyy.simple.download;
import android.content.ContentResolver;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -49,7 +50,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
private static final String DOWNLOAD_URL = private static final String DOWNLOAD_URL =
//"http://kotlinlang.org/docs/kotlin-docs.pdf"; //"http://kotlinlang.org/docs/kotlin-docs.pdf";
//"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe"; //"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe";
"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apks";
//"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip"; //"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip";
//"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk"; //"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk";
//"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载 //"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
@ -248,7 +249,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
private void startD() { private void startD() {
//Aria.get(this).setLogLevel(ALog.LOG_CLOSE); //Aria.get(this).setLogLevel(ALog.LOG_CLOSE);
//Aria.download(this).load("aaaa.apk"); //Aria.download(this).load("aaaa.apk");
String path = Environment.getExternalStorageDirectory().getPath() + "/ggsg9.apk"; String path = Environment.getExternalStorageDirectory().getPath() + "/ggsg10.apk";
//File file = new File(path); //File file = new File(path);
//if (file.exists()){ //if (file.exists()){
// file.delete(); // file.delete();

@ -31,7 +31,8 @@ public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
//String URL = "ftps://192.168.29.140:990/download/SDK_Demo-release.apk"; //String URL = "ftps://192.168.29.140:990/download/SDK_Demo-release.apk";
//String URL = "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1994&clientId=A000011106034058176"; //String URL = "http://d.quanscreen.com/k/down/resourceDownLoad?resourceId=1994&clientId=A000011106034058176";
//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";
String URL = "https://app-dl.byfen.com//app//201810//ef0400d637e768e9c630b4d38633ee06.zip"; //String URL = "https://app-dl.byfen.com//app//201810//ef0400d637e768e9c630b4d38633ee06.zip";
String URL = "ftps://9.9.9.59:990/download/SDK_Demo-release.apk";
//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";
@ -52,8 +53,8 @@ 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(URL); //module.start(URL);
//module.startFtp(URL); module.startFtp(URL);
break; break;
case R.id.stop: case R.id.stop:
module.stop(URL); module.stop(URL);

@ -78,10 +78,10 @@ public class AnyRunnModule {
.loadFtp(url) .loadFtp(url)
.login("lao", "123456") .login("lao", "123456")
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/Download/") .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/Download/")
//.asFtps() .asFtps()
//.setStorePath("/mnt/sdcard/Download/server.crt") .setStorePath("/mnt/sdcard/Download/server.crt")
//.setAlias("www.laoyuyu.me") .setAlias("www.laoyuyu.me")
//.setStorePass("123456") .setStorePass("123456")
.start(); .start();
} }

@ -19,10 +19,14 @@ package com.arialyy.aria.exception;
* Created by lyy on 2017/1/18. * Created by lyy on 2017/1/18.
* Aria 文件异常 * Aria 文件异常
*/ */
public class FileException extends NullPointerException { public class FileException extends BaseException {
private static final String ARIA_FILE_EXCEPTION = "Aria Exception:"; private static final String ARIA_FILE_EXCEPTION = "Aria File Exception:";
public FileException(String detailMessage) { public FileException(String tag, String detailMessage) {
super(ARIA_FILE_EXCEPTION + detailMessage); super(tag, String.format("%s%s", ARIA_FILE_EXCEPTION, detailMessage));
}
public FileException(String tag, String message, Exception e){
super(tag, message, e);
} }
} }

@ -13,8 +13,8 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true # org.gradle.parallel=true
#Wed Dec 07 20:19:22 CST 2016 #Wed Dec 07 20:19:22 CST 2016
#org.gradle.daemon=true org.gradle.daemon=true
#org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
# gradle proxy https://chaosleong.github.io/2017/02/10/Configuring-Gradle-Proxy/ # gradle proxy https://chaosleong.github.io/2017/02/10/Configuring-Gradle-Proxy/
#systemProp.socksProxyHost=127.0.0.1 #systemProp.socksProxyHost=127.0.0.1
#systemProp.socksProxyPort=60777 #systemProp.socksProxyPort=60777

Loading…
Cancel
Save