Skip to content
Permalink
Browse files

fix bug #608

优化异常提示
  • Loading branch information
AriaLyy committed Feb 6, 2020
1 parent 96efa35 commit e015c2a2f7cb4d16433b13a552b938e922d97320
Showing with 322 additions and 521 deletions.
  1. +3 −0 DEV_LOG.md
  2. +5 −6 FtpComponent/src/main/java/com/arialyy/aria/ftp/AbsFtpInfoTask.java
  3. +2 −2 FtpComponent/src/main/java/com/arialyy/aria/ftp/BaseFtpThreadTaskAdapter.java
  4. +2 −2 FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDFileInfoTask.java
  5. +2 −2 FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDGLoader.java
  6. +11 −11 FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDThreadTaskAdapter.java
  7. +2 −2 FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpULoader.java
  8. +9 −9 FtpComponent/src/main/java/com/arialyy/aria/ftp/upload/FtpUThreadTaskAdapter.java
  9. +20 −17 HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDFileInfoTask.java
  10. +5 −5 HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java
  11. +2 −2 HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoader.java
  12. +8 −9 HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java
  13. +2 −2 HttpComponent/src/main/java/com/arialyy/aria/http/upload/HttpULoader.java
  14. +5 −7 HttpComponent/src/main/java/com/arialyy/aria/http/upload/HttpUThreadTaskAdapter.java
  15. +3 −4 M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8InfoTask.java
  16. +10 −11 M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8ThreadTaskAdapter.java
  17. +7 −8 M3U8Component/src/main/java/com/arialyy/aria/m3u8/live/M3U8LiveLoader.java
  18. +6 −6 M3U8Component/src/main/java/com/arialyy/aria/m3u8/vod/M3U8VodLoader.java
  19. +4 −4 M3U8Component/src/main/java/com/arialyy/aria/m3u8/vod/VodStateManager.java
  20. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/core/group/AbsGroupLoader.java
  21. +3 −3 PublicComponent/src/main/java/com/arialyy/aria/core/group/SimpleSchedulers.java
  22. +5 −4 PublicComponent/src/main/java/com/arialyy/aria/core/listener/BaseListener.java
  23. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/core/listener/DownloadGroupListener.java
  24. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/core/listener/IDGroupListener.java
  25. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/core/listener/IEventListener.java
  26. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/core/loader/AbsNormalLoaderUtil.java
  27. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/core/loader/IInfoTask.java
  28. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalLoader.java
  29. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/core/loader/NormalThreadStateManager.java
  30. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/core/loader/SubLoader.java
  31. +1 −1 PublicComponent/src/main/java/com/arialyy/aria/core/manager/ThreadTaskManager.java
  32. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/core/task/AbsThreadTaskAdapter.java
  33. +2 −2 PublicComponent/src/main/java/com/arialyy/aria/core/task/IThreadTaskObserver.java
  34. +4 −4 PublicComponent/src/main/java/com/arialyy/aria/core/task/ThreadTask.java
  35. +12 −4 PublicComponent/src/main/java/com/arialyy/aria/exception/AriaException.java
  36. +5 −5 ...icComponent/src/main/java/com/arialyy/aria/exception/{M3U8Exception.java → AriaFTPException.java}
  37. +5 −5 ...onent/src/main/java/com/arialyy/aria/exception/{AriaLoginException.java → AriaHTTPException.java}
  38. +5 −5 ...omponent/src/main/java/com/arialyy/aria/exception/{AriaIOException.java → AriaM3U8Exception.java}
  39. +5 −8 ...cComponent/src/main/java/com/arialyy/aria/exception/{TaskException.java → AriaSFTPException.java}
  40. +0 −35 PublicComponent/src/main/java/com/arialyy/aria/exception/BaseException.java
  41. +0 −32 PublicComponent/src/main/java/com/arialyy/aria/exception/FileException.java
  42. +0 −32 PublicComponent/src/main/java/com/arialyy/aria/exception/FileNotFoundException.java
  43. +0 −24 PublicComponent/src/main/java/com/arialyy/aria/exception/ParamException.java
  44. +2 −4 PublicComponent/src/main/java/com/arialyy/aria/util/ALog.java
  45. +3 −3 PublicComponent/src/main/java/com/arialyy/aria/util/CommonUtil.java
  46. +6 −8 SFtpComponent/src/main/java/com/arialyy/aria/sftp/AbsSFtpInfoTask.java
  47. +2 −2 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDInfoTask.java
  48. +2 −2 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDLoader.java
  49. +6 −11 SFtpComponent/src/main/java/com/arialyy/aria/sftp/download/SFtpDThreadTaskAdapter.java
  50. +2 −2 SFtpComponent/src/main/java/com/arialyy/aria/sftp/upload/SFtpULoader.java
  51. +8 −13 SFtpComponent/src/main/java/com/arialyy/aria/sftp/upload/SFtpUThreadTaskAdapter.java
  52. +54 −76 app/src/main/java/com/arialyy/simple/core/download/group/DownloadGroupActivity.java
  53. +54 −70 app/src/main/java/com/arialyy/simple/core/download/group/FTPDirDownloadActivity.java
  54. +7 −37 app/src/main/res/layout/activity_download_group.xml
  55. +1 −0 app/src/main/res/layout/layout_progress_content.xml
@@ -1,4 +1,7 @@
## 开发日志
+ v_3.8.6
- fix bug https://github.com/AriaLyy/Aria/issues/608
- 优化异常提示
+ v_3.8.5 (2020/1/18)
- fix bug https://github.com/AriaLyy/Aria/issues/599
- 增加密钥url转换器的参数 https://github.com/AriaLyy/Aria/issues/603
@@ -31,8 +31,7 @@
import com.arialyy.aria.core.loader.IInfoTask;
import com.arialyy.aria.core.loader.ILoaderVisitor;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.exception.AriaFTPException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
@@ -161,9 +160,9 @@ private FTPClient createFtpClient() throws IOException, InterruptedException {
loginSuccess = client.login(urlEntity.user, urlEntity.password, urlEntity.account);
}
} catch (IOException e) {
ALog.e(TAG,
new TaskException(TAG, String.format("登录失败,错误码为:%s, msg:%s", client.getReplyCode(),
client.getReplyString()), e));
e.printStackTrace();
ALog.e(TAG, String.format("登录失败,错误码为:%s, msg:%s", client.getReplyCode(),
client.getReplyString()));
return null;
}
}
@@ -329,7 +328,7 @@ protected void failDownload(FTPClient client, String msg, Exception e, boolean n
needRetry = needRetry && !CheckUtil.ftpIsBadRequest(client.getReplyCode());
}

callback.onFail(mEntity, new AriaIOException(TAG, msg), needRetry);
callback.onFail(mEntity, new AriaFTPException(TAG, msg), needRetry);
}
}

@@ -25,7 +25,7 @@
import com.arialyy.aria.core.common.FtpConnectionMode;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.task.AbsThreadTaskAdapter;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.AriaFTPException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.SSLContextUtil;
import java.io.IOException;
@@ -105,7 +105,7 @@ protected FTPClient createClient() {
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
client.disconnect();
fail(new AriaIOException(TAG,
fail(new AriaFTPException(TAG,
String.format("无法连接到ftp服务器,错误码为:%s,msg:%s", reply, client.getReplyString())), false);
return null;
}
@@ -21,7 +21,7 @@
import com.arialyy.aria.core.common.CompleteInfo;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.AriaFTPException;
import com.arialyy.aria.ftp.AbsFtpInfoTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.FileUtil;
@@ -41,7 +41,7 @@
@Override protected void handleFile(String remotePath, FTPFile ftpFile) {
super.handleFile(remotePath, ftpFile);
if (!FileUtil.checkMemorySpace(mEntity.getFilePath(), ftpFile.getSize())) {
callback.onFail(mEntity, new AriaIOException(TAG,
callback.onFail(mEntity, new AriaFTPException(TAG,
String.format("获取ftp文件信息失败,内存空间不足, filePath: %s", mEntity.getFilePath())),
false);
}
@@ -25,7 +25,7 @@
import com.arialyy.aria.core.listener.IEventListener;
import com.arialyy.aria.core.loader.IInfoTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.AriaException;
import com.arialyy.aria.util.ALog;

/**
@@ -79,7 +79,7 @@ private void startSub() {
}
}

@Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) {
@Override public void onFail(AbsEntity entity, AriaException e, boolean needRetry) {
//getListener().onFail(needRetry, e);
fail(e, needRetry);
}
@@ -18,8 +18,7 @@
import aria.apache.commons.net.ftp.FTPClient;
import aria.apache.commons.net.ftp.FTPReply;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.exception.AriaFTPException;
import com.arialyy.aria.ftp.BaseFtpThreadTaskAdapter;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.BufferedRandomAccessFile;
@@ -57,7 +56,7 @@
getThreadRecord().endLocation));
client = createClient();
if (client == null) {
fail(new TaskException(TAG, "ftp client 创建失败"), false);
fail(new AriaFTPException(TAG, "ftp client 创建失败"), false);
return;
}
if (getThreadRecord().startLocation > 0) {
@@ -66,7 +65,7 @@
//发送第二次指令时,还需要再做一次判断
int reply = client.getReplyCode();
if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.COMMAND_OK) {
fail(new AriaIOException(TAG,
fail(new AriaFTPException(TAG,
String.format("获取文件信息错误,错误码为:%s,msg:%s", reply, client.getReplyString())), false);
client.disconnect();
return;
@@ -77,7 +76,7 @@
is = client.retrieveFileStream(remotePath);
reply = client.getReplyCode();
if (!FTPReply.isPositivePreliminary(reply)) {
fail(new AriaIOException(TAG,
fail(new AriaFTPException(TAG,
String.format("获取流失败,错误码为:%s,msg:%s", reply, client.getReplyString())), true);
client.disconnect();
return;
@@ -90,9 +89,9 @@
handleComplete();
}
} catch (IOException e) {
fail(new AriaIOException(TAG, String.format("下载失败【%s】", getThreadConfig().url), e), true);
fail(new AriaFTPException(TAG, String.format("下载失败【%s】", getThreadConfig().url), e), true);
} catch (Exception e) {
fail(new AriaIOException(TAG, String.format("下载失败【%s】", getThreadConfig().url), e), false);
fail(new AriaFTPException(TAG, String.format("下载失败【%s】", getThreadConfig().url), e), false);
} finally {
try {
if (is != null) {
@@ -154,7 +153,7 @@ private void readDynamicFile(InputStream is) {
}
handleComplete();
} catch (IOException e) {
fail(new AriaIOException(TAG, String.format("下载失败【%s】", getThreadConfig().url), e), true);
fail(new AriaFTPException(TAG, String.format("下载失败【%s】", getThreadConfig().url), e), true);
} finally {
try {
if (fos != null) {
@@ -179,8 +178,9 @@ private void readNormal(InputStream is) {
BufferedRandomAccessFile file = null;
try {
file =
new BufferedRandomAccessFile(getThreadConfig().tempFile, "rwd", getTaskConfig().getBuffSize());
if (getThreadRecord().startLocation > 0){
new BufferedRandomAccessFile(getThreadConfig().tempFile, "rwd",
getTaskConfig().getBuffSize());
if (getThreadRecord().startLocation > 0) {
file.seek(getThreadRecord().startLocation);
}
byte[] buffer = new byte[getTaskConfig().getBuffSize()];
@@ -203,7 +203,7 @@ private void readNormal(InputStream is) {
}
}
} catch (IOException e) {
fail(new AriaIOException(TAG, String.format("下载失败【%s】", getThreadConfig().url), e), true);
fail(new AriaFTPException(TAG, String.format("下载失败【%s】", getThreadConfig().url), e), true);
} finally {
try {
if (file != null) {
@@ -26,7 +26,7 @@
import com.arialyy.aria.core.manager.ThreadTaskManager;
import com.arialyy.aria.core.task.IThreadTask;
import com.arialyy.aria.core.upload.UTaskWrapper;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.AriaException;

final class FtpULoader extends NormalLoader<UTaskWrapper> {
private FTPFile ftpFile;
@@ -79,7 +79,7 @@ protected void startThreadTask() {
}
}

@Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) {
@Override public void onFail(AbsEntity entity, AriaException e, boolean needRetry) {
getListener().onFail(needRetry, e);
}
});
@@ -21,7 +21,7 @@
import aria.apache.commons.net.ftp.OnFtpInputStreamListener;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.AriaFTPException;
import com.arialyy.aria.ftp.BaseFtpThreadTaskAdapter;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.BufferedRandomAccessFile;
@@ -63,7 +63,7 @@
client.setRestartOffset(getThreadRecord().startLocation);
int reply = client.getReplyCode();
if (!FTPReply.isPositivePreliminary(reply) && reply != FTPReply.FILE_ACTION_OK) {
fail(new AriaIOException(TAG,
fail(new AriaFTPException(TAG,
String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply,
client.getReplyString(), getEntity().getFilePath())), false);
client.disconnect();
@@ -80,20 +80,20 @@
if (getThreadTask().isBreak()) {
return;
}
if (!complete){
fail(new AriaIOException(TAG, "ftp文件上传失败"), false);
if (!complete) {
fail(new AriaFTPException(TAG, "ftp文件上传失败"), false);
return;
}
ALog.i(TAG,
String.format("任务【%s】线程__%s__上传完毕", getEntity().getKey(), getThreadRecord().threadId));
complete();
} catch (IOException e) {
e.printStackTrace();
fail(new AriaIOException(TAG,
fail(new AriaFTPException(TAG,
String.format("上传失败,filePath: %s, uploadUrl: %s", getEntity().getFilePath(),
getThreadConfig().url)), true);
} catch (Exception e) {
fail(new AriaIOException(TAG, null, e), false);
fail(new AriaFTPException(TAG, null, e), false);
} finally {
try {
if (file != null) {
@@ -132,7 +132,7 @@ private void startTimer() {
@Override public void run() {
try {
if (isTimeOut) {
fail(new AriaIOException(TAG, "socket连接失败,该问题一般出现于网络断开,客户端重新连接,"
fail(new AriaFTPException(TAG, "socket连接失败,该问题一般出现于网络断开,客户端重新连接,"
+ "但是服务器端无法创建socket缺没有返回错误码的情况。"), false);
if (fa != null) {
fa.close();
@@ -195,7 +195,7 @@ private boolean upload(final BufferedRandomAccessFile bis)
if (e.getMessage().contains("AriaIOException caught while copying")) {
e.printStackTrace();
} else {
fail(new AriaIOException(TAG, msg, e), !storeSuccess);
fail(new AriaFTPException(TAG, msg, e), !storeSuccess);
}
return false;
} finally {
@@ -204,7 +204,7 @@ private boolean upload(final BufferedRandomAccessFile bis)
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
if (reply != FTPReply.TRANSFER_ABORTED) {
fail(new AriaIOException(TAG,
fail(new AriaFTPException(TAG,
String.format("文件上传错误,错误码为:%s, msg:%s, filePath: %s", reply, client.getReplyString(),
getEntity().getFilePath())), false);
}
@@ -27,9 +27,7 @@
import com.arialyy.aria.core.loader.IInfoTask;
import com.arialyy.aria.core.loader.ILoaderVisitor;
import com.arialyy.aria.core.processor.IHttpFileLenAdapter;
import com.arialyy.aria.exception.AriaIOException;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.exception.AriaHTTPException;
import com.arialyy.aria.http.ConnectionHelp;
import com.arialyy.aria.http.HttpTaskOption;
import com.arialyy.aria.util.ALog;
@@ -40,6 +38,7 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
@@ -85,14 +84,16 @@
conn.connect();
handleConnect(conn);
} catch (IOException e) {
e.printStackTrace();
failDownload(new AriaIOException(TAG,
String.format("下载失败,filePath: %s, url: %s", mEntity.getFilePath(), mEntity.getUrl())),
true);
failDownload(new AriaHTTPException(TAG,
String.format("下载失败,filePath: %s, url: %s", mEntity.getFilePath(), mEntity.getUrl()),
e), true);
} finally {
if (conn != null) {
try {
conn.getInputStream().close();
InputStream is = conn.getInputStream();
if (is != null){
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
@@ -132,7 +133,7 @@ private void handleConnect(HttpURLConnection conn) throws IOException {
long len = lenAdapter.handleFileLen(conn.getHeaderFields());

if (!FileUtil.checkMemorySpace(mEntity.getFilePath(), len)) {
failDownload(new TaskException(TAG,
failDownload(new AriaHTTPException(TAG,
String.format("下载失败,内存空间不足;filePath: %s, url: %s", mEntity.getFilePath(),
mEntity.getUrl())), false);
return;
@@ -176,7 +177,8 @@ private void handleConnect(HttpURLConnection conn) throws IOException {
if (!checkLen(len) && !isChunked) {
if (len < 0) {
failDownload(
new AriaIOException(TAG, String.format("任务下载失败,文件长度小于0, url: %s", mEntity.getUrl())),
new AriaHTTPException(TAG,
String.format("任务下载失败,文件长度小于0, url: %s", mEntity.getUrl())),
false);
}
return;
@@ -203,7 +205,8 @@ private void handleConnect(HttpURLConnection conn) throws IOException {
} else if (!checkLen(len) && !isChunked) {
if (len < 0) {
failDownload(
new AriaIOException(TAG, String.format("任务下载失败,文件长度小于0, url: %s", mEntity.getUrl())),
new AriaHTTPException(TAG,
String.format("任务下载失败,文件长度小于0, url: %s", mEntity.getUrl())),
false);
}
ALog.d(TAG, "len < 0");
@@ -214,16 +217,16 @@ private void handleConnect(HttpURLConnection conn) throws IOException {
mTaskWrapper.setSupportBP(false);
end = true;
} else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
failDownload(new AriaIOException(TAG,
String.format("任务下载失败,errorCode:404, url: %s", mEntity.getUrl())), true);
failDownload(new AriaHTTPException(TAG,
String.format("任务下载失败,errorCode:404, url: %s", mEntity.getUrl())), false);
} else if (code == HttpURLConnection.HTTP_MOVED_TEMP
|| code == HttpURLConnection.HTTP_MOVED_PERM
|| code == HttpURLConnection.HTTP_SEE_OTHER
|| code == HttpURLConnection.HTTP_CREATED // 201 跳转
|| code == 307) {
handleUrlReTurn(conn, conn.getHeaderField("Location"));
} else {
failDownload(new AriaIOException(TAG,
failDownload(new AriaHTTPException(TAG,
String.format("任务下载失败,errorCode:%s, errorMsg: %s, url: %s", code,
conn.getResponseMessage(), mEntity.getUrl())), !CheckUtil.httpIsBadRequest(code));
}
@@ -298,7 +301,7 @@ private void handleUrlReTurn(HttpURLConnection conn, String newUrl) throws IOExc
ALog.d(TAG, "30x跳转,新url为【" + newUrl + "");
if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null")) {
if (callback != null) {
callback.onFail(mEntity, new TaskException(TAG, "获取重定向链接失败"), false);
callback.onFail(mEntity, new AriaHTTPException(TAG, "获取重定向链接失败"), false);
}
return;
}
@@ -308,7 +311,7 @@ private void handleUrlReTurn(HttpURLConnection conn, String newUrl) throws IOExc
}

if (!CheckUtil.checkUrl(newUrl)) {
failDownload(new TaskException(TAG, "下载失败,重定向url错误"), false);
failDownload(new AriaHTTPException(TAG, "下载失败,重定向url错误"), false);
return;
}
taskOption.setRedirectUrl(newUrl);
@@ -341,7 +344,7 @@ private boolean checkLen(long len) {
return true;
}

private void failDownload(BaseException e, boolean needRetry) {
private void failDownload(AriaHTTPException e, boolean needRetry) {
if (callback != null) {
callback.onFail(mEntity, e, needRetry);
}

0 comments on commit e015c2a

Please sign in to comment.
You can’t perform that action at this time.