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 e848813b..9e0d094e 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 @@ -17,7 +17,7 @@ package com.arialyy.aria.core.command.normal; import android.util.Log; -import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; @@ -33,7 +33,7 @@ class AddCmd extends AbsNormalCmd { @Override public void executeCmd() { if (!canExeCmd) return; - AbsTask task = mQueue.getTask(mTaskEntity.getEntity()); + AbsNormalTask task = mQueue.getTask(mTaskEntity.getEntity()); if (task == null) { mTaskEntity.getEntity().setState(IEntity.STATE_WAIT); mQueue.createTask(mTargetName, mTaskEntity); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java index d12f0cad..5621da16 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java @@ -17,7 +17,7 @@ package com.arialyy.aria.core.command.normal; import android.text.TextUtils; -import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.AbsTaskEntity; /** @@ -31,7 +31,7 @@ class CancelCmd extends AbsNormalCmd { @Override public void executeCmd() { if (!canExeCmd) return; - AbsTask task = mQueue.getTask(mTaskEntity.getEntity()); + AbsNormalTask task = mQueue.getTask(mTaskEntity.getEntity()); if (task == null) { task = mQueue.createTask(mTargetName, mTaskEntity); } 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 a52555a8..f12b6487 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,7 +16,7 @@ package com.arialyy.aria.core.command.normal; import android.text.TextUtils; -import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.AbsTaskEntity; /** @@ -39,7 +39,7 @@ final class HighestPriorityCmd extends AbsNormalCmd @Override public void executeCmd() { if (!canExeCmd) return; - AbsTask task = mQueue.getTask(mTaskEntity.getEntity()); + AbsNormalTask task = mQueue.getTask(mTaskEntity.getEntity()); if (task == null) { task = mQueue.createTask(mTargetName, mTaskEntity); } 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 58b26bdc..8ae46e85 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 @@ -3,7 +3,7 @@ package com.arialyy.aria.core.command.normal; import android.util.Log; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; -import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.orm.DbEntity; @@ -29,7 +29,7 @@ final class ResumeAllCmd extends AbsNormalCmd { for (DownloadEntity entity : allEntity) { int exeNum = mQueue.getExePoolSize(); if (exeNum == 0 || exeNum < mQueue.getMaxTaskNum()) { - AbsTask task = createTask(entity); + AbsNormalTask task = createTask(entity); mQueue.startTask(task); } else { entity.setState(IEntity.STATE_WAIT); @@ -38,8 +38,8 @@ final class ResumeAllCmd extends AbsNormalCmd { } } - private AbsTask createTask(DownloadEntity entity) { - AbsTask task = mQueue.getTask(entity); + private AbsNormalTask createTask(DownloadEntity entity) { + AbsNormalTask task = mQueue.getTask(entity); if (task == null) { DownloadTaskEntity taskEntity = new DownloadTaskEntity(entity); task = mQueue.createTask(mTargetName, taskEntity); 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 2b042a27..39f58cd7 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 @@ -19,7 +19,7 @@ package com.arialyy.aria.core.command.normal; import android.text.TextUtils; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.QueueMod; -import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; @@ -47,7 +47,7 @@ class StartCmd extends AbsNormalCmd { maxTaskNum = manager.getUploadConfig().getMaxTaskNum(); } - AbsTask task = mQueue.getTask(mTaskEntity.getEntity()); + AbsNormalTask task = mQueue.getTask(mTaskEntity.getEntity()); if (task == null) { task = mQueue.createTask(mTargetName, mTaskEntity); if (!TextUtils.isEmpty(mTargetName)) { 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 9d0b0811..84d55329 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 @@ -18,7 +18,7 @@ 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.AbsNormalTask; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; @@ -34,7 +34,7 @@ class StopCmd extends AbsNormalCmd { @Override public void executeCmd() { if (!canExeCmd) return; - AbsTask task = mQueue.getTask(mTaskEntity.getEntity()); + AbsNormalTask task = mQueue.getTask(mTaskEntity.getEntity()); if (task == null) { if (mTaskEntity.getEntity().getState() == IEntity.STATE_RUNNING) { task = mQueue.createTask(mTargetName, mTaskEntity); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java new file mode 100644 index 00000000..4cfaa7a3 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupEntity.java @@ -0,0 +1,65 @@ +/* + * 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.core.download; + +import android.os.Parcel; +import com.arialyy.aria.core.inf.AbsGroupEntity; +import java.util.LinkedList; +import java.util.List; + +/** + * Created by AriaL on 2017/6/29. + * 下载任务组实体 + */ +public class DownloadGroupEntity extends AbsGroupEntity { + + private List mChild = new LinkedList<>(); + + public List getChild() { + return mChild; + } + + public void setChild(List child) { + this.mChild = child; + } + + @Override public int describeContents() { + return 0; + } + + @Override public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeTypedList(this.mChild); + } + + public DownloadGroupEntity() { + } + + protected DownloadGroupEntity(Parcel in) { + super(in); + this.mChild = in.createTypedArrayList(DownloadEntity.CREATOR); + } + + public static final Creator CREATOR = new Creator() { + @Override public DownloadGroupEntity createFromParcel(Parcel source) { + return new DownloadGroupEntity(source); + } + + @Override public DownloadGroupEntity[] newArray(int size) { + return new DownloadGroupEntity[size]; + } + }; +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java new file mode 100644 index 00000000..9a60b807 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java @@ -0,0 +1,24 @@ +/* + * 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.core.download; + +/** + * Created by AriaL on 2017/6/30. + */ + +public class DownloadGroupListener { + +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java new file mode 100644 index 00000000..308c041e --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java @@ -0,0 +1,269 @@ +///* +// * 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.core.download; +// +//import android.content.Context; +//import android.os.Handler; +//import android.util.SparseArray; +//import com.arialyy.aria.core.Aria; +//import com.arialyy.aria.core.AriaManager; +//import com.arialyy.aria.core.download.downloader.DownloadListener; +//import com.arialyy.aria.core.download.downloader.DownloadUtil; +//import com.arialyy.aria.core.inf.AbsGroupTask; +//import com.arialyy.aria.core.inf.IEntity; +//import com.arialyy.aria.core.scheduler.DownloadSchedulers; +//import com.arialyy.aria.core.scheduler.ISchedulers; +//import com.arialyy.aria.util.CheckUtil; +//import com.arialyy.aria.util.CommonUtil; +//import java.lang.ref.WeakReference; +//import java.util.HashMap; +//import java.util.List; +//import java.util.Map; +//import java.util.concurrent.ExecutorService; +//import java.util.concurrent.Executors; +// +///** +// * Created by AriaL on 2017/6/27. +// * 任务组任务 +// */ +//public class DownloadGroupTask extends AbsGroupTask { +// DListener mListener; +// SparseArray mUtils = new SparseArray<>(); +// boolean isStop = false; +// +// private ExecutorService mFixedThreadPool; +// +// private DownloadGroupTask(DownloadTaskEntity taskEntity, Handler outHandler) { +// mTaskEntity = taskEntity; +// mEntity = taskEntity.groupEntity; +// mOutHandler = outHandler; +// mContext = AriaManager.APP; +// mListener = new DListener(mContext, this, mOutHandler); +// mFixedThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); +// } +// +// @Override public void start() { +// List childs = mEntity.getChild(); +// int i = 1; +// mListener.sendInState2Target(ISchedulers.PRE); +// for (DownloadEntity entity : childs) { +// DownloadUtil util = createChildDownload(entity); +// if (isStop) break; +// mUtils.append(i, util); +// mFixedThreadPool.execute(util); +// i++; +// } +// } +// +// /** +// * 创建任务组单个任务下载工具 +// */ +// private DownloadUtil createChildDownload(DownloadEntity entity) { +// DownloadTaskEntity taskEntity = new DownloadTaskEntity(entity); +// taskEntity.headers = mTaskEntity.headers; +// taskEntity.requestEnum = mTaskEntity.requestEnum; +// taskEntity.redirectUrlKey = mTaskEntity.redirectUrlKey; +// taskEntity.removeFile = mTaskEntity.removeFile; +// return new DownloadUtil(mContext, taskEntity, mListener); +// } +// +// @Override public void stop() { +// isStop = true; +// if (mFixedThreadPool != null) { +// mFixedThreadPool.shutdown(); +// } +// for (int i = 1, len = mUtils.size(); i <= len; i++) { +// DownloadUtil util = mUtils.get(i); +// if (util != null && util.isDownloading()) { +// util.stopDownload(); +// } +// } +// } +// +// @Override public void cancel() { +// isStop = true; +// if (mFixedThreadPool != null) { +// mFixedThreadPool.shutdown(); +// } +// for (int i = 1, len = mUtils.size(); i <= len; i++) { +// DownloadUtil util = mUtils.get(i); +// if (util != null) { +// util.cancelDownload(); +// } +// } +// } +// +// /** +// * 下载监听类 +// */ +// private static class DListener extends DownloadListener { +// WeakReference outHandler; +// WeakReference wTask; +// Context context; +// long lastLen = 0; //上一次发送长度 +// long lastTime = 0; +// long INTERVAL_TIME = 1000; //1m更新周期 +// boolean isFirst = true; +// DownloadGroupEntity groupEntity; +// DownloadGroupTask task; +// boolean isConvertSpeed = false; +// Map mEntityMap = new HashMap<>(); +// +// DListener(Context context, DownloadGroupTask task, Handler outHandler) { +// this.context = context; +// this.outHandler = new WeakReference<>(outHandler); +// this.wTask = new WeakReference<>(task); +// this.task = wTask.get(); +// this.groupEntity = this.task.getEntity(); +// final AriaManager manager = AriaManager.getInstance(context); +// isConvertSpeed = manager.getDownloadConfig().isConvertSpeed(); +// for (DownloadEntity entity : groupEntity.getChild()) { +// mEntityMap.put(entity.getDownloadUrl(), entity); +// } +// } +// +// @Override public void onPre(String url) { +// saveData(url, IEntity.STATE_PRE, -1); +// } +// +// @Override public void onPostPre(String url, long fileSize) { +// DownloadEntity entity = mEntityMap.get(url); +// if (entity != null){ +// entity.setFileSize(fileSize); +// } +// saveData(url, IEntity.STATE_POST_PRE, -1); +// } +// +// @Override public void onStart(String url, long startLocation) { +// downloadEntity.setState(IEntity.STATE_RUNNING); +// sendInState2Target(ISchedulers.START); +// sendIntent(Aria.ACTION_START, startLocation); +// } +// +// @Override public void onResume(String url, long resumeLocation) { +// downloadEntity.setState(IEntity.STATE_RUNNING); +// sendInState2Target(ISchedulers.RESUME); +// sendIntent(Aria.ACTION_RESUME, resumeLocation); +// } +// +// @Override public void onProgress(String url, long currentLocation) { +// if (System.currentTimeMillis() - lastTime > INTERVAL_TIME) { +// long speed = currentLocation - lastLen; +// sendIntent.putExtra(Aria.CURRENT_LOCATION, currentLocation); +// sendIntent.putExtra(Aria.CURRENT_SPEED, speed); +// lastTime = System.currentTimeMillis(); +// if (isFirst) { +// speed = 0; +// isFirst = false; +// } +// handleSpeed(speed); +// downloadEntity.setCurrentProgress(currentLocation); +// lastLen = currentLocation; +// sendInState2Target(ISchedulers.RUNNING); +// context.sendBroadcast(sendIntent); +// } +// } +// +// @Override public void onStop(String url, long stopLocation) { +// downloadEntity.setState(task.isWait ? IEntity.STATE_WAIT : IEntity.STATE_STOP); +// handleSpeed(0); +// sendInState2Target(ISchedulers.STOP); +// sendIntent(Aria.ACTION_STOP, stopLocation); +// } +// +// @Override public void onCancel(String url) { +// downloadEntity.setState(IEntity.STATE_CANCEL); +// handleSpeed(0); +// sendInState2Target(ISchedulers.CANCEL); +// sendIntent(Aria.ACTION_CANCEL, -1); +// downloadEntity.deleteData(); +// } +// +// @Override public void onComplete(String url) { +// downloadEntity.setState(IEntity.STATE_COMPLETE); +// downloadEntity.setDownloadComplete(true); +// handleSpeed(0); +// sendInState2Target(ISchedulers.COMPLETE); +// sendIntent(Aria.ACTION_COMPLETE, downloadEntity.getFileSize()); +// } +// +// @Override public void onFail(String url) { +// downloadEntity.setFailNum(downloadEntity.getFailNum() + 1); +// downloadEntity.setState(IEntity.STATE_FAIL); +// handleSpeed(0); +// sendInState2Target(ISchedulers.FAIL); +// sendIntent(Aria.ACTION_FAIL, -1); +// } +// +// private void handleSpeed(long speed) { +// if (isConvertSpeed) { +// downloadEntity.setConvertSpeed(CommonUtil.formatFileSize(speed) + "/s"); +// } else { +// downloadEntity.setSpeed(speed); +// } +// } +// +// /** +// * 将任务状态发送给下载器 +// * +// * @param state {@link DownloadSchedulers#START} +// */ +// private void sendInState2Target(int state) { +// if (outHandler.get() != null) { +// outHandler.get().obtainMessage(state, task).sendToTarget(); +// } +// } +// +// private void saveData(String url, int state, long location) { +// DownloadEntity child = mEntityMap.get(url); +// if (child != null) { +// child.setState(state); +// child.setDownloadComplete(state == IEntity.STATE_COMPLETE); +// child.setCurrentProgress(location); +// child.update(); +// } +// } +// } +// +// public static class Builder { +// DownloadTaskEntity taskEntity; +// Handler outHandler; +// String targetName; +// +// public Builder(String targetName, DownloadTaskEntity taskEntity) { +// CheckUtil.checkTaskEntity(taskEntity); +// this.targetName = targetName; +// this.taskEntity = taskEntity; +// } +// +// /** +// * 设置自定义Handler处理下载状态时间 +// * +// * @param schedulers {@link ISchedulers} +// */ +// public DownloadGroupTask.Builder setOutHandler(ISchedulers schedulers) { +// this.outHandler = new Handler(schedulers); +// return this; +// } +// +// public DownloadGroupTask build() { +// DownloadGroupTask task = new DownloadGroupTask(taskEntity, outHandler); +// task.setTargetName(targetName); +// taskEntity.downloadEntity.save(); +// return task; +// } +// } +//} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTaskEntity.java new file mode 100644 index 00000000..94c7cd29 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTaskEntity.java @@ -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.core.download; + +import com.arialyy.aria.core.inf.AbsTaskEntity; + +/** + * Created by AriaL on 2017/7/1. + */ +public class DownloadGroupTaskEntity extends AbsTaskEntity { + + public DownloadGroupTaskEntity(DownloadGroupEntity entity) { + this.entity = entity; + } +} 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 f72d68b2..46d87b73 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 @@ -22,7 +22,10 @@ import android.os.Handler; import android.util.Log; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.core.download.downloader.DownloadListener; +import com.arialyy.aria.core.download.downloader.DownloadUtil; +import com.arialyy.aria.core.download.downloader.IDownloadListener; +import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulers; @@ -35,12 +38,11 @@ import java.lang.ref.WeakReference; * Created by lyy on 2016/8/11. * 下载任务类 */ -public class DownloadTask extends AbsTask { +public class DownloadTask extends AbsNormalTask { public static final String TAG = "DownloadTask"; private IDownloadListener mListener; - private Handler mOutHandler; - private IDownloadUtil mUtil; + private DownloadUtil mUtil; private boolean isWait = false; private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) { @@ -98,7 +100,6 @@ public class DownloadTask extends AbsTask { * 暂停任务,并让任务处于等待状态 */ @Override public void stopAndWait() { - super.stopAndWait(); stop(true); } @@ -166,9 +167,6 @@ public class DownloadTask extends AbsTask { mContext.sendBroadcast(intent); } mUtil.cancelDownload(); - mUtil.delConfigFile(); - mUtil.delTempFile(); - mEntity.deleteData(); } } @@ -232,7 +230,6 @@ public class DownloadTask extends AbsTask { } @Override public void supportBreakpoint(boolean support) { - super.supportBreakpoint(support); if (!support) { sendInState2Target(ISchedulers.SUPPORT_BREAK_POINT); sendIntent(Aria.ACTION_SUPPORT_BREAK_POINT, -1); @@ -240,14 +237,12 @@ public class DownloadTask extends AbsTask { } @Override public void onPre() { - super.onPre(); downloadEntity.setState(IEntity.STATE_PRE); sendInState2Target(ISchedulers.PRE); sendIntent(Aria.ACTION_PRE, -1); } @Override public void onPostPre(long fileSize) { - super.onPostPre(fileSize); downloadEntity.setFileSize(fileSize); downloadEntity.setState(IEntity.STATE_POST_PRE); sendInState2Target(ISchedulers.POST_PRE); @@ -255,25 +250,20 @@ public class DownloadTask extends AbsTask { } @Override public void onResume(long resumeLocation) { - super.onResume(resumeLocation); downloadEntity.setState(IEntity.STATE_RUNNING); sendInState2Target(ISchedulers.RESUME); sendIntent(Aria.ACTION_RESUME, resumeLocation); } @Override public void onStart(long startLocation) { - super.onStart(startLocation); downloadEntity.setState(IEntity.STATE_RUNNING); sendInState2Target(ISchedulers.START); sendIntent(Aria.ACTION_START, startLocation); } @Override public void onProgress(long currentLocation) { - super.onProgress(currentLocation); if (System.currentTimeMillis() - lastTime > INTERVAL_TIME) { long speed = currentLocation - lastLen; - sendIntent.putExtra(Aria.CURRENT_LOCATION, currentLocation); - sendIntent.putExtra(Aria.CURRENT_SPEED, speed); lastTime = System.currentTimeMillis(); if (isFirst) { speed = 0; @@ -283,12 +273,15 @@ public class DownloadTask extends AbsTask { downloadEntity.setCurrentProgress(currentLocation); lastLen = currentLocation; sendInState2Target(ISchedulers.RUNNING); + + if (!isOpenBroadCast) return; + sendIntent.putExtra(Aria.CURRENT_LOCATION, currentLocation); + sendIntent.putExtra(Aria.CURRENT_SPEED, speed); context.sendBroadcast(sendIntent); } } @Override public void onStop(long stopLocation) { - super.onStop(stopLocation); downloadEntity.setState(task.isWait ? IEntity.STATE_WAIT : IEntity.STATE_STOP); handleSpeed(0); sendInState2Target(ISchedulers.STOP); @@ -296,7 +289,6 @@ public class DownloadTask extends AbsTask { } @Override public void onCancel() { - super.onCancel(); downloadEntity.setState(IEntity.STATE_CANCEL); handleSpeed(0); sendInState2Target(ISchedulers.CANCEL); @@ -305,7 +297,6 @@ public class DownloadTask extends AbsTask { } @Override public void onComplete() { - super.onComplete(); downloadEntity.setState(IEntity.STATE_COMPLETE); downloadEntity.setDownloadComplete(true); handleSpeed(0); @@ -314,7 +305,6 @@ public class DownloadTask extends AbsTask { } @Override public void onFail() { - super.onFail(); downloadEntity.setFailNum(downloadEntity.getFailNum() + 1); downloadEntity.setState(IEntity.STATE_FAIL); handleSpeed(0); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java index 75f6a17b..70439cba 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskEntity.java @@ -21,17 +21,12 @@ import com.arialyy.aria.core.inf.AbsTaskEntity; * Created by lyy on 2017/1/23. * 下载任务实体 */ -public class DownloadTaskEntity extends AbsTaskEntity { +public class DownloadTaskEntity extends AbsTaskEntity { - public DownloadEntity downloadEntity; - - public DownloadTaskEntity(){} - - public DownloadTaskEntity(DownloadEntity downloadEntity) { - this.downloadEntity = downloadEntity; + public DownloadTaskEntity() { } - @Override public DownloadEntity getEntity() { - return downloadEntity; + public DownloadTaskEntity(DownloadEntity entity) { + this.entity = entity; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskGroup.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskGroup.java deleted file mode 100644 index edb322a4..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskGroup.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.arialyy.aria.core.download; - -/** - * Created by AriaL on 2017/6/27. - */ - -public class DownloadTaskGroup { -} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ChildThreadConfigEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ChildThreadConfigEntity.java new file mode 100644 index 00000000..94b865ea --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ChildThreadConfigEntity.java @@ -0,0 +1,24 @@ +package com.arialyy.aria.core.download.downloader; + +import com.arialyy.aria.core.download.DownloadTaskEntity; +import java.io.File; + +/** + * 子线程下载信息类 + */ +final class ChildThreadConfigEntity { + //线程Id + int THREAD_ID; + //下载文件大小 + long FILE_SIZE; + //子线程启动下载位置 + long START_LOCATION; + //子线程结束下载位置 + long END_LOCATION; + //下载路径 + File TEMP_FILE; + String DOWNLOAD_URL; + String CONFIG_FILE_PATH; + DownloadTaskEntity DOWNLOAD_TASK_ENTITY; + boolean IS_SUPPORT_BREAK_POINT = true; +} \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/ConnectionHelp.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java similarity index 97% rename from Aria/src/main/java/com/arialyy/aria/core/download/ConnectionHelp.java rename to Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java index e05f0aee..028db87c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/ConnectionHelp.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/ConnectionHelp.java @@ -13,8 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.downloader; +import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.util.SSLContextUtil; import java.io.IOException; import java.net.HttpURLConnection; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java new file mode 100644 index 00000000..914f70a9 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java @@ -0,0 +1,240 @@ +/* + * 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.core.download.downloader; + +import com.arialyy.aria.core.download.DownloadEntity; +import com.arialyy.aria.core.download.DownloadGroupTaskEntity; +import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.inf.IEntity; +import com.arialyy.aria.orm.DbEntity; +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * Created by AriaL on 2017/6/30. + * 下载组工具 + */ +public class DownloadGroupUtil implements IDownloadUtil { + private static final String TAG = "DownloadGroupUtil"; + /** + * 任务组所有任务总大小 + */ + private long mTotalSize = 0; + private long mCurrentProgress = 0; + private ExecutorService mInfoPool; + private ExecutorService mExePool; + private IDownloadListener mListener; + private DownloadGroupTaskEntity mTaskEntity; + private boolean isRunning = true; + /** + * 保存所有没有下载完成的任务,key为下载地址 + */ + private Map mExeMap = new HashMap<>(); + + /** + * 下载失败的映射表,key为下载地址 + */ + private Map mFailMap = new HashMap<>(); + + /** + * 下载器映射表,key为下载地址 + */ + private Map mDownloaderMap = new HashMap<>(); + + DownloadGroupUtil(IDownloadListener listener, DownloadGroupTaskEntity taskEntity) { + mListener = listener; + mTaskEntity = taskEntity; + mInfoPool = Executors.newCachedThreadPool(); + + for (DownloadEntity entity : mTaskEntity.entity.getChild()) { + File file = new File(entity.getDownloadPath()); + if (entity.isDownloadComplete() && file.exists()) { + mTotalSize += entity.getFileSize(); + } else { + mExeMap.put(entity.getDownloadUrl(), createDownloadTask(entity)); + } + mCurrentProgress += entity.getCurrentProgress(); + } + } + + @Override public long getFileSize() { + return mTotalSize; + } + + @Override public long getCurrentLocation() { + return mCurrentProgress; + } + + @Override public boolean isDownloading() { + return isRunning; + } + + @Override public void cancelDownload() { + isRunning = false; + if (!mInfoPool.isShutdown()) { + mInfoPool.shutdown(); + } + + Set keys = mDownloaderMap.keySet(); + for (String key : keys) { + DownloadThreader db = mDownloaderMap.get(key); + if (db != null) { + db.cancelDownload(); + } + } + } + + @Override public void stopDownload() { + isRunning = false; + if (!mInfoPool.isShutdown()) { + mInfoPool.shutdown(); + } + + Set keys = mDownloaderMap.keySet(); + for (String key : keys) { + DownloadThreader db = mDownloaderMap.get(key); + if (db != null) { + db.stopDownload(); + } + } + } + + @Override public void startDownload() { + isRunning = true; + Set keys = mExeMap.keySet(); + for (String key : keys) { + DownloadTaskEntity taskEntity = mExeMap.get(key); + mInfoPool.execute(new FileInfoThread(taskEntity, new FileInfoThread.OnFileInfoCallback() { + + @Override public void onComplete(String url, int code) { + DownloadTaskEntity te = mExeMap.get(url); + if (te != null) { + mTotalSize += te.getEntity().getFileSize(); + startChildDownload(te); + } + } + + @Override public void onFail(String url, String errorMsg) { + mFailMap.put(url, mExeMap.get(url)); + } + })); + } + mListener.onPostPre(mTotalSize); + } + + @Override public void resumeDownload() { + startDownload(); + } + + /** + * 启动子任务下载器 + */ + private void startChildDownload(DownloadTaskEntity taskEntity) { + ChildDownloadListener listener = new ChildDownloadListener(taskEntity); + DownloadThreader dt = new DownloadThreader(listener, taskEntity); + mDownloaderMap.put(taskEntity.getEntity().getDownloadUrl(), dt); + mExePool.execute(dt); + } + + /** + * 创建子任务下载信息 + */ + private DownloadTaskEntity createDownloadTask(DownloadEntity entity) { + DownloadTaskEntity taskEntity = + DbEntity.findData(DownloadTaskEntity.class, "key=?", entity.getDownloadUrl()); + if (taskEntity != null) { + return taskEntity; + } + taskEntity = new DownloadTaskEntity(entity); + taskEntity.headers = mTaskEntity.headers; + taskEntity.requestEnum = mTaskEntity.requestEnum; + taskEntity.redirectUrlKey = mTaskEntity.redirectUrlKey; + taskEntity.removeFile = mTaskEntity.removeFile; + return taskEntity; + } + + /** + * 子任务事件监听 + */ + private class ChildDownloadListener extends DownloadListener { + + DownloadTaskEntity taskEntity; + DownloadEntity entity; + long lastLen = 0; //上一次发送长度 + long lastTime = 0; + long INTERVAL_TIME = 1000; //1m更新周期 + + ChildDownloadListener(DownloadTaskEntity entity) { + this.taskEntity = entity; + this.entity = taskEntity.getEntity(); + } + + @Override public void onPre() { + saveData(IEntity.STATE_PRE, -1); + } + + @Override public void onPostPre(long fileSize) { + entity.setFileSize(fileSize); + saveData(IEntity.STATE_POST_PRE, -1); + } + + @Override public void onResume(long resumeLocation) { + saveData(IEntity.STATE_POST_PRE, IEntity.STATE_RUNNING); + } + + @Override public void onStart(long startLocation) { + saveData(IEntity.STATE_POST_PRE, IEntity.STATE_RUNNING); + } + + @Override public void onProgress(long currentLocation) { + if (System.currentTimeMillis() - lastTime > INTERVAL_TIME) { + long speed = currentLocation - lastLen; + lastTime = System.currentTimeMillis(); + handleSpeed(speed); + entity.setCurrentProgress(currentLocation); + lastLen = currentLocation; + } + } + + @Override public void onStop(long stopLocation) { + saveData(IEntity.STATE_STOP, stopLocation); + } + + @Override public void onCancel() { + saveData(IEntity.STATE_CANCEL, -1); + } + + @Override public void onComplete() { + saveData(IEntity.STATE_COMPLETE, entity.getFileSize()); + } + + @Override public void onFail() { + entity.setFailNum(entity.getFailNum() + 1); + saveData(IEntity.STATE_FAIL, -1); + } + + private void saveData(int state, long location) { + entity.setState(state); + entity.setDownloadComplete(state == IEntity.STATE_COMPLETE); + entity.setCurrentProgress(location); + entity.update(); + } + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadListener.java similarity index 92% rename from Aria/src/main/java/com/arialyy/aria/core/download/DownloadListener.java rename to Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadListener.java index a2cbf237..f8d2349e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadListener.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.downloader; + /** * @author lyy */ -class DownloadListener implements IDownloadListener { +public class DownloadListener implements IDownloadListener { @Override public void onResume(long resumeLocation) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadStateConstance.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadStateConstance.java similarity index 97% rename from Aria/src/main/java/com/arialyy/aria/core/download/DownloadStateConstance.java rename to Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadStateConstance.java index 8c815ee9..7d145a1a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadStateConstance.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadStateConstance.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.downloader; /** * Created by lyy on 2017/1/18. diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadThreader.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadThreader.java new file mode 100644 index 00000000..ca70cc7c --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadThreader.java @@ -0,0 +1,346 @@ +/* + * 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.core.download.downloader; + +import android.content.Context; +import android.util.Log; +import android.util.SparseArray; +import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.download.DownloadEntity; +import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.util.BufferedRandomAccessFile; +import com.arialyy.aria.util.CommonUtil; +import java.io.File; +import java.io.IOException; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * Created by AriaL on 2017/7/1. + */ +class DownloadThreader implements Runnable, IDownloadUtil { + private final String TAG = "DownloadThreader"; + private IDownloadListener mListener; + private DownloadTaskEntity mTaskEntity; + private DownloadEntity mEntity; + private ExecutorService mFixedThreadPool; + private File mConfigFile;//下载信息配置文件 + private Context mContext; + private File mTempFile; //下载的文件 + private boolean isNewTask = true; + private int mThreadNum, mRealThreadNum; + private DownloadStateConstance mConstance; + private SparseArray mTask = new SparseArray<>(); + + DownloadThreader(IDownloadListener listener, DownloadTaskEntity taskEntity) { + mListener = listener; + mTaskEntity = taskEntity; + mEntity = mTaskEntity.getEntity(); + mContext = AriaManager.APP; + mConstance = new DownloadStateConstance(); + } + + @Override public void run() { + checkTask(); + startDownload(); + } + + @Override public long getFileSize() { + return mEntity.getFileSize(); + } + + /** + * 获取当前下载位置 + */ + @Override public long getCurrentLocation() { + return mConstance.CURRENT_LOCATION; + } + + @Override public boolean isDownloading() { + return mConstance.isDownloading; + } + + @Override public void cancelDownload() { + mConstance.isCancel = true; + mConstance.isDownloading = false; + if (mFixedThreadPool != null) { + mFixedThreadPool.shutdown(); + } + for (int i = 0; i < mThreadNum; i++) { + SingleThreadTask task = (SingleThreadTask) mTask.get(i); + if (task != null) { + task.cancel(); + } + } + CommonUtil.delDownloadTaskConfig(mTaskEntity.removeFile, mEntity); + } + + @Override public void stopDownload() { + mConstance.isStop = true; + mConstance.isDownloading = false; + if (mFixedThreadPool != null) { + mFixedThreadPool.shutdown(); + } + for (int i = 0; i < mThreadNum; i++) { + SingleThreadTask task = (SingleThreadTask) mTask.get(i); + if (task != null) { + task.stop(); + } + } + } + + @Override public void startDownload() { + mConstance.isDownloading = true; + try { + if (!mTaskEntity.isSupportBP) { + mThreadNum = 1; + handleNoSupportBreakpointDownload(); + } else { + mThreadNum = + isNewTask ? AriaManager.getInstance(mContext).getDownloadConfig().getThreadNum() + : mRealThreadNum; + mFixedThreadPool = Executors.newFixedThreadPool(mThreadNum); + handleBreakpoint(); + } + } catch (IOException e) { + failDownload("下载失败【downloadUrl:" + + mEntity.getDownloadUrl() + + "】\n【filePath:" + + mEntity.getDownloadPath() + + "】\n" + + CommonUtil.getPrintException(e)); + } + } + + @Override public void resumeDownload() { + startDownload(); + } + + /** + * 返回该下载器的 + */ + public IDownloadListener getListener() { + return mListener; + } + + /** + * 检查任务是否是新任务,新任务条件: + * 1、文件不存在 + * 2、下载记录文件不存在 + * 3、下载记录文件缺失或不匹配 + * 4、数据库记录不存在 + * 5、不支持断点,则是新任务 + */ + private void checkTask() { + if (!mTaskEntity.isSupportBP) { + isNewTask = true; + return; + } + mConfigFile = new File(mContext.getFilesDir().getPath() + + AriaManager.DOWNLOAD_TEMP_DIR + + mEntity.getFileName() + + ".properties"); + mTempFile = new File(mEntity.getDownloadPath()); + if (!mConfigFile.exists()) { //记录文件被删除,则重新下载 + isNewTask = true; + CommonUtil.createFile(mConfigFile.getPath()); + } else if (!mTempFile.exists()) { + isNewTask = true; + } else if (DbEntity.findData(DownloadEntity.class, "downloadUrl=?", mEntity.getDownloadUrl()) + == null) { + isNewTask = true; + } else { + isNewTask = checkConfigFile(); + } + } + + /** + * 检查记录文件,如果是新任务返回{@code true},否则返回{@code false} + */ + private boolean checkConfigFile() { + Properties pro = CommonUtil.loadConfig(mConfigFile); + if (pro.isEmpty()) { + return true; + } + Set keys = pro.keySet(); + int num = 0; + for (Object key : keys) { + if (String.valueOf(key).contains("_record_")) { + num++; + } + } + if (num == 0) { + return true; + } + mRealThreadNum = num; + for (int i = 0; i < mRealThreadNum; i++) { + if (pro.getProperty(mTempFile.getName() + "_record_" + i) == null) { + Object state = pro.getProperty(mTempFile.getName() + "_state_" + i); + if (state != null && Integer.parseInt(state + "") == 1) { + continue; + } + return true; + } + } + return false; + } + + /** + * 恢复记录地址 + * + * @return true 表示下载完成 + */ + private boolean resumeRecordLocation(int i, long startL, long endL) { + mConstance.CURRENT_LOCATION += endL - startL; + Log.d(TAG, "++++++++++ 线程_" + i + "_已经下载完成 ++++++++++"); + mConstance.COMPLETE_THREAD_NUM++; + mConstance.STOP_NUM++; + mConstance.CANCEL_NUM++; + if (mConstance.isComplete()) { + if (mConfigFile.exists()) { + mConfigFile.delete(); + } + mListener.onComplete(); + mConstance.isDownloading = false; + return true; + } + return false; + } + + /** + * 创建单线程任务 + */ + private void addSingleTask(int i, long startL, long endL, long fileLength) { + ChildThreadConfigEntity entity = new ChildThreadConfigEntity(); + entity.FILE_SIZE = fileLength; + entity.DOWNLOAD_URL = + mEntity.isRedirect() ? mEntity.getRedirectUrl() : mEntity.getDownloadUrl(); + entity.TEMP_FILE = mTempFile; + entity.THREAD_ID = i; + entity.START_LOCATION = startL; + entity.END_LOCATION = endL; + entity.CONFIG_FILE_PATH = mConfigFile.getPath(); + entity.IS_SUPPORT_BREAK_POINT = mTaskEntity.isSupportBP; + entity.DOWNLOAD_TASK_ENTITY = mTaskEntity; + mConstance.THREAD_NUM = mThreadNum; + SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity); + mTask.put(i, task); + } + + /** + * 启动单线程下载任务 + */ + private void startSingleTask(int[] recordL) { + if (mConstance.CURRENT_LOCATION > 0) { + mListener.onResume(mConstance.CURRENT_LOCATION); + } else { + mListener.onStart(mConstance.CURRENT_LOCATION); + } + mFixedThreadPool = Executors.newFixedThreadPool(recordL.length); + for (int l : recordL) { + if (l == -1) continue; + Runnable task = mTask.get(l); + if (task != null) { + mFixedThreadPool.execute(task); + } + } + } + + /** + * 处理断点 + */ + private void handleBreakpoint() throws IOException { + long fileLength = mEntity.getFileSize(); + Properties pro = CommonUtil.loadConfig(mConfigFile); + int blockSize = (int) (fileLength / mThreadNum); + int[] recordL = new int[mThreadNum]; + for (int i = 0; i < mThreadNum; i++) { + recordL[i] = -1; + } + int rl = 0; + if (isNewTask) { + CommonUtil.createFile(mTempFile.getPath()); + BufferedRandomAccessFile file = + new BufferedRandomAccessFile(new File(mTempFile.getPath()), "rwd", 8192); + //设置文件长度 + file.setLength(fileLength); + file.close(); + } + + for (int i = 0; i < mThreadNum; i++) { + long startL = i * blockSize, endL = (i + 1) * blockSize; + Object state = pro.getProperty(mTempFile.getName() + "_state_" + i); + if (state != null && Integer.parseInt(state + "") == 1) { //该线程已经完成 + if (resumeRecordLocation(i, startL, endL)) return; + continue; + } + //分配下载位置 + Object record = pro.getProperty(mTempFile.getName() + "_record_" + i); + //如果有记录,则恢复下载 + if (!isNewTask && record != null && Long.parseLong(record + "") >= 0) { + Long r = Long.parseLong(record + ""); + mConstance.CURRENT_LOCATION += r - startL; + Log.d(TAG, "任务【" + mEntity.getFileName() + "】线程__" + i + "__恢复下载"); + mListener.onChildResume(r); + startL = r; + recordL[rl] = i; + rl++; + } else { + recordL[rl] = i; + rl++; + } + if (i == (mThreadNum - 1)) { + //最后一个线程的结束位置即为文件的总长度 + endL = fileLength; + } + addSingleTask(i, startL, endL, fileLength); + } + startSingleTask(recordL); + } + + /** + * 处理不支持断点的下载 + */ + private void handleNoSupportBreakpointDownload() { + ChildThreadConfigEntity entity = new ChildThreadConfigEntity(); + long len = mEntity.getFileSize(); + entity.FILE_SIZE = len; + entity.DOWNLOAD_URL = + mEntity.isRedirect() ? mEntity.getRedirectUrl() : mEntity.getDownloadUrl(); + entity.TEMP_FILE = mTempFile; + entity.THREAD_ID = 0; + entity.START_LOCATION = 0; + entity.END_LOCATION = entity.FILE_SIZE; + entity.CONFIG_FILE_PATH = mConfigFile.getPath(); + entity.IS_SUPPORT_BREAK_POINT = mTaskEntity.isSupportBP; + entity.DOWNLOAD_TASK_ENTITY = mTaskEntity; + mConstance.THREAD_NUM = mThreadNum; + SingleThreadTask task = new SingleThreadTask(mConstance, mListener, entity); + mTask.put(0, task); + mFixedThreadPool.execute(task); + mListener.onPostPre(len); + mListener.onStart(0); + } + + private void failDownload(String errorMsg) { + Log.e(TAG, errorMsg); + mConstance.isDownloading = false; + mListener.onFail(); + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadUtil.java similarity index 92% rename from Aria/src/main/java/com/arialyy/aria/core/download/DownloadUtil.java rename to Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadUtil.java index 526f08ba..d2b3b8fe 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadUtil.java @@ -14,14 +14,15 @@ * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.downloader; import android.content.Context; import android.util.Log; import android.util.SparseArray; import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.download.DownloadEntity; +import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.orm.DbEntity; -import com.arialyy.aria.orm.DbUtil; import com.arialyy.aria.util.BufferedRandomAccessFile; import com.arialyy.aria.util.CommonUtil; import java.io.File; @@ -37,7 +38,7 @@ import java.util.concurrent.Executors; * Created by lyy on 2015/8/25. * 下载工具类 */ -class DownloadUtil implements IDownloadUtil, Runnable { +public class DownloadUtil implements IDownloadUtil, Runnable { private static final String TAG = "DownloadUtil"; /** * 线程数 @@ -54,7 +55,7 @@ class DownloadUtil implements IDownloadUtil, Runnable { private boolean isSupportBreakpoint = true; private Context mContext; private DownloadEntity mDownloadEntity; - private DownloadTaskEntity mDownloadTaskEntity; + private DownloadTaskEntity mTaskEntity; private ExecutorService mFixedThreadPool; private File mDownloadFile; //下载的文件 private File mConfigFile;//下载信息配置文件 @@ -62,9 +63,9 @@ class DownloadUtil implements IDownloadUtil, Runnable { private DownloadStateConstance CONSTANCE; DownloadUtil(Context context, DownloadTaskEntity entity, IDownloadListener downloadListener) { - mDownloadEntity = entity.downloadEntity; + mDownloadEntity = entity.getEntity(); mContext = context.getApplicationContext(); - mDownloadTaskEntity = entity; + mTaskEntity = entity; mListener = downloadListener; // 线程下载数改变后,新的下载才会生效 //mFixedThreadPool = Executors.newFixedThreadPool(Integer.MAX_VALUE); @@ -74,7 +75,7 @@ class DownloadUtil implements IDownloadUtil, Runnable { private void init() { mConnectTimeOut = AriaManager.getInstance(mContext).getDownloadConfig().getConnectTimeOut(); - mDownloadFile = new File(mDownloadTaskEntity.downloadEntity.getDownloadPath()); + mDownloadFile = new File(mTaskEntity.getEntity().getDownloadPath()); //读取已完成的线程数 mConfigFile = new File(mContext.getFilesDir().getPath() + AriaManager.DOWNLOAD_TEMP_DIR @@ -113,6 +114,10 @@ class DownloadUtil implements IDownloadUtil, Runnable { return mListener; } + @Override public long getFileSize() { + return mDownloadEntity.getFileSize(); + } + /** * 获取当前下载位置 */ @@ -148,6 +153,7 @@ class DownloadUtil implements IDownloadUtil, Runnable { task.cancel(); } } + CommonUtil.delDownloadTaskConfig(mTaskEntity.removeFile, mDownloadEntity); } /** @@ -170,7 +176,7 @@ class DownloadUtil implements IDownloadUtil, Runnable { /** * 删除下载记录文件 */ - @Override public void delConfigFile() { + public void delConfigFile() { if (mContext != null && mDownloadEntity != null) { File dFile = new File(mDownloadEntity.getDownloadPath()); File config = @@ -184,7 +190,7 @@ class DownloadUtil implements IDownloadUtil, Runnable { /** * 删除temp文件 */ - @Override public void delTempFile() { + public void delTempFile() { if (mContext != null && mDownloadEntity != null) { File dFile = new File(mDownloadEntity.getDownloadPath()); if (dFile.exists()) { @@ -217,7 +223,7 @@ class DownloadUtil implements IDownloadUtil, Runnable { try { URL url = new URL(mDownloadEntity.getDownloadUrl()); conn = ConnectionHelp.handleConnection(url); - conn = ConnectionHelp.setConnectParam(mDownloadTaskEntity, conn); + conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); conn.setRequestProperty("Range", "bytes=" + 0 + "-"); conn.setConnectTimeout(mConnectTimeOut); conn.connect(); @@ -237,7 +243,7 @@ class DownloadUtil implements IDownloadUtil, Runnable { } /** - * 处理状态吗 + * 处理状态码 */ private void handleConnect(HttpURLConnection conn) throws IOException { int len = conn.getContentLength(); @@ -290,19 +296,18 @@ class DownloadUtil implements IDownloadUtil, Runnable { * 处理30x跳转 */ private void handle302Turn(HttpURLConnection conn) throws IOException { - String newUrl = conn.getHeaderField(mDownloadTaskEntity.redirectUrlKey); + String newUrl = conn.getHeaderField(mTaskEntity.redirectUrlKey); Log.d(TAG, "30x跳转,新url为【" + newUrl + "】"); mDownloadEntity.setRedirect(true); mDownloadEntity.setRedirectUrl(newUrl); mDownloadEntity.update(); String cookies = conn.getHeaderField("Set-Cookie"); conn = (HttpURLConnection) new URL(newUrl).openConnection(); - conn = ConnectionHelp.setConnectParam(mDownloadTaskEntity, conn); + conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); conn.setRequestProperty("Cookie", cookies); conn.setRequestProperty("Range", "bytes=" + 0 + "-"); conn.setConnectTimeout(mConnectTimeOut); conn.connect(); - handleConnect(conn); } @@ -333,7 +338,7 @@ class DownloadUtil implements IDownloadUtil, Runnable { //分配下载位置 Object record = pro.getProperty(mDownloadFile.getName() + "_record_" + i); //如果有记录,则恢复下载 - if (!isNewTask && record != null && Long.parseLong(record + "") > 0) { + if (!isNewTask && record != null && Long.parseLong(record + "") >= 0) { Long r = Long.parseLong(record + ""); CONSTANCE.CURRENT_LOCATION += r - startL; Log.d(TAG, "任务【" + mDownloadEntity.getFileName() + "】线程__" + i + "__恢复下载"); @@ -373,7 +378,7 @@ class DownloadUtil implements IDownloadUtil, Runnable { entity.END_LOCATION = entity.FILE_SIZE; entity.CONFIG_FILE_PATH = mConfigFile.getPath(); entity.IS_SUPPORT_BREAK_POINT = isSupportBreakpoint; - entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity; + entity.DOWNLOAD_TASK_ENTITY = mTaskEntity; THREAD_NUM = 1; CONSTANCE.THREAD_NUM = THREAD_NUM; SingleThreadTask task = new SingleThreadTask(CONSTANCE, mListener, entity); @@ -473,7 +478,7 @@ class DownloadUtil implements IDownloadUtil, Runnable { entity.END_LOCATION = endL; entity.CONFIG_FILE_PATH = mConfigFile.getPath(); entity.IS_SUPPORT_BREAK_POINT = isSupportBreakpoint; - entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity; + entity.DOWNLOAD_TASK_ENTITY = mTaskEntity; CONSTANCE.THREAD_NUM = THREAD_NUM; SingleThreadTask task = new SingleThreadTask(CONSTANCE, mListener, entity); mTask.put(i, task); @@ -498,23 +503,4 @@ class DownloadUtil implements IDownloadUtil, Runnable { } } - /** - * 子线程下载信息类 - */ - final static class ChildThreadConfigEntity { - //线程Id - int THREAD_ID; - //下载文件大小 - long FILE_SIZE; - //子线程启动下载位置 - long START_LOCATION; - //子线程结束下载位置 - long END_LOCATION; - //下载路径 - File TEMP_FILE; - String DOWNLOAD_URL; - String CONFIG_FILE_PATH; - DownloadTaskEntity DOWNLOAD_TASK_ENTITY; - boolean IS_SUPPORT_BREAK_POINT = true; - } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FileInfoThread.java new file mode 100644 index 00000000..71e33f78 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FileInfoThread.java @@ -0,0 +1,161 @@ +/* + * 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.core.download.downloader; + +import android.util.Log; +import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.download.DownloadEntity; +import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.util.CommonUtil; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * 下载文件信息获取 + */ +class FileInfoThread implements Runnable { + private final String TAG = "FileInfoThread"; + private DownloadEntity mEntity; + private DownloadTaskEntity mTaskEntity; + private int mConnectTimeOut; + private OnFileInfoCallback onFileInfoListener; + + interface OnFileInfoCallback { + /** + * 处理完成 + * + * @param code 状态码 + */ + void onComplete(String url, int code); + + /** + * 请求失败 + * + * @param errorMsg 错误信息 + */ + void onFail(String url, String errorMsg); + } + + FileInfoThread(DownloadTaskEntity taskEntity) { + this(taskEntity, null); + } + + FileInfoThread(DownloadTaskEntity taskEntity, OnFileInfoCallback callback) { + this.mTaskEntity = taskEntity; + mEntity = taskEntity.getEntity(); + mConnectTimeOut = + AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getConnectTimeOut(); + onFileInfoListener = callback; + } + + @Override public void run() { + HttpURLConnection conn = null; + try { + URL url = new URL(mEntity.getDownloadUrl()); + conn = ConnectionHelp.handleConnection(url); + conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); + conn.setRequestProperty("Range", "bytes=" + 0 + "-"); + conn.setConnectTimeout(mConnectTimeOut); + conn.connect(); + handleConnect(conn); + } catch (IOException e) { + failDownload("下载失败【downloadUrl:" + + mEntity.getDownloadUrl() + + "】\n【filePath:" + + mEntity.getDownloadPath() + + "】\n" + + CommonUtil.getPrintException(e)); + } finally { + if (conn != null) { + conn.disconnect(); + } + } + } + + private void handleConnect(HttpURLConnection conn) throws IOException { + int len = conn.getContentLength(); + int code = conn.getResponseCode(); + boolean isComplete = false; + mTaskEntity.code = code; + if (code == HttpURLConnection.HTTP_PARTIAL) { + if (!checkLen(len)) return; + mEntity.setFileSize(len); + mTaskEntity.isSupportBP = true; + isComplete = true; + } else if (code == HttpURLConnection.HTTP_OK) { + if (!checkLen(len)) return; + mEntity.setFileSize(len); + mTaskEntity.isSupportBP = false; + isComplete = true; + } else if (code == HttpURLConnection.HTTP_NOT_FOUND) { + failDownload("任务【" + mEntity.getDownloadUrl() + "】下载失败,错误码:404"); + } else if (code == HttpURLConnection.HTTP_MOVED_TEMP + || code == HttpURLConnection.HTTP_MOVED_PERM + || code == HttpURLConnection.HTTP_SEE_OTHER) { + mTaskEntity.redirectUrlKey = conn.getHeaderField(mTaskEntity.redirectUrlKey); + mEntity.setRedirect(true); + mEntity.setRedirectUrl(mTaskEntity.redirectUrlKey); + handle302Turn(conn); + } else { + failDownload("任务【" + mEntity.getDownloadUrl() + "】下载失败,错误码:" + code); + } + if (isComplete) { + if (onFileInfoListener != null) { + onFileInfoListener.onComplete(mEntity.getDownloadUrl(), code); + } + mEntity.update(); + mTaskEntity.update(); + } + } + + /** + * 处理30x跳转 + */ + private void handle302Turn(HttpURLConnection conn) throws IOException { + String newUrl = conn.getHeaderField(mTaskEntity.redirectUrlKey); + Log.d(TAG, "30x跳转,新url为【" + newUrl + "】"); + String cookies = conn.getHeaderField("Set-Cookie"); + conn = (HttpURLConnection) new URL(newUrl).openConnection(); + conn = ConnectionHelp.setConnectParam(mTaskEntity, conn); + conn.setRequestProperty("Cookie", cookies); + conn.setRequestProperty("Range", "bytes=" + 0 + "-"); + conn.setConnectTimeout(mConnectTimeOut); + conn.connect(); + handleConnect(conn); + } + + /** + * 检查长度是否合法 + * + * @param len 从服务器获取的文件长度 + * @return true, 合法 + */ + private boolean checkLen(long len) { + if (len < 0) { + failDownload("任务【" + mEntity.getDownloadUrl() + "】下载失败,文件长度小于0"); + return false; + } + return true; + } + + private void failDownload(String errorMsg) { + Log.e(TAG, errorMsg); + if (onFileInfoListener != null) { + onFileInfoListener.onFail(mEntity.getDownloadUrl(), errorMsg); + } + } +} \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/IDownloadListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadListener.java similarity index 97% rename from Aria/src/main/java/com/arialyy/aria/core/download/IDownloadListener.java rename to Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadListener.java index 0e805e35..d9c06376 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/IDownloadListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadListener.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.downloader; /** * 下载监听 diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/IDownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadUtil.java similarity index 82% rename from Aria/src/main/java/com/arialyy/aria/core/download/IDownloadUtil.java rename to Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadUtil.java index 471d0048..f0265cf3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/IDownloadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.downloader; /** * Created by lyy on 2016/10/31. @@ -22,6 +22,11 @@ package com.arialyy.aria.core.download; */ interface IDownloadUtil { + /** + * 获取文件大小 + */ + public long getFileSize(); + /** * 获取当前下载位置 */ @@ -53,19 +58,4 @@ interface IDownloadUtil { * 从上次断点恢复下载 */ public void resumeDownload(); - - /** - * 删除下载记录文件 - */ - public void delConfigFile(); - - /** - * 删除temp文件 - */ - public void delTempFile(); - - /** - * 设置最大下载速度 - */ - public void setMaxSpeed(double maxSpeed); } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/SingleThreadTask.java similarity index 98% rename from Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java rename to Aria/src/main/java/com/arialyy/aria/core/download/downloader/SingleThreadTask.java index b46b8750..245d32e6 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/SingleThreadTask.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.downloader; import android.os.Build; import android.text.TextUtils; @@ -36,7 +36,7 @@ import java.util.Properties; */ final class SingleThreadTask implements Runnable { private static final String TAG = "SingleThreadTask"; - private DownloadUtil.ChildThreadConfigEntity mConfigEntity; + private ChildThreadConfigEntity mConfigEntity; private String mConfigFPath; private long mChildCurrentLocation = 0; private int mBufSize; @@ -45,7 +45,7 @@ final class SingleThreadTask implements Runnable { private long mSleepTime = 0; SingleThreadTask(DownloadStateConstance constance, IDownloadListener listener, - DownloadUtil.ChildThreadConfigEntity downloadInfo) { + ChildThreadConfigEntity downloadInfo) { AriaManager manager = AriaManager.getInstance(AriaManager.APP); CONSTANCE = constance; CONSTANCE.CONNECT_TIME_OUT = manager.getDownloadConfig().getConnectTimeOut(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java new file mode 100644 index 00000000..63806454 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java @@ -0,0 +1,136 @@ +/* + * 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.core.inf; + +import android.os.Parcel; +import android.os.Parcelable; +import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.orm.Ignore; + +/** + * Created by AriaL on 2017/6/29. + */ +public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable { + /** + * 速度 + */ + @Ignore private long speed = 0; + /** + * 单位转换后的速度 + */ + @Ignore private String convertSpeed = "0b/s"; + + /** + * 扩展字段 + */ + private String str = ""; + /** + * 文件大小 + */ + private long fileSize = 1; + private int state = STATE_WAIT; + /** + * 当前下载进度 + */ + private long currentProgress = 0; + /** + * 完成时间 + */ + private long completeTime; + + public long getSpeed() { + return speed; + } + + public void setSpeed(long speed) { + this.speed = speed; + } + + public String getConvertSpeed() { + return convertSpeed; + } + + public void setConvertSpeed(String convertSpeed) { + this.convertSpeed = convertSpeed; + } + + public String getStr() { + return str; + } + + public void setStr(String str) { + this.str = str; + } + + public long getFileSize() { + return fileSize; + } + + public void setFileSize(long fileSize) { + this.fileSize = fileSize; + } + + public int getState() { + return state; + } + + public void setState(int state) { + this.state = state; + } + + public long getCurrentProgress() { + return currentProgress; + } + + public void setCurrentProgress(long currentProgress) { + this.currentProgress = currentProgress; + } + + public long getCompleteTime() { + return completeTime; + } + + public void setCompleteTime(long completeTime) { + this.completeTime = completeTime; + } + + public AbsEntity() { + } + + @Override public int describeContents() { + return 0; + } + + @Override public void writeToParcel(Parcel dest, int flags) { + dest.writeLong(this.speed); + dest.writeString(this.convertSpeed); + dest.writeString(this.str); + dest.writeLong(this.fileSize); + dest.writeInt(this.state); + dest.writeLong(this.currentProgress); + dest.writeLong(this.completeTime); + } + + protected AbsEntity(Parcel in) { + this.speed = in.readLong(); + this.convertSpeed = in.readString(); + this.str = in.readString(); + this.fileSize = in.readLong(); + this.state = in.readInt(); + this.currentProgress = in.readLong(); + this.completeTime = in.readLong(); + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java index c50258f7..9432a0de 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java @@ -23,92 +23,18 @@ import com.arialyy.aria.orm.Ignore; /** * Created by AriaL on 2017/6/3. */ -public abstract class AbsGroupEntity extends DbEntity implements IEntity, Parcelable { +public abstract class AbsGroupEntity extends AbsEntity implements Parcelable { /** - * 速度 + * 组名 */ - @Ignore private long speed = 0; - /** - * 单位转换后的速度 - */ - @Ignore private String convertSpeed = "0b/s"; - - /** - * 扩展字段 - */ - private String str = ""; - /** - * 文件大小 - */ - private long fileSize = 1; - private int state = STATE_WAIT; - /** - * 当前下载进度 - */ - private long currentProgress = 0; - /** - * 完成时间 - */ - private long completeTime; - /** - * 文件名 - */ - private String grooupName = ""; - - public long getSpeed() { - return speed; - } - - public void setSpeed(long speed) { - this.speed = speed; - } - - public String getConvertSpeed() { - return convertSpeed; - } - - public void setConvertSpeed(String convertSpeed) { - this.convertSpeed = convertSpeed; - } - - public String getStr() { - return str; - } - - public void setStr(String str) { - this.str = str; - } - - public long getFileSize() { - return fileSize; - } - - public void setFileSize(long fileSize) { - this.fileSize = fileSize; - } - - public int getState() { - return state; - } - - public void setState(int state) { - this.state = state; - } - - public long getCurrentProgress() { - return currentProgress; - } - - public void setCurrentProgress(long currentProgress) { - this.currentProgress = currentProgress; - } + private String groupName = ""; - public long getCompleteTime() { - return completeTime; + public String getGroupName() { + return groupName; } - public void setCompleteTime(long completeTime) { - this.completeTime = completeTime; + public void setGroupName(String groupName) { + this.groupName = groupName; } public AbsGroupEntity() { @@ -119,22 +45,12 @@ public abstract class AbsGroupEntity exten } @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeLong(this.speed); - dest.writeString(this.convertSpeed); - dest.writeString(this.str); - dest.writeLong(this.fileSize); - dest.writeInt(this.state); - dest.writeLong(this.currentProgress); - dest.writeLong(this.completeTime); + super.writeToParcel(dest, flags); + dest.writeString(this.groupName); } protected AbsGroupEntity(Parcel in) { - this.speed = in.readLong(); - this.convertSpeed = in.readString(); - this.str = in.readString(); - this.fileSize = in.readLong(); - this.state = in.readInt(); - this.currentProgress = in.readLong(); - this.completeTime = in.readLong(); + super(in); + this.groupName = in.readString(); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java new file mode 100644 index 00000000..b7eb3a93 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTask.java @@ -0,0 +1,71 @@ +/* + * 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.core.inf; + +import com.arialyy.aria.util.CommonUtil; + +/** + * Created by AriaL on 2017/6/29. + */ +public abstract class AbsGroupTask + extends AbsTask { + + protected TASK_ENTITY mTaskEntity; + + @Override public int getPercent() { + return 0; + } + + @Override public long getFileSize() { + return 0; + } + + @Override public String getConvertFileSize() { + return null; + } + + @Override public long getCurrentProgress() { + return 0; + } + + @Override public String getConvertCurrentProgress() { + return null; + } + + @Override public int getState() { + return mEntity.getState(); + } + + @Override public String getExtendField() { + return mEntity.getStr(); + } + + @Override public String getKey() { + return mEntity.getGroupName(); + } + + @Override public boolean isRunning() { + return false; + } + + @Override public ENTITY getEntity() { + return mEntity; + } + + @Override public void removeRecord() { + + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java index 8411c960..91a1dae5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java @@ -23,55 +23,27 @@ import com.arialyy.aria.orm.Ignore; /** * Created by AriaL on 2017/6/3. */ -public abstract class AbsNormalEntity extends DbEntity implements IEntity, Parcelable { - /** - * 速度 - */ - @Ignore private long speed = 0; - /** - * 单位转换后的速度 - */ - @Ignore private String convertSpeed = "0b/s"; +public abstract class AbsNormalEntity extends AbsEntity implements Parcelable { /** * 下载失败计数,每次开始都重置为0 */ @Ignore private int failNum = 0; - /** - * 扩展字段 - */ - private String str = ""; - /** - * 文件大小 - */ - private long fileSize = 1; - private int state = STATE_WAIT; - /** - * 当前下载进度 - */ - private long currentProgress = 0; - /** - * 完成时间 - */ - private long completeTime; /** * 文件名 */ private String fileName = ""; - public long getSpeed() { - return speed; - } - - public void setSpeed(long speed) { - this.speed = speed; - } + /** + * 是否是任务组里面的下载实体 + */ + private boolean isGroupChild = false; - public String getConvertSpeed() { - return convertSpeed; + public boolean isGroupChild() { + return isGroupChild; } - public void setConvertSpeed(String convertSpeed) { - this.convertSpeed = convertSpeed; + public void setGroupChild(boolean groupChild) { + isGroupChild = groupChild; } public int getFailNum() { @@ -82,46 +54,6 @@ public abstract class AbsNormalEntity extends DbEntity implements IEntity, Parce this.failNum = failNum; } - public String getStr() { - return str; - } - - public void setStr(String str) { - this.str = str; - } - - public long getFileSize() { - return fileSize; - } - - public void setFileSize(long fileSize) { - this.fileSize = fileSize; - } - - public int getState() { - return state; - } - - public void setState(int state) { - this.state = state; - } - - public long getCurrentProgress() { - return currentProgress; - } - - public void setCurrentProgress(long currentProgress) { - this.currentProgress = currentProgress; - } - - public long getCompleteTime() { - return completeTime; - } - - public void setCompleteTime(long completeTime) { - this.completeTime = completeTime; - } - public String getFileName() { return fileName; } @@ -138,26 +70,16 @@ public abstract class AbsNormalEntity extends DbEntity implements IEntity, Parce } @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeLong(this.speed); - dest.writeString(this.convertSpeed); + super.writeToParcel(dest, flags); dest.writeInt(this.failNum); - dest.writeString(this.str); - dest.writeLong(this.fileSize); - dest.writeInt(this.state); - dest.writeLong(this.currentProgress); - dest.writeLong(this.completeTime); dest.writeString(this.fileName); + dest.writeByte(this.isGroupChild ? (byte) 1 : (byte) 0); } protected AbsNormalEntity(Parcel in) { - this.speed = in.readLong(); - this.convertSpeed = in.readString(); + super(in); this.failNum = in.readInt(); - this.str = in.readString(); - this.fileSize = in.readLong(); - this.state = in.readInt(); - this.currentProgress = in.readLong(); - this.completeTime = in.readLong(); this.fileName = in.readString(); + this.isGroupChild = in.readByte() != 0; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java new file mode 100644 index 00000000..a381edef --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTask.java @@ -0,0 +1,100 @@ +/* + * 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.core.inf; + +import com.arialyy.aria.util.CommonUtil; + +/** + * Created by lyy on 2017/6/3. + */ +public abstract class AbsNormalTask extends AbsTask { + + private boolean isHeighestTask = false; + + /** + * 暂停任务,并让任务处于等待状态 + */ + public void stopAndWait() { + + } + + /** + * 最高优先级命令,最高优先级命令有以下属性 + * 1、在下载队列中,有且只有一个最高优先级任务 + * 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成 + * 3、任务调度器不会暂停最高优先级任务 + * 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效 + * 5、如果下载队列中已经满了,则会停止队尾的任务 + * 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务 + */ + public void setHighestPriority(boolean isHighestPriority) { + isHeighestTask = isHighestPriority; + } + + public boolean isHighestPriorityTask() { + return isHeighestTask; + } + + /** + * 获取百分比进度 + * + * @return 返回百分比进度,如果文件长度为0,返回0 + */ + @Override public int getPercent() { + if (mEntity.getFileSize() == 0) { + return 0; + } + return (int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize()); + } + + /** + * 获取文件大小 + */ + @Override public long getFileSize() { + return mEntity.getFileSize(); + } + + /** + * 转换单位后的文件长度 + * + * @return 如果文件长度为0,则返回0m,否则返回转换后的长度1b、1kb、1mb、1gb、1tb + */ + @Override public String getConvertFileSize() { + if (mEntity.getFileSize() == 0) { + return "0mb"; + } + return CommonUtil.formatFileSize(mEntity.getFileSize()); + } + + /** + * 获取当前下载进度 + */ + @Override public long getCurrentProgress() { + return mEntity.getCurrentProgress(); + } + + /** + * 获取单位转换后的进度 + * + * @return 如:已经下载3mb的大小,则返回{@code 3mb} + */ + @Override public String getConvertCurrentProgress() { + if (mEntity.getCurrentProgress() == 0) { + return "0b"; + } + return CommonUtil.formatFileSize(mEntity.getCurrentProgress()); + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java index 3be9ea52..02a476bd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java @@ -16,26 +16,21 @@ package com.arialyy.aria.core.inf; import android.content.Context; -import com.arialyy.aria.util.CommonUtil; +import android.os.Handler; /** - * Created by lyy on 2017/6/3. + * Created by AriaL on 2017/6/29. */ -public abstract class AbsTask - implements ITask { +public abstract class AbsTask implements ITask { protected ENTITY mEntity; + protected Handler mOutHandler; /** * 用于生成该任务对象的hash码 */ private String mTargetName; protected Context mContext; - private boolean isHeighestTask = false; - - @Override public void stopAndWait() { - - } /** * 任务当前状态 @@ -46,6 +41,15 @@ public abstract class AbsTask @@ -88,73 +92,6 @@ public abstract class AbsTask extends DbEntity { + + public ENTITY entity; + + /** + * Task实体对应的key + */ + public String key; -public abstract class AbsTaskEntity { /** * http 请求头 */ @@ -44,5 +52,17 @@ public abstract class AbsTaskEntity { */ public boolean removeFile = false; - public abstract AbsNormalEntity getEntity(); + /** + * 是否支持断点, {@code true} 为支持断点 + */ + public boolean isSupportBP = true; + + /** + * 状态码 + */ + public int code; + + public ENTITY getEntity() { + return entity; + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java index 5535ad92..b5caee25 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java @@ -18,29 +18,17 @@ package com.arialyy.aria.core.inf; /** * Created by lyy on 2017/2/13. */ - -public interface ITask { - - /** - * 获取 - */ +public interface ITask { /** - * 暂停任务,并让任务处于等待状态 + * 获取下载状态 */ - public void stopAndWait(); + int getState(); /** - * 设置任务为最高优先级任务,在下载队列中,有且只有一个最高优先级任务 - */ - public void setHighestPriority(boolean isHighestPriority); - - /** - * 该任务是否是最高优先级任务 - * - * @return {@code true} 任务为最高优先级任务 + * 获取扩展字段 */ - public boolean isHighestPriorityTask(); + String getExtendField(); /** * 唯一标识符,DownloadTask 为下载地址,UploadTask 为文件路径 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 c2b1d239..fa307650 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 @@ -19,21 +19,21 @@ package com.arialyy.aria.core.queue; import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.inf.AbsNormalEntity; -import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.AbsTaskEntity; -import com.arialyy.aria.core.queue.pool.CachePool; -import com.arialyy.aria.core.queue.pool.ExecutePool; +import com.arialyy.aria.core.queue.pool.NormalCachePool; +import com.arialyy.aria.core.queue.pool.NormalExecutePool; import java.util.Set; /** * Created by lyy on 2017/2/23. * 任务队列 */ -abstract class AbsTaskQueue +abstract class AbsTaskQueue implements ITaskQueue { private final String TAG = "AbsTaskQueue"; - CachePool mCachePool = new CachePool<>(); - ExecutePool mExecutePool; + NormalCachePool mCachePool = new NormalCachePool<>(); + NormalExecutePool mExecutePool; @Override public boolean taskIsRunning(String key) { return mExecutePool.getTask(key) != null; @@ -73,14 +73,14 @@ abstract class AbsTaskQueue(true); + mExecutePool = new NormalExecutePool<>(true); } @Override public void setTaskHighestPriority(DownloadTask task) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java index b628a1d3..4ce69d80 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java @@ -19,9 +19,8 @@ package com.arialyy.aria.core.queue; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTask; -import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadTask; @@ -31,7 +30,7 @@ import com.arialyy.aria.core.upload.UploadTaskEntity; * Created by lyy on 2016/8/16. * 任务功能接口 */ -public interface ITaskQueue { +public interface ITaskQueue { /** * 通过key判断任务是否正在执行 diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java index 2b56ac84..3e0eb262 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/UploadTaskQueue.java @@ -19,7 +19,7 @@ package com.arialyy.aria.core.queue; import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.queue.pool.ExecutePool; +import com.arialyy.aria.core.queue.pool.NormalExecutePool; import com.arialyy.aria.core.scheduler.UploadSchedulers; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadTask; @@ -43,7 +43,7 @@ public class UploadTaskQueue extends AbsTaskQueue(false); + mExecutePool = new NormalExecutePool<>(false); } @Override public void setMaxTaskNum(int newMaxNum) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/GroupCachePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/GroupCachePool.java new file mode 100644 index 00000000..3e256198 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/GroupCachePool.java @@ -0,0 +1,23 @@ +/* + * 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.core.queue.pool; + +/** + * Created by AriaL on 2017/6/29. + * 任务组缓冲池 + */ +public class GroupCachePool { +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/GroupExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/GroupExecutePool.java new file mode 100644 index 00000000..188b84d4 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/GroupExecutePool.java @@ -0,0 +1,23 @@ +/* + * 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.core.queue.pool; + +/** + * Created by AriaL on 2017/6/29. + */ + +public class GroupExecutePool { +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/NormalCachePool.java similarity index 96% rename from Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java rename to Aria/src/main/java/com/arialyy/aria/core/queue/pool/NormalCachePool.java index 964137a4..9f4d54ab 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/NormalCachePool.java @@ -32,14 +32,14 @@ import java.util.concurrent.TimeUnit; * Created by lyy on 2016/8/14. * 任务缓存池,所有下载任务最先缓存在这个池中 */ -public class CachePool implements IPool { - private static final String TAG = "CachePool"; +public class NormalCachePool implements IPool { + private static final String TAG = "NormalCachePool"; private static final int MAX_NUM = Integer.MAX_VALUE; //最大下载任务数 private static final long TIME_OUT = 1000; private Map mCacheMap; private LinkedBlockingQueue mCacheQueue; - public CachePool() { + public NormalCachePool() { mCacheQueue = new LinkedBlockingQueue<>(MAX_NUM); mCacheMap = new HashMap<>(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/NormalExecutePool.java similarity index 96% rename from Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java rename to Aria/src/main/java/com/arialyy/aria/core/queue/pool/NormalExecutePool.java index 6892d208..756d40cf 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/NormalExecutePool.java @@ -31,14 +31,14 @@ import java.util.concurrent.TimeUnit; * Created by lyy on 2016/8/15. * 任务执行池,所有当前下载任务都该任务池中,默认下载大小为2 */ -public class ExecutePool implements IPool { - private static final String TAG = "ExecutePool"; +public class NormalExecutePool implements IPool { + private static final String TAG = "NormalExecutePool"; private static final long TIME_OUT = 1000; private ArrayBlockingQueue mExecuteQueue; private Map mExecuteMap; private int mSize; - public ExecutePool(boolean isDownload) { + public NormalExecutePool(boolean isDownload) { if (isDownload) { mSize = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum(); } else { 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 4931e673..8e097f48 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 @@ -21,7 +21,7 @@ import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.inf.AbsNormalEntity; -import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.queue.ITaskQueue; @@ -34,7 +34,7 @@ import java.util.concurrent.ConcurrentHashMap; /** * Created by lyy on 2017/6/4. */ -public abstract class AbsSchedulers, QUEUE extends ITaskQueue> +public abstract class AbsSchedulers, QUEUE extends ITaskQueue> implements ISchedulers { private static final String TAG = "AbsSchedulers"; 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 ba799ca0..88c30140 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 @@ -22,7 +22,7 @@ import android.util.Log; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.inf.AbsTask; +import com.arialyy.aria.core.inf.AbsNormalTask; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulers; @@ -33,9 +33,8 @@ import java.lang.ref.WeakReference; * Created by lyy on 2017/2/23. * 上传任务 */ -public class UploadTask extends AbsTask { +public class UploadTask extends AbsNormalTask { private static final String TAG = "UploadTask"; - private Handler mOutHandler; private UploadUtil mUtil; private UListener mListener;