..
This commit is contained in:
@ -338,7 +338,7 @@ class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
* 处理不支持断点的下载
|
||||
*/
|
||||
private void handleNoSupportBreakpointDownload(HttpURLConnection conn) {
|
||||
ConfigEntity entity = new ConfigEntity();
|
||||
ChildThreadConfigEntity entity = new ChildThreadConfigEntity();
|
||||
long len = conn.getContentLength();
|
||||
entity.FILE_SIZE = len;
|
||||
entity.DOWNLOAD_URL = mDownloadEntity.isRedirect() ? mDownloadEntity.getRedirectUrl()
|
||||
@ -348,7 +348,7 @@ class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
entity.START_LOCATION = 0;
|
||||
entity.END_LOCATION = entity.FILE_SIZE;
|
||||
entity.CONFIG_FILE_PATH = mConfigFile.getPath();
|
||||
entity.isSupportBreakpoint = isSupportBreakpoint;
|
||||
entity.IS_SUPPORT_BREAK_POINT = isSupportBreakpoint;
|
||||
entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity;
|
||||
THREAD_NUM = 1;
|
||||
CONSTANCE.THREAD_NUM = THREAD_NUM;
|
||||
@ -439,7 +439,7 @@ class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
* 创建单线程任务
|
||||
*/
|
||||
private void addSingleTask(int i, long startL, long endL, long fileLength) {
|
||||
ConfigEntity entity = new ConfigEntity();
|
||||
ChildThreadConfigEntity entity = new ChildThreadConfigEntity();
|
||||
entity.FILE_SIZE = fileLength;
|
||||
entity.DOWNLOAD_URL = mDownloadEntity.isRedirect() ? mDownloadEntity.getRedirectUrl()
|
||||
: mDownloadEntity.getDownloadUrl();
|
||||
@ -448,7 +448,7 @@ class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
entity.START_LOCATION = startL;
|
||||
entity.END_LOCATION = endL;
|
||||
entity.CONFIG_FILE_PATH = mConfigFile.getPath();
|
||||
entity.isSupportBreakpoint = isSupportBreakpoint;
|
||||
entity.IS_SUPPORT_BREAK_POINT = isSupportBreakpoint;
|
||||
entity.DOWNLOAD_TASK_ENTITY = mDownloadTaskEntity;
|
||||
CONSTANCE.THREAD_NUM = THREAD_NUM;
|
||||
SingleThreadTask task = new SingleThreadTask(CONSTANCE, mListener, entity);
|
||||
@ -477,16 +477,20 @@ class DownloadUtil implements IDownloadUtil, Runnable {
|
||||
/**
|
||||
* 子线程下载信息类
|
||||
*/
|
||||
final static class ConfigEntity {
|
||||
//文件大小
|
||||
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 isSupportBreakpoint = true;
|
||||
boolean IS_SUPPORT_BREAK_POINT = true;
|
||||
}
|
||||
}
|
@ -28,9 +28,7 @@ import java.math.BigDecimal;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2017/1/18.
|
||||
@ -38,7 +36,7 @@ import java.util.Set;
|
||||
*/
|
||||
final class SingleThreadTask implements Runnable {
|
||||
private static final String TAG = "SingleThreadTask";
|
||||
private DownloadUtil.ConfigEntity mConfigEntity;
|
||||
private DownloadUtil.ChildThreadConfigEntity mConfigEntity;
|
||||
private String mConfigFPath;
|
||||
private long mChildCurrentLocation = 0;
|
||||
private int mBufSize;
|
||||
@ -47,14 +45,14 @@ final class SingleThreadTask implements Runnable {
|
||||
private long mSleepTime = 0;
|
||||
|
||||
SingleThreadTask(DownloadStateConstance constance, IDownloadListener listener,
|
||||
DownloadUtil.ConfigEntity downloadInfo) {
|
||||
DownloadUtil.ChildThreadConfigEntity downloadInfo) {
|
||||
AriaManager manager = AriaManager.getInstance(AriaManager.APP);
|
||||
CONSTANCE = constance;
|
||||
CONSTANCE.CONNECT_TIME_OUT = manager.getDownloadConfig().getConnectTimeOut();
|
||||
CONSTANCE.READ_TIME_OUT = manager.getDownloadConfig().getIOTimeOut();
|
||||
mListener = listener;
|
||||
this.mConfigEntity = downloadInfo;
|
||||
if (mConfigEntity.isSupportBreakpoint) {
|
||||
if (mConfigEntity.IS_SUPPORT_BREAK_POINT) {
|
||||
mConfigFPath = downloadInfo.CONFIG_FILE_PATH;
|
||||
}
|
||||
mBufSize = manager.getDownloadConfig().getBuffSize();
|
||||
@ -82,7 +80,7 @@ final class SingleThreadTask implements Runnable {
|
||||
try {
|
||||
URL url = new URL(mConfigEntity.DOWNLOAD_URL);
|
||||
conn = ConnectionHelp.handleConnection(url);
|
||||
if (mConfigEntity.isSupportBreakpoint) {
|
||||
if (mConfigEntity.IS_SUPPORT_BREAK_POINT) {
|
||||
Log.d(TAG, "任务【"
|
||||
+ mConfigEntity.TEMP_FILE.getName()
|
||||
+ "】线程__"
|
||||
@ -129,7 +127,7 @@ final class SingleThreadTask implements Runnable {
|
||||
return;
|
||||
}
|
||||
//支持断点的处理
|
||||
if (mConfigEntity.isSupportBreakpoint) {
|
||||
if (mConfigEntity.IS_SUPPORT_BREAK_POINT) {
|
||||
Log.i(TAG, "任务【"
|
||||
+ mConfigEntity.TEMP_FILE.getName()
|
||||
+ "】线程__"
|
||||
@ -180,7 +178,7 @@ final class SingleThreadTask implements Runnable {
|
||||
protected void stop() {
|
||||
synchronized (AriaManager.LOCK) {
|
||||
try {
|
||||
if (mConfigEntity.isSupportBreakpoint) {
|
||||
if (mConfigEntity.IS_SUPPORT_BREAK_POINT) {
|
||||
CONSTANCE.STOP_NUM++;
|
||||
Log.d(TAG, "任务【"
|
||||
+ mConfigEntity.TEMP_FILE.getName()
|
||||
@ -221,7 +219,7 @@ final class SingleThreadTask implements Runnable {
|
||||
*/
|
||||
protected void cancel() {
|
||||
synchronized (AriaManager.LOCK) {
|
||||
if (mConfigEntity.isSupportBreakpoint) {
|
||||
if (mConfigEntity.IS_SUPPORT_BREAK_POINT) {
|
||||
CONSTANCE.CANCEL_NUM++;
|
||||
Log.d(TAG, "任务【"
|
||||
+ mConfigEntity.TEMP_FILE.getName()
|
||||
@ -260,7 +258,7 @@ final class SingleThreadTask implements Runnable {
|
||||
if (ex != null) {
|
||||
Log.e(TAG, msg + "\n" + CommonUtil.getPrintException(ex));
|
||||
}
|
||||
if (mConfigEntity.isSupportBreakpoint) {
|
||||
if (mConfigEntity.IS_SUPPORT_BREAK_POINT) {
|
||||
writeConfig(false, currentLocation);
|
||||
if (CONSTANCE.isFail()) {
|
||||
Log.e(TAG, "任务【" + mConfigEntity.TEMP_FILE.getName() + "】下载失败");
|
||||
|
Reference in New Issue
Block a user