From 3fa49f11ddad2bd8ae4b5efdc285b1728ac8442a Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Wed, 25 Oct 2017 20:32:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97=E7=BA=A7?= =?UTF-8?q?=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/arialyy/aria/core/AriaManager.java | 23 ++++- .../com/arialyy/aria/core/ConfigHelper.java | 6 +- .../com/arialyy/aria/core/FtpUrlEntity.java | 17 ++++ .../com/arialyy/aria/core/SubTaskManager.java | 8 +- .../com/arialyy/aria/core/TaskManager.java | 4 +- .../arialyy/aria/core/WidgetLiftManager.java | 6 +- .../aria/core/command/group/AbsGroupCmd.java | 4 +- .../core/command/normal/AbsNormalCmd.java | 13 ++- .../aria/core/command/normal/AddCmd.java | 4 +- .../command/normal/HighestPriorityCmd.java | 5 +- .../core/command/normal/ResumeAllCmd.java | 4 +- .../aria/core/command/normal/StartCmd.java | 4 +- .../aria/core/command/normal/StopCmd.java | 4 +- .../arialyy/aria/core/common/AbsFileer.java | 6 +- .../aria/core/common/AbsFtpInfoThread.java | 26 +++--- .../aria/core/common/AbsThreadTask.java | 26 +++--- .../core/download/DownloadGroupTarget.java | 4 +- .../aria/core/download/DownloadGroupTask.java | 4 +- .../aria/core/download/DownloadTask.java | 4 +- .../core/download/FtpDirDownloadTarget.java | 6 +- .../aria/core/download/FtpDownloadTarget.java | 5 +- .../download/downloader/AbsGroupUtil.java | 18 ++-- .../core/download/downloader/Downloader.java | 4 +- .../download/downloader/FtpDirInfoThread.java | 5 +- .../download/downloader/FtpThreadTask.java | 6 +- .../downloader/HttpFileInfoThread.java | 6 +- .../download/downloader/HttpThreadTask.java | 11 ++- .../aria/core/inf/AbsDownloadTarget.java | 4 +- .../com/arialyy/aria/core/inf/AbsTarget.java | 4 +- .../arialyy/aria/core/inf/AbsTaskEntity.java | 2 - .../arialyy/aria/core/queue/AbsTaskQueue.java | 18 ++-- .../core/queue/DownloadGroupTaskQueue.java | 5 +- .../aria/core/queue/DownloadTaskQueue.java | 7 +- .../aria/core/queue/UploadTaskQueue.java | 5 +- .../aria/core/queue/pool/BaseCachePool.java | 16 ++-- .../aria/core/queue/pool/BaseExecutePool.java | 16 ++-- .../core/queue/pool/DownloadExecutePool.java | 8 +- .../aria/core/scheduler/AbsSchedulers.java | 16 ++-- .../aria/core/upload/FtpUploadTarget.java | 6 +- .../core/upload/uploader/FtpThreadTask.java | 6 +- .../core/upload/uploader/HttpThreadTask.java | 8 +- .../java/com/arialyy/aria/orm/DbUtil.java | 6 +- .../java/com/arialyy/aria/orm/SqlHelper.java | 12 +-- .../main/java/com/arialyy/aria/util/ALog.java | 90 +++++++++++++++++++ .../java/com/arialyy/aria/util/CheckUtil.java | 11 ++- .../com/arialyy/aria/util/CommonUtil.java | 31 ++++--- .../simple/download/FtpDownloadActivity.java | 8 +- .../group/FTPDirDownloadActivity.java | 2 +- .../arialyy/aria/core/upload/UploadTask.java | 5 +- 49 files changed, 325 insertions(+), 194 deletions(-) create mode 100644 Aria/src/main/java/com/arialyy/aria/util/ALog.java diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index 2e8df2fa..d26a313a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -27,7 +27,6 @@ import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.text.TextUtils; -import android.util.Log; import android.widget.PopupWindow; import com.arialyy.aria.core.command.ICmd; import com.arialyy.aria.core.common.QueueMod; @@ -42,6 +41,7 @@ import com.arialyy.aria.core.upload.UploadReceiver; import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbUtil; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.io.File; import java.io.IOException; @@ -67,6 +67,16 @@ import org.xml.sax.SAXException; public static final Object LOCK = new Object(); public static final String DOWNLOAD_TEMP_DIR = "/Aria/temp/download/"; public static final String UPLOAD_TEMP_DIR = "/Aria/temp/upload/"; + + public static final int LOG_LEVEL_VERBOSE = 2; + public static final int LOG_LEVEL_DEBUG = 3; + public static final int LOG_LEVEL_INFO = 4; + public static final int LOG_LEVEL_WARN = 5; + public static final int LOG_LEVEL_ERROR = 6; + public static final int LOG_LEVEL_ASSERT = 7; + public static final int LOG_CLOSE = 8; + public static final int LOG_DEFAULT = LOG_LEVEL_DEBUG; + @SuppressLint("StaticFieldLeak") private static volatile AriaManager INSTANCE = null; private Map mReceivers = new ConcurrentHashMap<>(); public static Context APP; @@ -94,6 +104,15 @@ import org.xml.sax.SAXException; return mReceivers; } + /** + * 设置Aria 日志级别 + * + * @param level {@link #LOG_LEVEL_VERBOSE} + */ + public void setLogLevel(int level) { + ALog.LOG_LEVEL = level; + } + /** * 设置上传任务的执行队列类型 * @@ -356,7 +375,7 @@ import org.xml.sax.SAXException; CommonUtil.createFileFormInputStream(APP.getAssets().open("aria_config.xml"), APP.getFilesDir().getPath() + Configuration.XML_FILE); } catch (ParserConfigurationException | IOException | SAXException e) { - Log.e(TAG, e.toString()); + ALog.e(TAG, e.toString()); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java index 6243d5ca..586ceb4e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java @@ -16,7 +16,7 @@ package com.arialyy.aria.core; import android.text.TextUtils; -import android.util.Log; +import com.arialyy.aria.util.ALog; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -210,7 +210,7 @@ class ConfigHelper extends DefaultHandler { num = Integer.parseInt(value); } if (num < 1) { - Log.e(TAG, "任务队列数不能小于 1"); + ALog.w(TAG, "任务队列数不能小于 1"); num = 2; } if (isDownloadConfig) { @@ -227,7 +227,7 @@ class ConfigHelper extends DefaultHandler { num = Integer.parseInt(value); } if (num < 1) { - Log.e(TAG, "下载线程数不能小于 1"); + ALog.e(TAG, "下载线程数不能小于 1"); num = 1; } if (isDownloadConfig) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java b/Aria/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java index 1d4efd45..15e05cd1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java @@ -1,3 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.core; import java.net.InetAddress; diff --git a/Aria/src/main/java/com/arialyy/aria/core/SubTaskManager.java b/Aria/src/main/java/com/arialyy/aria/core/SubTaskManager.java index 803f9275..8169f10d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/SubTaskManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/SubTaskManager.java @@ -16,9 +16,9 @@ package com.arialyy.aria.core; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.command.group.GroupCmdFactory; import com.arialyy.aria.core.inf.AbsGroupTaskEntity; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.util.List; @@ -86,16 +86,16 @@ public class SubTaskManager { */ private boolean checkUrl(String url) { if (TextUtils.isEmpty(url)) { - Log.e(TAG, "子任务地址不能为null"); + ALog.e(TAG, "子任务地址不能为null"); return false; } List urls = mEntity.getEntity().getUrls(); if (urls == null || urls.isEmpty()) { - Log.e(TAG, "任务组任务链接为null"); + ALog.e(TAG, "任务组任务链接为null"); return false; } if (!urls.contains(url)) { - Log.e(TAG, "任务组中没有改Url【+ " + url + "】"); + ALog.e(TAG, "任务组中没有改Url【+ " + url + "】"); return false; } return true; diff --git a/Aria/src/main/java/com/arialyy/aria/core/TaskManager.java b/Aria/src/main/java/com/arialyy/aria/core/TaskManager.java index ebdea6ae..2d8820e2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/TaskManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/TaskManager.java @@ -15,8 +15,8 @@ */ package com.arialyy.aria.core; -import android.util.Log; import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.util.Iterator; import java.util.Map; @@ -54,7 +54,7 @@ public class TaskManager { public boolean addTask(String key, AbsTask task) { String hash = CommonUtil.keyToHashKey(key); if (map.keySet().contains(hash)) { - Log.e(TAG, "任务【" + key + "】已存在"); + ALog.e(TAG, "任务【" + key + "】已存在"); return false; } map.put(CommonUtil.keyToHashKey(key), task); diff --git a/Aria/src/main/java/com/arialyy/aria/core/WidgetLiftManager.java b/Aria/src/main/java/com/arialyy/aria/core/WidgetLiftManager.java index aeac3122..d2dacfd9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/WidgetLiftManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/WidgetLiftManager.java @@ -21,8 +21,8 @@ import android.content.DialogInterface; import android.os.Build; import android.os.Message; import android.support.v4.app.DialogFragment; -import android.util.Log; import android.widget.PopupWindow; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.lang.reflect.Field; @@ -62,7 +62,7 @@ final class WidgetLiftManager { PopupWindow.OnDismissListener listener = (PopupWindow.OnDismissListener) dismissField.get(popupWindow); if (listener != null) { - Log.e(TAG, "你已经对PopupWindow设置了Dismiss事件。为了防止内存泄露," + ALog.e(TAG, "你已经对PopupWindow设置了Dismiss事件。为了防止内存泄露," + "请在dismiss方法中调用Aria.download(this).unRegister();来注销事件"); return true; } else { @@ -97,7 +97,7 @@ final class WidgetLiftManager { Field cancelField = CommonUtil.getField(dialog.getClass(), "mCancelMessage"); Message cancelMsg = (Message) cancelField.get(dialog); if (cancelMsg != null) { - Log.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。" + ALog.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。" + "为了防止内存泄露,请在dismiss方法中调用Aria.download(this).unRegister();来注销事件\n" + "如果你使用的是DialogFragment,那么你需要在onDestroy()中进行销毁Aria事件操作"); return true; diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java index 95bb6c9d..0246b207 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java @@ -15,13 +15,13 @@ */ package com.arialyy.aria.core.command.group; -import android.util.Log; import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.inf.AbsGroupTask; import com.arialyy.aria.core.inf.AbsGroupTaskEntity; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; /** @@ -64,7 +64,7 @@ public abstract class AbsGroupCmd extends AbsCmd extends AbsCmd { TAG = CommonUtil.getClassName(this); if (taskType == ICmd.TASK_TYPE_DOWNLOAD) { if (!(entity instanceof DownloadTaskEntity)) { - Log.w(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD"); + ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD"); return; } mQueue = DownloadTaskQueue.getInstance(); } else if (taskType == ICmd.TASK_TYPE_DOWNLOAD_GROUP) { if (!(entity instanceof DownloadGroupTaskEntity)) { - Log.w(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD_GROUP"); + ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD_GROUP"); return; } mQueue = DownloadGroupTaskQueue.getInstance(); } else if (taskType == ICmd.TASK_TYPE_UPLOAD) { if (!(entity instanceof UploadTaskEntity)) { - Log.w(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_UPLOAD"); + ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_UPLOAD"); return; } mQueue = UploadTaskQueue.getInstance(); } else { - Log.w(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD、TASK_TYPE_DOWNLOAD_GROUP、TASK_TYPE_UPLOAD"); + ALog.e(TAG, "任务类型错误,任务类型应该为ICM.TASK_TYPE_DOWNLOAD、TASK_TYPE_DOWNLOAD_GROUP、TASK_TYPE_UPLOAD"); + return; } isDownloadCmd = taskType < ICmd.TASK_TYPE_UPLOAD; } - - /** * 删除所有任务 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java index 079599d7..9c9c851e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java @@ -16,10 +16,10 @@ package com.arialyy.aria.core.command.normal; -import android.util.Log; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.util.ALog; /** * Created by lyy on 2016/8/22. @@ -38,7 +38,7 @@ class AddCmd extends AbsNormalCmd { mTaskEntity.getEntity().setState(IEntity.STATE_WAIT); createTask(); } else { - Log.w(TAG, "添加命令执行失败,【该任务已经存在】"); + ALog.w(TAG, "添加命令执行失败,【该任务已经存在】"); } } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java index 5ea17930..ac3570d1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java @@ -16,12 +16,11 @@ package com.arialyy.aria.core.command.normal; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.DownloadTask; -import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.queue.DownloadTaskQueue; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.NetUtils; /** @@ -47,7 +46,7 @@ final class HighestPriorityCmd extends AbsNormalCmd @Override public void executeCmd() { if (!canExeCmd) return; if (!NetUtils.isConnected(AriaManager.APP)){ - Log.w(TAG, "启动任务失败,网络未连接"); + ALog.e(TAG, "启动任务失败,网络未连接"); return; } DownloadTask task = (DownloadTask) getTask(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java index e6e0cd8c..ec3560c0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java @@ -1,6 +1,5 @@ package com.arialyy.aria.core.command.normal; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; @@ -11,6 +10,7 @@ import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.NetUtils; import java.util.ArrayList; import java.util.List; @@ -34,7 +34,7 @@ final class ResumeAllCmd extends AbsNormalCmd { @Override public void executeCmd() { if (!NetUtils.isConnected(AriaManager.APP)) { - Log.w(TAG, "恢复任务失败,网络未连接"); + ALog.w(TAG, "恢复任务失败,网络未连接"); return; } if (isDownloadCmd) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java index d5650547..0a6eb7e7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java @@ -17,7 +17,6 @@ package com.arialyy.aria.core.command.normal; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.QueueMod; import com.arialyy.aria.core.download.DownloadGroupTaskEntity; @@ -30,6 +29,7 @@ import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.NetUtils; import java.util.ArrayList; import java.util.List; @@ -48,7 +48,7 @@ class StartCmd extends AbsNormalCmd { @Override public void executeCmd() { if (!canExeCmd) return; if (!NetUtils.isConnected(AriaManager.APP)) { - Log.w(TAG, "启动任务失败,网络未连接"); + ALog.e(TAG, "启动任务失败,网络未连接"); return; } String mod; diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java index 6bd75bf5..15a9479b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java @@ -17,10 +17,10 @@ package com.arialyy.aria.core.command.normal; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.util.ALog; /** * Created by lyy on 2016/9/20. @@ -39,7 +39,7 @@ class StopCmd extends AbsNormalCmd { if (mTaskEntity.getEntity().getState() == IEntity.STATE_RUNNING) { stopTask(); } else { - Log.w(TAG, "停止命令执行失败,【调度器中没有该任务】"); + ALog.w(TAG, "停止命令执行失败,【调度器中没有该任务】"); } } else { if (!TextUtils.isEmpty(mTargetName)) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java index af0a580d..c0687c9a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFileer.java @@ -16,7 +16,6 @@ package com.arialyy.aria.core.common; import android.content.Context; -import android.util.Log; import android.util.SparseArray; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.DownloadTaskEntity; @@ -25,6 +24,7 @@ import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IEventListener; import com.arialyy.aria.core.upload.UploadTaskEntity; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.io.File; import java.util.Properties; @@ -264,7 +264,7 @@ public abstract class AbsFileer= ips.length) { - Log.e(TAG, "遇到[ECONNREFUSED-连接被服务器拒绝]错误,已没有其他地址,链接失败"); + ALog.w(TAG, "遇到[ECONNREFUSED-连接被服务器拒绝]错误,已没有其他地址,链接失败"); return null; } try { @@ -219,7 +221,7 @@ public abstract class AbsFtpInfoThread { mUtil = new FtpDirDownloadUtil(mListener, mTaskEntity); break; } + Log.d(TAG, "FTP_TASK_MD5:" + mTaskEntity.hashCode()); } @Override public boolean isRunning() { @@ -59,7 +61,7 @@ public class DownloadGroupTask extends AbsGroupTask { @Override public void start() { if (mUtil.isRunning()) { - Log.d(TAG, "任务正在下载"); + ALog.d(TAG, "任务正在下载"); } else { mUtil.start(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java index 01effb8d..aa2b7394 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java @@ -18,12 +18,12 @@ package com.arialyy.aria.core.download; import android.os.Handler; import android.os.Looper; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.IUtil; import com.arialyy.aria.core.download.downloader.SimpleDownloadUtil; import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.scheduler.ISchedulers; +import com.arialyy.aria.util.ALog; import java.io.File; /** @@ -115,7 +115,7 @@ public class DownloadTask extends AbsNormalTask { @Override public void start() { mListener.isWait = false; if (mUtil.isRunning()) { - Log.d(TAG, "任务正在下载"); + ALog.d(TAG, "任务正在下载"); } else { mUtil.start(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java index 3ab07527..bb8a1f13 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirDownloadTarget.java @@ -19,6 +19,7 @@ import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; /** @@ -34,6 +35,7 @@ public class FtpDirDownloadTarget mTargetName = targetName; mTaskEntity.urlEntity = CommonUtil.getFtpUrlInfo(url); mTaskEntity.requestType = AbsTaskEntity.FTP_DIR; + Log.d(TAG, "FTP_TARGET_MD5:" + mTaskEntity.hashCode()); } private void init(String key) { @@ -77,10 +79,10 @@ public class FtpDirDownloadTarget */ public FtpDirDownloadTarget login(String userName, String password, String account) { if (TextUtils.isEmpty(userName)) { - Log.e(TAG, "用户名不能为null"); + ALog.e(TAG, "用户名不能为null"); return this; } else if (TextUtils.isEmpty(password)) { - Log.e(TAG, "密码不能为null"); + ALog.e(TAG, "密码不能为null"); return this; } mTaskEntity.urlEntity.needLogin = true; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java index d476f12c..e28769df 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDownloadTarget.java @@ -19,6 +19,7 @@ import android.support.annotation.NonNull; import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.io.File; @@ -100,10 +101,10 @@ public class FtpDownloadTarget extends DownloadTarget { */ public FtpDownloadTarget login(String userName, String password, String account) { if (TextUtils.isEmpty(userName)) { - Log.e(TAG, "用户名不能为null"); + ALog.e(TAG, "用户名不能为null"); return this; } else if (TextUtils.isEmpty(password)) { - Log.e(TAG, "密码不能为null"); + ALog.e(TAG, "密码不能为null"); return this; } mTaskEntity.urlEntity.needLogin = true; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java index 8324e09f..cc0ec1b6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java @@ -15,8 +15,8 @@ */ package com.arialyy.aria.core.download.downloader; -import android.util.Log; import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.common.IUtil; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity; @@ -24,6 +24,7 @@ import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.NetUtils; import java.io.File; @@ -201,11 +202,11 @@ public abstract class AbsGroupUtil implements IUtil { DownloadTaskEntity entity = mTasksMap.get(url); if (entity != null) { if (entity.getState() == IEntity.STATE_COMPLETE) { - Log.w(TAG, "任务【" + url + "】已完成," + type + "失败"); + ALog.w(TAG, "任务【" + url + "】已完成," + type + "失败"); return false; } } else { - Log.w(TAG, "任务组中没有该任务【" + url + "】," + type + "失败"); + ALog.w(TAG, "任务组中没有该任务【" + url + "】," + type + "失败"); return false; } return true; @@ -387,7 +388,7 @@ public abstract class AbsGroupUtil implements IUtil { if (taskEntity != null) { taskEntity.entity = entity; //ftp登录的 - taskEntity.urlEntity = mTaskEntity.urlEntity; + taskEntity.urlEntity = createFtpUrlEntity(entity); mTasksMap.put(entity.getUrl(), taskEntity); return taskEntity; } @@ -401,13 +402,18 @@ public abstract class AbsGroupUtil implements IUtil { taskEntity.isGroupTask = true; taskEntity.requestType = mTaskEntity.requestType; //ftp登录的 - taskEntity.urlEntity = mTaskEntity.urlEntity; - taskEntity.key = entity.getDownloadPath(); + taskEntity.urlEntity = createFtpUrlEntity(entity); taskEntity.save(); mTasksMap.put(entity.getUrl(), taskEntity); return taskEntity; } + private FtpUrlEntity createFtpUrlEntity(DownloadEntity entity) { + FtpUrlEntity urlEntity = CommonUtil.getFtpUrlInfo(entity.getUrl()); + urlEntity.validAddr = mTaskEntity.urlEntity.validAddr; + return urlEntity; + } + /** * 子任务事件监听 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java index f12b6ef4..9d0c966b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java @@ -15,7 +15,6 @@ */ package com.arialyy.aria.core.download.downloader; -import android.util.Log; import com.arialyy.aria.core.common.AbsFileer; import com.arialyy.aria.core.common.AbsThreadTask; import com.arialyy.aria.core.common.SubThreadConfig; @@ -24,6 +23,7 @@ import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IDownloadListener; import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.ErrorHelp; @@ -102,7 +102,7 @@ class Downloader extends AbsFileer { private void failDownload(String errorMsg) { closeTimer(); - Log.e(TAG, errorMsg); + ALog.e(TAG, errorMsg); mConstance.isRunning = false; mListener.onFail(false); ErrorHelp.saveError("", mEntity, "", errorMsg); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java index e3edec7c..a7ba36d8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpDirInfoThread.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core.download.downloader; +import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.common.AbsFtpInfoThread; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.download.DownloadEntity; @@ -52,8 +53,10 @@ class FtpDirInfoThread extends AbsFtpInfoThread InputStream is = null; BufferedRandomAccessFile file = null; try { - Log.d(TAG, "任务【" + ALog.d(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】线程__" + mConfig.THREAD_ID @@ -90,7 +90,7 @@ class FtpThreadTask extends AbsFtpThreadTask } } if (STATE.isCancel || STATE.isStop) return; - Log.i(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】线程__" + mConfig.THREAD_ID + "__下载完毕"); + ALog.i(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】线程__" + mConfig.THREAD_ID + "__下载完毕"); writeConfig(true, 1); STATE.COMPLETE_THREAD_NUM++; if (STATE.isComplete()) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java index 55cd8f4f..105b0ebf 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java @@ -16,11 +16,11 @@ package com.arialyy.aria.core.download.downloader; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.io.IOException; import java.net.HttpURLConnection; @@ -127,7 +127,7 @@ class HttpFileInfoThread implements Runnable { */ private void handle302Turn(HttpURLConnection conn) throws IOException { String newUrl = conn.getHeaderField(mTaskEntity.redirectUrlKey); - Log.d(TAG, "30x跳转,location【 " + mTaskEntity.redirectUrlKey + "】" + "新url为【" + newUrl + "】"); + ALog.d(TAG, "30x跳转,location【 " + mTaskEntity.redirectUrlKey + "】" + "新url为【" + newUrl + "】"); if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null")) { if (onFileInfoListener != null) { onFileInfoListener.onFail(mEntity.getUrl(), "获取重定向链接失败", false); @@ -163,7 +163,7 @@ class HttpFileInfoThread implements Runnable { } private void failDownload(String errorMsg, boolean needRetry) { - Log.e(TAG, errorMsg); + ALog.e(TAG, errorMsg); if (onFileInfoListener != null) { onFileInfoListener.onFail(mEntity.getUrl(), errorMsg, needRetry); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java index dd85cb83..a05c1cdd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java @@ -15,19 +15,18 @@ */ package com.arialyy.aria.core.download.downloader; -import android.util.Log; import com.arialyy.aria.core.common.AbsThreadTask; import com.arialyy.aria.core.common.StateConstance; import com.arialyy.aria.core.common.SubThreadConfig; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.IDownloadListener; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.CommonUtil; import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; @@ -54,7 +53,7 @@ final class HttpThreadTask extends AbsThreadTask extends DbEntity { * 账号和密码 */ @Ignore public FtpUrlEntity urlEntity; - //@Ignore public String userName, userPw, account, serverIp; - //@Ignore public int port; /** * 刷新信息 {@code true} 重新刷新下载信息 diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java index a08aff6e..c76e983d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java @@ -16,13 +16,13 @@ package com.arialyy.aria.core.queue; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.queue.pool.BaseCachePool; import com.arialyy.aria.core.queue.pool.BaseExecutePool; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.NetUtils; /** @@ -114,7 +114,7 @@ abstract class AbsTaskQueue entity.key = entity.getEntity().getFilePath(); mCachePool.putTask(task); } else { - Log.e(TAG, "target name 为 null是!!"); + ALog.e(TAG, "target name 为 null是!!"); } return task; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java index d0c4545f..fb8d0f59 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseCachePool.java @@ -17,12 +17,10 @@ package com.arialyy.aria.core.queue.pool; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.inf.AbsTask; -import com.arialyy.aria.core.inf.ITask; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; -import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -87,16 +85,16 @@ public class BaseCachePool implements IPool { @Override public boolean putTask(TASK task) { synchronized (AriaManager.LOCK) { if (task == null) { - Log.e(TAG, "下载任务不能为空!!"); + ALog.e(TAG, "下载任务不能为空!!"); return false; } String url = task.getKey(); if (mCacheQueue.contains(task)) { - Log.w(TAG, "队列中已经包含了该任务,任务下载链接【" + url + "】"); + ALog.w(TAG, "队列中已经包含了该任务,任务下载链接【" + url + "】"); return false; } else { boolean s = mCacheQueue.offer(task); - Log.d(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】")); + ALog.d(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】")); if (s) { mCacheMap.put(CommonUtil.keyToHashKey(url), task); } @@ -125,7 +123,7 @@ public class BaseCachePool implements IPool { @Override public TASK getTask(String downloadUrl) { synchronized (AriaManager.LOCK) { if (TextUtils.isEmpty(downloadUrl)) { - Log.e(TAG, "请传入有效的下载链接"); + ALog.e(TAG, "请传入有效的下载链接"); return null; } String key = CommonUtil.keyToHashKey(downloadUrl); @@ -136,7 +134,7 @@ public class BaseCachePool implements IPool { @Override public boolean removeTask(TASK task) { synchronized (AriaManager.LOCK) { if (task == null) { - Log.e(TAG, "任务不能为空"); + ALog.e(TAG, "任务不能为空"); return false; } else { String key = CommonUtil.keyToHashKey(task.getKey()); @@ -149,7 +147,7 @@ public class BaseCachePool implements IPool { @Override public boolean removeTask(String downloadUrl) { synchronized (AriaManager.LOCK) { if (TextUtils.isEmpty(downloadUrl)) { - Log.e(TAG, "请传入有效的下载链接"); + ALog.e(TAG, "请传入有效的下载链接"); return false; } String key = CommonUtil.keyToHashKey(downloadUrl); diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java index 02d18d36..58e69bc2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/BaseExecutePool.java @@ -17,9 +17,9 @@ package com.arialyy.aria.core.queue.pool; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.util.Map; import java.util.concurrent.ArrayBlockingQueue; @@ -62,12 +62,12 @@ public class BaseExecutePool implements IPool { @Override public boolean putTask(TASK task) { synchronized (AriaManager.LOCK) { if (task == null) { - Log.e(TAG, "任务不能为空!!"); + ALog.e(TAG, "任务不能为空!!"); return false; } String url = task.getKey(); if (mExecuteQueue.contains(task)) { - Log.e(TAG, "队列中已经包含了该任务,任务key【" + url + "】"); + ALog.e(TAG, "队列中已经包含了该任务,任务key【" + url + "】"); return false; } else { if (mExecuteQueue.size() >= mSize) { @@ -112,7 +112,7 @@ public class BaseExecutePool implements IPool { synchronized (AriaManager.LOCK) { String url = newTask.getKey(); boolean s = mExecuteQueue.offer(newTask); - Log.w(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】")); + ALog.d(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】")); if (s) { mExecuteMap.put(CommonUtil.keyToHashKey(url), newTask); } @@ -128,7 +128,7 @@ public class BaseExecutePool implements IPool { try { TASK oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS); if (oldTask == null) { - Log.e(TAG, "移除任务失败"); + ALog.w(TAG, "移除任务失败"); return false; } oldTask.stop(); @@ -162,7 +162,7 @@ public class BaseExecutePool implements IPool { @Override public TASK getTask(String key) { synchronized (AriaManager.LOCK) { if (TextUtils.isEmpty(key)) { - Log.e(TAG, "请传入有效的任务key"); + ALog.e(TAG, "请传入有效的任务key"); return null; } return mExecuteMap.get(CommonUtil.keyToHashKey(key)); @@ -172,7 +172,7 @@ public class BaseExecutePool implements IPool { @Override public boolean removeTask(TASK task) { synchronized (AriaManager.LOCK) { if (task == null) { - Log.e(TAG, "任务不能为空"); + ALog.e(TAG, "任务不能为空"); return false; } else { return removeTask(task.getKey()); @@ -183,7 +183,7 @@ public class BaseExecutePool implements IPool { @Override public boolean removeTask(String key) { synchronized (AriaManager.LOCK) { if (TextUtils.isEmpty(key)) { - Log.e(TAG, "请传入有效的任务key"); + ALog.e(TAG, "请传入有效的任务key"); return false; } String convertKey = CommonUtil.keyToHashKey(key); diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java index 5c4d03e8..4fde7329 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java @@ -15,9 +15,9 @@ */ package com.arialyy.aria.core.queue.pool; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -36,13 +36,13 @@ class DownloadExecutePool extends BaseExecutePool { @Override public boolean putTask(TASK task) { synchronized (AriaManager.LOCK) { if (task == null) { - Log.e(TAG, "任务不能为空!!"); + ALog.e(TAG, "任务不能为空!!"); return false; } String url = task.getKey(); if (mExecuteQueue.contains(task)) { if (!task.isRunning()) return true; - Log.e(TAG, "队列中已经包含了该任务,任务key【" + url + "】"); + ALog.e(TAG, "队列中已经包含了该任务,任务key【" + url + "】"); return false; } else { if (mExecuteQueue.size() >= mSize) { @@ -65,7 +65,7 @@ class DownloadExecutePool extends BaseExecutePool { try { TASK oldTask = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS); if (oldTask == null) { - Log.e(TAG, "移除任务失败"); + ALog.e(TAG, "移除任务失败"); return false; } if (oldTask.isHighestPriorityTask()) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java index 94c6ce9e..1c6a47bd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java @@ -17,7 +17,6 @@ package com.arialyy.aria.core.scheduler; import android.os.CountDownTimer; import android.os.Message; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.inf.AbsEntity; @@ -28,6 +27,7 @@ import com.arialyy.aria.core.inf.GroupSendParams; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.queue.ITaskQueue; import com.arialyy.aria.core.upload.UploadTask; +import com.arialyy.aria.util.ALog; import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -60,7 +60,7 @@ abstract class AbsSchedulers) clazz.newInstance(); } catch (ClassNotFoundException e) { - Log.e(TAG, targetName + ",没有Aria的Download或Upload注解方法"); + ALog.e(TAG, targetName + ",没有Aria的Download或Upload注解方法"); } catch (InstantiationException e) { - Log.e(TAG, e.getMessage()); + ALog.e(TAG, e.getMessage()); } catch (IllegalAccessException e) { - Log.e(TAG, e.getMessage()); + ALog.e(TAG, e.getMessage()); } return listener; } @@ -100,7 +100,7 @@ abstract class AbsSchedulers listener) { if (listener != null) { if (task == null) { - Log.e(TAG, "TASK 为null,回调失败"); + ALog.e(TAG, "TASK 为null,回调失败"); return; } switch (state) { @@ -275,7 +275,7 @@ abstract class AbsSchedulers { FTPClient client = null; BufferedRandomAccessFile file = null; try { - Log.d(TAG, "任务【" + ALog.d(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】线程__" + mConfig.THREAD_ID @@ -71,7 +71,7 @@ class FtpThreadTask extends AbsFtpThreadTask { } upload(client, file); if (STATE.isCancel || STATE.isStop) return; - Log.i(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】线程__" + mConfig.THREAD_ID + "__上传完毕"); + ALog.i(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】线程__" + mConfig.THREAD_ID + "__上传完毕"); writeConfig(true, 1); STATE.COMPLETE_THREAD_NUM++; if (STATE.isComplete()) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java index 58a91259..2ac37421 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java @@ -15,13 +15,13 @@ */ package com.arialyy.aria.core.upload.uploader; -import android.util.Log; import com.arialyy.aria.core.common.AbsThreadTask; import com.arialyy.aria.core.common.StateConstance; import com.arialyy.aria.core.common.SubThreadConfig; import com.arialyy.aria.core.inf.IUploadListener; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadTaskEntity; +import com.arialyy.aria.util.ALog; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -56,7 +56,7 @@ class HttpThreadTask extends AbsThreadTask { @Override public void run() { File uploadFile = new File(mEntity.getFilePath()); if (!uploadFile.exists()) { - Log.e(TAG, "【" + mEntity.getFilePath() + "】,文件不存在。"); + ALog.e(TAG, "【" + mEntity.getFilePath() + "】,文件不存在。"); fail(); return; } @@ -89,7 +89,7 @@ class HttpThreadTask extends AbsThreadTask { addFormField(writer, key, mTaskEntity.formFields.get(key)); } uploadFile(writer, mTaskEntity.attachment, uploadFile); - Log.d(TAG, finish(writer) + ""); + finish(writer); } catch (IOException e) { e.printStackTrace(); fail(); @@ -193,7 +193,7 @@ class HttpThreadTask extends AbsThreadTask { reader.close(); mHttpConn.disconnect(); } else { - Log.w(TAG, "state_code = " + status); + ALog.w(TAG, "state_code = " + status); fail(); } diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java b/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java index 9ddce325..172ea821 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java @@ -21,8 +21,8 @@ import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.support.annotation.NonNull; -import android.util.Log; import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; import java.util.List; @@ -203,10 +203,10 @@ public class DbUtil { synchronized int getRowId(Class clazz, Object[] wheres, Object[] values) { checkDb(); if (wheres.length <= 0 || values.length <= 0) { - Log.e(TAG, "请输入删除条件"); + ALog.e(TAG, "请输入删除条件"); return -1; } else if (wheres.length != values.length) { - Log.e(TAG, "groupName 和 vaule 长度不相等"); + ALog.e(TAG, "groupName 和 vaule 长度不相等"); return -1; } StringBuilder sb = new StringBuilder(); diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java index 0abbafad..d6b5e7db 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -22,8 +22,8 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.support.annotation.NonNull; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; import java.lang.reflect.Field; @@ -96,10 +96,10 @@ final class SqlHelper extends SQLiteOpenHelper { */ private void handleDbUpdate(SQLiteDatabase db) { if (db == null) { - Log.d("SqlHelper", "db 为 null"); + ALog.e("SqlHelper", "db 为 null"); return; } else if (!db.isOpen()) { - Log.d("SqlHelper", "db已关闭"); + ALog.e("SqlHelper", "db已关闭"); return; } Set tables = DBConfig.mapping.keySet(); @@ -206,10 +206,10 @@ final class SqlHelper extends SQLiteOpenHelper { Class clazz, @NonNull String[] wheres, @NonNull String[] values) { db = checkDb(db); if (wheres.length <= 0 || values.length <= 0) { - Log.e(TAG, "请输入查询条件"); + ALog.e(TAG, "请输入查询条件"); return null; } else if (wheres.length != values.length) { - Log.e(TAG, "groupName 和 vaule 长度不相等"); + ALog.e(TAG, "groupName 和 vaule 长度不相等"); return null; } StringBuilder sb = new StringBuilder(); @@ -517,7 +517,7 @@ final class SqlHelper extends SQLiteOpenHelper { str = "遍历整个数据库 >>>> "; break; } - Log.v(TAG, str + sql); + ALog.v(TAG, str + sql); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/util/ALog.java b/Aria/src/main/java/com/arialyy/aria/util/ALog.java new file mode 100644 index 00000000..6c6eeb3a --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/util/ALog.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.util; + +import android.text.TextUtils; +import android.util.Log; +import com.arialyy.aria.core.AriaManager; + +/** + * Created by Aria.Lao on 2017/10/25. + * Aria日志工具 + */ +public class ALog { + + public static int LOG_LEVEL = AriaManager.LOG_DEFAULT; + + public static int v(String tag, String msg) { + return println(Log.VERBOSE, tag, msg); + } + + public static int d(String tag, String msg) { + return println(Log.DEBUG, tag, msg); + } + + public static int i(String tag, String msg) { + return println(Log.INFO, tag, msg); + } + + public static int w(String tag, String msg) { + return println(Log.WARN, tag, msg); + } + + public static int e(String tag, String msg) { + return println(Log.ERROR, tag, msg); + } + + public static int e(String tag, Throwable e) { + return println(Log.ERROR, tag, getExceptionString(e)); + } + + /** + * 将异常信息转换为字符串 + */ + public static String getExceptionString(Throwable ex) { + StringBuilder err = new StringBuilder(); + err.append("ExceptionDetailed:\n"); + err.append("====================Exception Info====================\n"); + err.append(ex.toString()); + err.append("\n"); + StackTraceElement[] stack = ex.getStackTrace(); + for (StackTraceElement stackTraceElement : stack) { + err.append(stackTraceElement.toString()).append("\n"); + } + Throwable cause = ex.getCause(); + if (cause != null) { + err.append("【Caused by】: "); + err.append(cause.toString()); + err.append("\n"); + StackTraceElement[] stackTrace = cause.getStackTrace(); + for (StackTraceElement stackTraceElement : stackTrace) { + err.append(stackTraceElement.toString()).append("\n"); + } + } + err.append("==================================================="); + return err.toString(); + } + + private static int println(int level, String tag, String msg) { + if (LOG_LEVEL <= level) { + return Log.println(level, tag, TextUtils.isEmpty(msg) ? "null" : msg); + } else { + return -1; + } + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java index 745d2826..2f2d7353 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CheckUtil.java @@ -17,7 +17,6 @@ package com.arialyy.aria.util; import android.text.TextUtils; -import android.util.Log; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; @@ -135,20 +134,20 @@ public class CheckUtil { if (entity instanceof DownloadTaskEntity) { DownloadEntity entity1 = ((DownloadTaskEntity) entity).getEntity(); if (entity1 == null) { - Log.e(TAG, "下载实体不能为空"); + ALog.e(TAG, "下载实体不能为空"); } else if (checkType && TextUtils.isEmpty(entity1.getUrl())) { - Log.e(TAG, "下载链接不能为空"); + ALog.e(TAG, "下载链接不能为空"); } else if (checkType && TextUtils.isEmpty(entity1.getDownloadPath())) { - Log.e(TAG, "保存路径不能为空"); + ALog.e(TAG, "保存路径不能为空"); } else { b = true; } } else if (entity instanceof UploadTaskEntity) { UploadEntity entity1 = ((UploadTaskEntity) entity).getEntity(); if (entity1 == null) { - Log.e(TAG, "上传实体不能为空"); + ALog.e(TAG, "上传实体不能为空"); } else if (TextUtils.isEmpty(entity1.getFilePath())) { - Log.e(TAG, "上传文件路径不能为空"); + ALog.e(TAG, "上传文件路径不能为空"); } else { b = true; } diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index b8b2b0c6..b71f89b6 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -22,7 +22,6 @@ import android.content.SharedPreferences; import android.net.Uri; import android.text.TextUtils; import android.util.Base64; -import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.command.ICmd; @@ -251,7 +250,7 @@ public class CommonUtil { md.update(sb.toString().getBytes()); md5 = new BigInteger(1, md.digest()).toString(16); } catch (NoSuchAlgorithmException e) { - Log.e(TAG, e.getMessage()); + ALog.e(TAG, e.getMessage()); } return md5; } @@ -356,12 +355,12 @@ public class CommonUtil { File dir = new File("/sys/devices/system/cpu/"); //Filter to only list the devices we care about File[] files = dir.listFiles(new CpuFilter()); - Log.d(TAG, "CPU Count: " + files.length); + ALog.d(TAG, "CPU Count: " + files.length); //Return the number of cores (virtual CPU devices) return files.length; } catch (Exception e) { //Print exception - Log.d(TAG, "CPU Count: Failed."); + ALog.d(TAG, "CPU Count: Failed."); e.printStackTrace(); //Default to return 1 core return 1; @@ -391,13 +390,13 @@ public class CommonUtil { */ public static boolean checkMD5(String md5, File updateFile) { if (TextUtils.isEmpty(md5) || updateFile == null) { - Log.e(TAG, "MD5 string empty or updateFile null"); + ALog.e(TAG, "MD5 string empty or updateFile null"); return false; } String calculatedDigest = getFileMD5(updateFile); if (calculatedDigest == null) { - Log.e(TAG, "calculatedDigest null"); + ALog.e(TAG, "calculatedDigest null"); return false; } return calculatedDigest.equalsIgnoreCase(md5); @@ -408,13 +407,13 @@ public class CommonUtil { */ public static boolean checkMD5(String md5, InputStream is) { if (TextUtils.isEmpty(md5) || is == null) { - Log.e(TAG, "MD5 string empty or updateFile null"); + ALog.e(TAG, "MD5 string empty or updateFile null"); return false; } String calculatedDigest = getFileMD5(is); if (calculatedDigest == null) { - Log.e(TAG, "calculatedDigest null"); + ALog.e(TAG, "calculatedDigest null"); return false; } return calculatedDigest.equalsIgnoreCase(md5); @@ -428,7 +427,7 @@ public class CommonUtil { try { is = new FileInputStream(updateFile); } catch (FileNotFoundException e) { - Log.e(TAG, "Exception while getting FileInputStream", e); + ALog.e(TAG, e); return null; } @@ -443,7 +442,7 @@ public class CommonUtil { try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { - Log.e(TAG, "Exception while getting digest", e); + ALog.e(TAG, e); return null; } @@ -465,7 +464,7 @@ public class CommonUtil { try { is.close(); } catch (IOException e) { - Log.e(TAG, "Exception on closing MD5 input stream", e); + ALog.e(TAG, e); } } } @@ -699,7 +698,7 @@ public class CommonUtil { File file = new File(path); if (!file.exists()) { if (!file.mkdirs()) { - Log.d(TAG, "创建失败,请检查路径和是否配置文件权限!"); + ALog.d(TAG, "创建失败,请检查路径和是否配置文件权限!"); return false; } return true; @@ -714,14 +713,14 @@ public class CommonUtil { */ public static void createFile(String path) { if (TextUtils.isEmpty(path)) { - Log.e(TAG, "文件路径不能为null"); + ALog.e(TAG, "文件路径不能为null"); return; } File file = new File(path); if (!file.getParentFile().exists()) { - Log.d(TAG, "目标文件所在路径不存在,准备创建……"); + ALog.d(TAG, "目标文件所在路径不存在,准备创建……"); if (!createDir(file.getParent())) { - Log.d(TAG, "创建目录文件所在的目录失败!文件路径【" + path + "】"); + ALog.d(TAG, "创建目录文件所在的目录失败!文件路径【" + path + "】"); } } // 创建目标文件 @@ -732,7 +731,7 @@ public class CommonUtil { } try { if (file.createNewFile()) { - Log.d(TAG, "创建文件成功:" + file.getAbsolutePath()); + ALog.d(TAG, "创建文件成功:" + file.getAbsolutePath()); } } catch (IOException e) { e.printStackTrace(); diff --git a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java index e7dd8d89..65f0e100 100644 --- a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java @@ -36,7 +36,9 @@ import java.io.File; */ public class FtpDownloadActivity extends BaseActivity { //private final String URL = "ftp://192.168.1.9:21/下载/AriaPrj.zip"; - private final String URL = "ftp://192.168.1.9:21/下载/[电影天堂www.dy2018.com]赛车总动员3BD中英双字.mp4"; + //private final String URL = "ftp://192.168.1.9:21/下载/[电影天堂www.dy2018.com]赛车总动员3BD中英双字.mp4"; + //private final String URL = "ftp://d:d@dygodj8.com:12311/[电影天堂www.dy2018.com]光辉岁月BD韩语中字.rmvb"; + private final String URL = "ftp://172.18.104.64:21/upload/成都.mp3"; @Override protected void init(Bundle savedInstanceState) { super.init(savedInstanceState); @@ -58,8 +60,8 @@ public class FtpDownloadActivity extends BaseActivity { - private static final String dir = "ftp://172.18.104.49:21/haha/"; + private static final String dir = "ftp://172.18.104.64:21/haha/"; @Bind(R.id.child_list) SubStateLinearLayout mChildList; diff --git a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java index 0df8d652..678a84ac 100644 --- a/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java +++ b/aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java @@ -17,11 +17,10 @@ package com.arialyy.aria.core.upload; import android.os.Handler; import android.os.Looper; -import android.util.Log; -import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.core.upload.uploader.SimpleUploadUtil; +import com.arialyy.aria.util.ALog; /** * Created by lyy on 2017/2/23. @@ -54,7 +53,7 @@ public class UploadTask extends AbsNormalTask { @Override public void start() { if (mUtil.isRunning()) { - Log.d(TAG, "任务正在下载"); + ALog.d(TAG, "任务正在下载"); } else { mUtil.start(); }