pull/330/head
AriaLyy 8 years ago
parent 81609a1bf6
commit 360debecc4
  1. 1
      .gitignore
  2. 2
      .idea/modules.xml
  3. 2
      Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java
  4. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  5. 2
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadUtil.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadUtil.java
  7. 44
      Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java

1
.gitignore vendored

@ -11,3 +11,4 @@
.idea/misc.xml .idea/misc.xml
.gradle .gradle
/.idea /.idea
.idea

@ -3,9 +3,7 @@
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/Aria.iml" filepath="$PROJECT_DIR$/Aria.iml" /> <module fileurl="file://$PROJECT_DIR$/Aria.iml" filepath="$PROJECT_DIR$/Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/Aria/Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/Aria/Aria-Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria-Aria.iml" /> <module fileurl="file://$PROJECT_DIR$/Aria/Aria-Aria.iml" filepath="$PROJECT_DIR$/Aria/Aria-Aria.iml" />
<module fileurl="file://$PROJECT_DIR$/AriaPrj.iml" filepath="$PROJECT_DIR$/AriaPrj.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules> </modules>
</component> </component>

@ -40,7 +40,7 @@ public abstract class AbsCmd<T extends ITaskEntity> implements ICmd {
* @param targetName 产生任务的对象名 * @param targetName 产生任务的对象名
*/ */
AbsCmd(String targetName, T entity) { AbsCmd(String targetName, T entity) {
CheckUtil.checkTaskEntity(entity); CheckUtil.checkCmdEntity(entity);
mTargetName = targetName; mTargetName = targetName;
mEntity = entity; mEntity = entity;
TAG = CommonUtil.getClassName(this); TAG = CommonUtil.getClassName(this);

@ -188,7 +188,7 @@ public class DownloadTask implements ITask {
public Builder(String targetName, DownloadTaskEntity taskEntity) { public Builder(String targetName, DownloadTaskEntity taskEntity) {
CheckUtil.checkDownloadEntity(taskEntity.downloadEntity); CheckUtil.checkDownloadTaskEntity(taskEntity.downloadEntity);
this.targetName = targetName; this.targetName = targetName;
this.taskEntity = taskEntity; this.taskEntity = taskEntity;
} }

@ -62,7 +62,7 @@ final class DownloadUtil implements IDownloadUtil, Runnable {
DownloadUtil(Context context, DownloadTaskEntity entity, IDownloadListener downloadListener, DownloadUtil(Context context, DownloadTaskEntity entity, IDownloadListener downloadListener,
int threadNum) { int threadNum) {
CheckUtil.checkDownloadEntity(entity.downloadEntity); CheckUtil.checkDownloadTaskEntity(entity.downloadEntity);
mDownloadEntity = entity.downloadEntity; mDownloadEntity = entity.downloadEntity;
mContext = context.getApplicationContext(); mContext = context.getApplicationContext();
mDownloadTaskEntity = entity; mDownloadTaskEntity = entity;

@ -50,7 +50,7 @@ final class UploadUtil implements Runnable {
UploadUtil(UploadTaskEntity taskEntity, IUploadListener listener) { UploadUtil(UploadTaskEntity taskEntity, IUploadListener listener) {
mTaskEntity = taskEntity; mTaskEntity = taskEntity;
CheckUtil.checkUploadEntity(taskEntity.uploadEntity); CheckUtil.checkUploadTaskEntity(taskEntity.uploadEntity);
mUploadEntity = taskEntity.uploadEntity; mUploadEntity = taskEntity.uploadEntity;
if (listener == null) { if (listener == null) {
throw new IllegalArgumentException("上传监听不能为空"); throw new IllegalArgumentException("上传监听不能为空");

@ -17,14 +17,12 @@
package com.arialyy.aria.util; package com.arialyy.aria.util;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
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.ITaskEntity; import com.arialyy.aria.core.inf.ITaskEntity;
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.FileException; import com.arialyy.aria.exception.FileException;
import java.io.File;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -89,20 +87,40 @@ public class CheckUtil {
*/ */
public static void checkTaskEntity(ITaskEntity entity) { public static void checkTaskEntity(ITaskEntity entity) {
if (entity instanceof DownloadTaskEntity) { if (entity instanceof DownloadTaskEntity) {
checkDownloadEntity(((DownloadTaskEntity) entity).downloadEntity); checkDownloadTaskEntity(((DownloadTaskEntity) entity).downloadEntity);
} else if (entity instanceof UploadTaskEntity) { } else if (entity instanceof UploadTaskEntity) {
checkUploadEntity(((UploadTaskEntity) entity).uploadEntity); checkUploadTaskEntity(((UploadTaskEntity) entity).uploadEntity);
}
}
/**
* 检查命令实体
*/
public static void checkCmdEntity(ITaskEntity entity) {
if (entity instanceof DownloadTaskEntity) {
DownloadEntity entity1 = ((DownloadTaskEntity) entity).downloadEntity;
if (entity1 == null) {
throw new NullPointerException("下载实体不能为空");
} else if (TextUtils.isEmpty(entity1.getDownloadUrl())) {
throw new IllegalArgumentException("下载链接不能为空");
}
} else if (entity instanceof UploadTaskEntity) {
UploadEntity entity1 = ((UploadTaskEntity) entity).uploadEntity;
if (entity1 == null) {
throw new NullPointerException("上传实体不能为空");
} else if (TextUtils.isEmpty(entity1.getFilePath())) {
throw new IllegalArgumentException("上传文件路径不能为空");
}
} }
} }
/** /**
* 检查上传实体是否合法 * 检查上传实体是否合法
*/ */
public static void checkUploadEntity(UploadEntity entity) { public static void checkUploadTaskEntity(UploadEntity entity) {
if (entity == null) { if (entity == null) {
throw new NullPointerException("上传实体不能为空"); throw new NullPointerException("上传实体不能为空");
} } else if (TextUtils.isEmpty(entity.getFilePath())) {
if (TextUtils.isEmpty(entity.getFilePath())) {
throw new IllegalArgumentException("上传文件路径不能为空"); throw new IllegalArgumentException("上传文件路径不能为空");
} else if (TextUtils.isEmpty(entity.getFileName())) { } else if (TextUtils.isEmpty(entity.getFileName())) {
throw new IllegalArgumentException("上传文件名不能为空"); throw new IllegalArgumentException("上传文件名不能为空");
@ -115,7 +133,7 @@ public class CheckUtil {
* @param entity 下载实体 * @param entity 下载实体
* @return 合法(true) * @return 合法(true)
*/ */
public static void checkDownloadEntity(DownloadEntity entity) { public static void checkDownloadTaskEntity(DownloadEntity entity) {
if (entity == null) { if (entity == null) {
throw new NullPointerException("下载实体不能为空"); throw new NullPointerException("下载实体不能为空");
} else if (TextUtils.isEmpty(entity.getDownloadUrl())) { } else if (TextUtils.isEmpty(entity.getDownloadUrl())) {
@ -125,15 +143,5 @@ public class CheckUtil {
} else if (TextUtils.isEmpty(entity.getDownloadPath())) { } else if (TextUtils.isEmpty(entity.getDownloadPath())) {
throw new FileException("文件保存路径不能为null"); throw new FileException("文件保存路径不能为null");
} }
String fileName = entity.getFileName();
if (fileName.contains(" ")) {
fileName = fileName.replace(" ", "_");
}
String dPath = entity.getDownloadPath();
File file = new File(dPath);
if (file.isDirectory()) {
dPath += fileName;
entity.setDownloadPath(dPath);
}
} }
} }
Loading…
Cancel
Save