移除检查任务信息主动抛出的异常
This commit is contained in:
@@ -22,10 +22,11 @@ public enum ErrorCode {
|
||||
ERROR_CODE_URL_NULL(2, "url 为空"), ERROR_CODE_URL_INVALID(3, "url 无效"),
|
||||
ERROR_CODE_PAGE_NUM(4, "page和num不能小于1"), ERROR_CODE_GROUP_URL_NULL(5, "组合任务url列表为空"),
|
||||
ERROR_CODE_UPLOAD_FILE_NULL(7, "上传文件不存在"),
|
||||
ERROR_CODE_MEMBER_WARNING(8, "为了防止内存泄漏,请使用静态的成员类(public static class xxx)或文件类(A.java)");
|
||||
ERROR_CODE_MEMBER_WARNING(8, "为了防止内存泄漏,请使用静态的成员类(public static class xxx)或文件类(A.java)"),
|
||||
ERROR_CODE_TASK_NOT_EXIST(9, "任务信息不存在");
|
||||
|
||||
int code;
|
||||
String msg;
|
||||
public int code;
|
||||
public String msg;
|
||||
|
||||
ErrorCode(int code, String msg) {
|
||||
this.code = code;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.arialyy.aria.core.download;
|
||||
|
||||
import com.arialyy.aria.core.event.ErrorEvent;
|
||||
import com.arialyy.aria.core.common.AbsEntity;
|
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
import java.util.List;
|
||||
@@ -26,19 +25,6 @@ import java.util.List;
|
||||
public abstract class AbsGroupTaskWrapper<ENTITY extends AbsEntity, SUB extends AbsTaskWrapper>
|
||||
extends AbsTaskWrapper<ENTITY> {
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private ErrorEvent errorEvent;
|
||||
|
||||
public ErrorEvent getErrorEvent() {
|
||||
return errorEvent;
|
||||
}
|
||||
|
||||
public void setErrorEvent(ErrorEvent errorEvent) {
|
||||
this.errorEvent = errorEvent;
|
||||
}
|
||||
|
||||
public AbsGroupTaskWrapper(ENTITY entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,9 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable {
|
||||
|
||||
@Override public int getTaskType() {
|
||||
int type;
|
||||
if (getUrl().startsWith("ftp")) {
|
||||
if (TextUtils.isEmpty(getUrl())) {
|
||||
type = ITaskWrapper.ERROR;
|
||||
} else if (getUrl().startsWith("ftp")) {
|
||||
type = ITaskWrapper.D_FTP;
|
||||
} else {
|
||||
M3U8Entity temp = getM3U8Entity();
|
||||
|
||||
@@ -62,7 +62,6 @@ public class DownloadGroupTask extends AbsGroupTask<DGTaskWrapper> {
|
||||
Handler outHandler;
|
||||
|
||||
public Builder(DGTaskWrapper taskEntity) {
|
||||
CheckUtil.checkTaskEntity(taskEntity);
|
||||
this.taskEntity = taskEntity;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ package com.arialyy.aria.core.wrapper;
|
||||
|
||||
import com.arialyy.aria.core.TaskOptionParams;
|
||||
import com.arialyy.aria.core.common.AbsEntity;
|
||||
import com.arialyy.aria.core.common.ErrorCode;
|
||||
import com.arialyy.aria.core.config.BaseTaskConfig;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||
@@ -26,8 +25,6 @@ import com.arialyy.aria.core.inf.IEntity;
|
||||
import com.arialyy.aria.core.inf.ITaskOption;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.util.ComponentUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/2/23. 所有任务实体的父类
|
||||
@@ -87,15 +84,6 @@ public abstract class AbsTaskWrapper<ENTITY extends AbsEntity>
|
||||
*/
|
||||
private TaskOptionParams optionParams = new TaskOptionParams();
|
||||
|
||||
/**
|
||||
* 初始状态列表
|
||||
*/
|
||||
private List<ErrorCode> errorCode = new ArrayList<>();
|
||||
|
||||
public List<ErrorCode> getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setTaskOption(ITaskOption option) {
|
||||
this.taskOption = option;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.arialyy.aria.core.inf.IEntity;
|
||||
*/
|
||||
public interface ITaskWrapper {
|
||||
|
||||
int DEFAULT = 0;
|
||||
int ERROR = 0;
|
||||
|
||||
/**
|
||||
* HTTP单任务载
|
||||
|
||||
@@ -46,7 +46,7 @@ public enum ActionPolicy {
|
||||
/**
|
||||
* 父表有变更时,子表将外键列设置成一个默认的值,default配置的值
|
||||
*/
|
||||
SET_DEFAULT("SET DEFAULT"),
|
||||
SET_DEFAULT("SET ERROR"),
|
||||
|
||||
/**
|
||||
* 在父表上update/delete记录时,同步update/delete掉子表的匹配记录
|
||||
|
||||
@@ -184,7 +184,7 @@ class DelegateCommon extends AbsDelegate {
|
||||
if (SqlUtil.isDefault(field)) {
|
||||
Default d = field.getAnnotation(Default.class);
|
||||
if (!TextUtils.isEmpty(d.value())) {
|
||||
sb.append(" DEFAULT ").append("'").append(d.value()).append("'");
|
||||
sb.append(" ERROR ").append("'").append(d.value()).append("'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,13 +17,6 @@
|
||||
package com.arialyy.aria.util;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.ErrorCode;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.upload.UTaskWrapper;
|
||||
import com.arialyy.aria.core.upload.UploadEntity;
|
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
|
||||
@@ -54,52 +47,12 @@ public class CheckUtil {
|
||||
if (page < 1 || num < 1) throw new NullPointerException("page和num不能小于1");
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测url是否合法,如果url不合法,将抛异常
|
||||
*/
|
||||
public static ErrorCode checkTaskId(long taskId) {
|
||||
if (taskId < 0) {
|
||||
return ErrorCode.ERROR_CODE_TASK_ID_NULL;
|
||||
}
|
||||
return ErrorCode.ERROR_CODE_NORMAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测url是否合法,如果url不合法,将抛异常
|
||||
*/
|
||||
public static void checkUrlInvalidThrow(String url) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
throw new IllegalArgumentException("url不能为null");
|
||||
} else if (!url.startsWith("http") && !url.startsWith("ftp") && !url.startsWith("sftp")) {
|
||||
throw new IllegalArgumentException("url错误");
|
||||
}
|
||||
int index = url.indexOf("://");
|
||||
if (index == -1) {
|
||||
throw new IllegalArgumentException("url不合法");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测url是否合法,如果url不合法,将抛出{@link IllegalArgumentException}异常
|
||||
*/
|
||||
public static void checkUrl(String url) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
throw new NullPointerException("url为空");
|
||||
} else if (!url.startsWith("http") && !url.startsWith("ftp") && !url.startsWith("sftp")) {
|
||||
throw new IllegalArgumentException(String.format("url【%s】错误", url));
|
||||
}
|
||||
int index = url.indexOf("://");
|
||||
if (index == -1) {
|
||||
throw new IllegalArgumentException(String.format("url【%s】不合法", url));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测url是否合法
|
||||
*
|
||||
* @return {@code true} 合法,{@code false} 非法
|
||||
*/
|
||||
public static boolean checkUrlNotThrow(String url) {
|
||||
public static boolean checkUrl(String url) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
ALog.e(TAG, "url不能为null");
|
||||
return false;
|
||||
@@ -116,65 +69,23 @@ public class CheckUtil {
|
||||
|
||||
/**
|
||||
* 检测下载链接组是否为null
|
||||
*
|
||||
* @return true 组合任务url为空
|
||||
*/
|
||||
public static void checkDownloadUrls(List<String> urls) {
|
||||
public static boolean checkDownloadUrlsIsEmpty(List<String> urls) {
|
||||
if (urls == null || urls.isEmpty()) {
|
||||
throw new IllegalArgumentException("链接组不能为null");
|
||||
ALog.e(TAG, "链接组不能为null");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测上传地址是否为null
|
||||
*/
|
||||
public static void checkUploadPath(String uploadPath) {
|
||||
public static void checkUploadPathIsEmpty(String uploadPath) {
|
||||
if (TextUtils.isEmpty(uploadPath)) {
|
||||
throw new IllegalArgumentException("上传地址不能为null");
|
||||
}
|
||||
File file = new File(uploadPath);
|
||||
if (!file.exists()) {
|
||||
throw new IllegalArgumentException("上传文件不存在");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查任务实体
|
||||
*/
|
||||
public static void checkTaskEntity(AbsTaskWrapper entity) {
|
||||
if (entity instanceof DTaskWrapper) {
|
||||
checkDownloadTaskEntity(((DTaskWrapper) entity).getEntity());
|
||||
} else if (entity instanceof UTaskWrapper) {
|
||||
checkUploadTaskEntity(((UTaskWrapper) entity).getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查上传实体是否合法
|
||||
*/
|
||||
private static void checkUploadTaskEntity(UploadEntity entity) {
|
||||
if (entity == null) {
|
||||
throw new NullPointerException("上传实体不能为空");
|
||||
} else if (TextUtils.isEmpty(entity.getFilePath())) {
|
||||
throw new IllegalArgumentException("上传文件路径不能为空");
|
||||
} else if (TextUtils.isEmpty(entity.getFileName())) {
|
||||
throw new IllegalArgumentException("上传文件名不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测下载实体是否合法
|
||||
* 合法(true)
|
||||
*
|
||||
* @param entity 下载实体
|
||||
*/
|
||||
private static void checkDownloadTaskEntity(DownloadEntity entity) {
|
||||
if (entity == null) {
|
||||
throw new NullPointerException("下载实体不能为空");
|
||||
} else if (TextUtils.isEmpty(entity.getUrl())) {
|
||||
throw new IllegalArgumentException("下载链接不能为空");
|
||||
} else if (TextUtils.isEmpty(entity.getFileName())) {
|
||||
throw new NullPointerException("文件名不能为null");
|
||||
} else if (TextUtils.isEmpty(entity.getDownloadPath())) {
|
||||
throw new NullPointerException("文件保存路径不能为null");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user