修复分块文件长度错误的bug
This commit is contained in:
@@ -391,16 +391,20 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
"startLocation = %s; endLocation = %s; block = %s; tempLen = %s; i = %s",
|
"startLocation = %s; endLocation = %s; block = %s; tempLen = %s; i = %s",
|
||||||
tr.startLocation, tr.endLocation, blockLen, temp.length(), i));
|
tr.startLocation, tr.endLocation, blockLen, temp.length(), i));
|
||||||
if (tr.endLocation == realLocation) {
|
if (tr.endLocation == realLocation) {
|
||||||
ALog.d(TAG, String.format("分块【%s】已完成,更新记录", temp.getPath()));
|
ALog.i(TAG, String.format("分块【%s】已完成,更新记录", temp.getPath()));
|
||||||
tr.startLocation = realLocation;
|
tr.startLocation = realLocation;
|
||||||
tr.isComplete = true;
|
tr.isComplete = true;
|
||||||
mCompleteThreadNum++;
|
mCompleteThreadNum++;
|
||||||
} else {
|
} else {
|
||||||
tr.isComplete = false;
|
tr.isComplete = false;
|
||||||
if (realLocation != tr.startLocation) {
|
if (realLocation == tr.startLocation) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (realLocation > tr.startLocation) {
|
||||||
ALog.i(TAG, String.format("修正分块【%s】的进度记录为:%s", temp.getPath(), realLocation));
|
ALog.i(TAG, String.format("修正分块【%s】的进度记录为:%s", temp.getPath(), realLocation));
|
||||||
tr.startLocation = realLocation;
|
tr.startLocation = realLocation;
|
||||||
} else if (realLocation > tr.endLocation) {
|
} else {
|
||||||
ALog.i(TAG, String.format("分块【%s】错误,将重新开始该分块", temp.getPath()));
|
ALog.i(TAG, String.format("分块【%s】错误,将重新开始该分块", temp.getPath()));
|
||||||
temp.delete();
|
temp.delete();
|
||||||
tr.startLocation = i * blockLen;
|
tr.startLocation = i * blockLen;
|
||||||
@@ -415,7 +419,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* convertDb 为兼容性代码
|
* convertDb 是兼容性代码
|
||||||
* 从3.4.1开始,线程配置信息将存储在数据库中。
|
* 从3.4.1开始,线程配置信息将存储在数据库中。
|
||||||
* 将配置文件的内容复制到数据库中,并将配置文件删除
|
* 将配置文件的内容复制到数据库中,并将配置文件删除
|
||||||
*/
|
*/
|
||||||
@@ -548,13 +552,9 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
private void handleBreakpoint() {
|
private void handleBreakpoint() {
|
||||||
long fileLength = mEntity.getFileSize();
|
long fileLength = mEntity.getFileSize();
|
||||||
long blockSize = fileLength / mTotalThreadNum;
|
long blockSize = fileLength / mTotalThreadNum;
|
||||||
int[] threadId = new int[mTotalThreadNum];
|
Set<Integer> threads = new HashSet<>();
|
||||||
int rl = 0;
|
|
||||||
|
|
||||||
mRecord.fileLength = fileLength;
|
mRecord.fileLength = fileLength;
|
||||||
for (int i = 0; i < mTotalThreadNum; i++) {
|
|
||||||
threadId[i] = -1;
|
|
||||||
}
|
|
||||||
if (mTaskEntity.isNewTask() && !handleNewTask()) {
|
if (mTaskEntity.isNewTask() && !handleNewTask()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -572,7 +572,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tr.blockLen == 0) {
|
if (tr.blockLen == 0) {
|
||||||
tr.blockLen = i == mTotalThreadNum - 1 ? (fileLength - i * blockSize) : blockSize;
|
tr.blockLen = CommonUtil.getBlockLen(fileLength, i, mTotalThreadNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tr.isComplete) {//该线程已经完成
|
if (tr.isComplete) {//该线程已经完成
|
||||||
@@ -605,8 +605,7 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
AbsThreadTask task = createSingThreadTask(i, startL, endL, fileLength, tr);
|
AbsThreadTask task = createSingThreadTask(i, startL, endL, fileLength, tr);
|
||||||
if (task == null) return;
|
if (task == null) return;
|
||||||
mTask.put(i, task);
|
mTask.put(i, task);
|
||||||
threadId[rl] = i;
|
threads.add(i);
|
||||||
rl++;
|
|
||||||
}
|
}
|
||||||
if (mConstance.CURRENT_LOCATION != 0
|
if (mConstance.CURRENT_LOCATION != 0
|
||||||
&& mConstance.CURRENT_LOCATION != mEntity.getCurrentProgress()) {
|
&& mConstance.CURRENT_LOCATION != mEntity.getCurrentProgress()) {
|
||||||
@@ -614,13 +613,13 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte
|
|||||||
mEntity.setCurrentProgress(mConstance.CURRENT_LOCATION);
|
mEntity.setCurrentProgress(mConstance.CURRENT_LOCATION);
|
||||||
}
|
}
|
||||||
saveRecord();
|
saveRecord();
|
||||||
startThreadTask(threadId);
|
startThreadTask(threads);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动单线程任务
|
* 启动单线程任务
|
||||||
*/
|
*/
|
||||||
private void startThreadTask(int[] recordL) {
|
private void startThreadTask(Set<Integer> recordL) {
|
||||||
if (isBreak()) {
|
if (isBreak()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
|||||||
|
|
||||||
private final String TAG = "AbsThreadTask";
|
private final String TAG = "AbsThreadTask";
|
||||||
/**
|
/**
|
||||||
* 当前子线程的下载位置
|
* 当前子线程相对于总长度的位置
|
||||||
*/
|
*/
|
||||||
protected long mChildCurrentLocation = 0;
|
protected long mChildCurrentLocation = 0;
|
||||||
protected int mBufSize;
|
protected int mBufSize;
|
||||||
@@ -236,23 +236,59 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
|||||||
f.delete();
|
f.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File targetFile = new File(STATE.TASK_RECORD.filePath);
|
||||||
|
if (targetFile.exists() && targetFile.length() > mEntity.getFileSize()) {
|
||||||
|
ALog.e(TAG, String.format("任务【%s】分块文件合并失败,下载长度超出文件真实长度,downloadLen: %s,fileSize: %s",
|
||||||
|
mConfig.TEMP_FILE.getName(), targetFile.length(), mEntity.getFileSize()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查下载完成的分块大小,如果下载完成的分块大小大于或小于分配的大小,则需要重新下载该分块
|
||||||
|
* 如果是非分块任务,直接返回{@code true}
|
||||||
|
*
|
||||||
|
* @return {@code true} 分块分大小正常,{@code false} 分块大小错误
|
||||||
|
*/
|
||||||
|
protected boolean checkBlock() {
|
||||||
|
if (!getTaskRecord().isBlock) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ThreadRecord tr = getThreadRecord();
|
||||||
|
File blockFile = getBockFile();
|
||||||
|
if (!blockFile.exists() || blockFile.length() != tr.blockLen) {
|
||||||
|
ALog.i(TAG, String.format("分块【%s】下载错误,即将重新下载该分块,开始位置:%s,结束位置:%s", blockFile.getName(),
|
||||||
|
tr.startLocation, tr.endLocation));
|
||||||
|
retryThis(isBreak());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 停止任务
|
* 停止任务
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
synchronized (AriaManager.LOCK) {
|
synchronized (AriaManager.LOCK) {
|
||||||
if (mConfig.SUPPORT_BP) {
|
if (mConfig.SUPPORT_BP) {
|
||||||
final long currentTemp = mChildCurrentLocation;
|
final long stopLocation;
|
||||||
|
if (getTaskRecord().isBlock) {
|
||||||
|
File blockFile = getBockFile();
|
||||||
|
ThreadRecord tr = getThreadRecord();
|
||||||
|
long block = mEntity.getFileSize() / getTaskRecord().threadRecords.size();
|
||||||
|
stopLocation =
|
||||||
|
blockFile.exists() ? (tr.threadId * block + blockFile.length()) : tr.threadId * block;
|
||||||
|
} else {
|
||||||
|
stopLocation = mChildCurrentLocation;
|
||||||
|
}
|
||||||
STATE.STOP_NUM++;
|
STATE.STOP_NUM++;
|
||||||
ALog.d(TAG, String.format("任务【%s】thread__%s__停止【停止位置:%s】", mConfig.TEMP_FILE.getName(),
|
ALog.d(TAG, String.format("任务【%s】thread__%s__停止【当前线程停止位置:%s】", mConfig.TEMP_FILE.getName(),
|
||||||
mConfig.THREAD_ID, currentTemp));
|
mConfig.THREAD_ID, stopLocation));
|
||||||
writeConfig(false, currentTemp);
|
writeConfig(false, stopLocation);
|
||||||
if (STATE.isStop()) {
|
if (STATE.isStop()) {
|
||||||
ALog.i(TAG, String.format("任务【%s】已停止", mConfig.TEMP_FILE.getName()));
|
ALog.i(TAG, String.format("任务【%s】已停止", mConfig.TEMP_FILE.getName()));
|
||||||
STATE.isRunning = false;
|
STATE.isRunning = false;
|
||||||
@@ -273,7 +309,8 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
|||||||
synchronized (AriaManager.LOCK) {
|
synchronized (AriaManager.LOCK) {
|
||||||
if (STATE.CURRENT_LOCATION > mEntity.getFileSize()) {
|
if (STATE.CURRENT_LOCATION > mEntity.getFileSize()) {
|
||||||
String errorMsg =
|
String errorMsg =
|
||||||
String.format("下载失败,下载长度超出文件大;currentLocation=%s, fileSize=%s", STATE.CURRENT_LOCATION,
|
String.format("下载失败,下载长度超出文件真实长度;currentLocation=%s, fileSize=%s",
|
||||||
|
STATE.CURRENT_LOCATION,
|
||||||
mEntity.getFileSize());
|
mEntity.getFileSize());
|
||||||
taskBreak = true;
|
taskBreak = true;
|
||||||
fail(mChildCurrentLocation, new FileException(TAG, errorMsg), false);
|
fail(mChildCurrentLocation, new FileException(TAG, errorMsg), false);
|
||||||
@@ -376,31 +413,42 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
|||||||
if (getTaskRecord().isBlock) {
|
if (getTaskRecord().isBlock) {
|
||||||
ThreadRecord tr = getThreadRecord();
|
ThreadRecord tr = getThreadRecord();
|
||||||
long block = mEntity.getFileSize() / getTaskRecord().threadRecords.size();
|
long block = mEntity.getFileSize() / getTaskRecord().threadRecords.size();
|
||||||
File file = mConfig.TEMP_FILE;
|
|
||||||
if (file.length() > tr.endLocation) {
|
File blockFile = getBockFile();
|
||||||
ALog.i(TAG, String.format("分块【%s】错误,将重新下载该分块", file.getPath()));
|
if (blockFile.length() > tr.blockLen) {
|
||||||
boolean b = file.delete();
|
ALog.i(TAG, String.format("分块【%s】错误,将重新下载该分块", blockFile.getPath()));
|
||||||
ALog.w(TAG, "删除:" + b);
|
blockFile.delete();
|
||||||
tr.startLocation = block * tr.threadId;
|
tr.startLocation = block * tr.threadId;
|
||||||
tr.isComplete = false;
|
tr.isComplete = false;
|
||||||
mConfig.START_LOCATION = tr.startLocation;
|
mConfig.START_LOCATION = tr.startLocation;
|
||||||
} else if (file.length() == tr.endLocation) {
|
} else if (blockFile.length() < tr.blockLen) {
|
||||||
|
tr.startLocation = block * tr.threadId + blockFile.length();
|
||||||
|
tr.isComplete = false;
|
||||||
|
mConfig.START_LOCATION = tr.startLocation;
|
||||||
|
STATE.CURRENT_LOCATION = getBlockRealTotalSize();
|
||||||
|
ALog.i(TAG, String.format("修正分块【%s】,开始位置:%s,当前进度:%s", blockFile.getPath(), tr.startLocation,
|
||||||
|
STATE.CURRENT_LOCATION));
|
||||||
|
} else {
|
||||||
STATE.COMPLETE_THREAD_NUM++;
|
STATE.COMPLETE_THREAD_NUM++;
|
||||||
tr.isComplete = true;
|
tr.isComplete = true;
|
||||||
} else {
|
|
||||||
tr.startLocation = block * tr.threadId + file.length();
|
|
||||||
mConfig.START_LOCATION = tr.startLocation;
|
|
||||||
tr.isComplete = false;
|
|
||||||
STATE.CURRENT_LOCATION = getBlockRealTotalSize();
|
|
||||||
ALog.i(TAG, String.format("修正分块【%s】进度,开始位置:%s,当前进度:%s", file.getPath(), tr.startLocation,
|
|
||||||
STATE.CURRENT_LOCATION));
|
|
||||||
}
|
}
|
||||||
|
tr.update();
|
||||||
} else {
|
} else {
|
||||||
mConfig.START_LOCATION = mChildCurrentLocation == 0 ? mConfig.START_LOCATION
|
mConfig.START_LOCATION = mChildCurrentLocation == 0 ? mConfig.START_LOCATION
|
||||||
: mConfig.THREAD_RECORD.startLocation;
|
: mConfig.THREAD_RECORD.startLocation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取分块文件
|
||||||
|
*
|
||||||
|
* @return 分块文件
|
||||||
|
*/
|
||||||
|
private File getBockFile() {
|
||||||
|
return new File(String.format(AbsFileer.SUB_PATH, STATE.TASK_RECORD.filePath,
|
||||||
|
getThreadRecord().threadId));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取分块任务真实的进度
|
* 获取分块任务真实的进度
|
||||||
*
|
*
|
||||||
@@ -448,7 +496,9 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
|||||||
ThreadRecord tr = getThreadRecord();
|
ThreadRecord tr = getThreadRecord();
|
||||||
if (tr != null) {
|
if (tr != null) {
|
||||||
tr.isComplete = isComplete;
|
tr.isComplete = isComplete;
|
||||||
if (getTaskRecord().isBlock || getTaskRecord().isOpenDynamicFile) {
|
if (getTaskRecord().isBlock) {
|
||||||
|
tr.startLocation = record;
|
||||||
|
} else if (getTaskRecord().isOpenDynamicFile) {
|
||||||
tr.startLocation = mConfig.TEMP_FILE.length();
|
tr.startLocation = mConfig.TEMP_FILE.length();
|
||||||
} else {
|
} else {
|
||||||
if (0 < record && record < mConfig.END_LOCATION) {
|
if (0 < record && record < mConfig.END_LOCATION) {
|
||||||
|
|||||||
@@ -133,6 +133,9 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
|
|||||||
if (isBreak()) {
|
if (isBreak()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!checkBlock()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ALog.i(TAG,
|
ALog.i(TAG,
|
||||||
String.format("任务【%s】线程__%s__下载完毕", mConfig.TEMP_FILE.getName(), mConfig.THREAD_ID));
|
String.format("任务【%s】线程__%s__下载完毕", mConfig.TEMP_FILE.getName(), mConfig.THREAD_ID));
|
||||||
writeConfig(true, mConfig.END_LOCATION);
|
writeConfig(true, mConfig.END_LOCATION);
|
||||||
|
|||||||
@@ -247,6 +247,9 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
|||||||
if (isBreak()) {
|
if (isBreak()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!checkBlock()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mChildCurrentLocation == mConfig.END_LOCATION) {
|
if (mChildCurrentLocation == mConfig.END_LOCATION) {
|
||||||
//支持断点的处理
|
//支持断点的处理
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import com.arialyy.aria.core.inf.IEntity;
|
|||||||
import com.arialyy.aria.core.inf.TaskSchedulerType;
|
import com.arialyy.aria.core.inf.TaskSchedulerType;
|
||||||
import com.arialyy.aria.core.queue.pool.BaseCachePool;
|
import com.arialyy.aria.core.queue.pool.BaseCachePool;
|
||||||
import com.arialyy.aria.core.queue.pool.BaseExecutePool;
|
import com.arialyy.aria.core.queue.pool.BaseExecutePool;
|
||||||
|
import com.arialyy.aria.core.queue.pool.DownloadSharePool;
|
||||||
|
import com.arialyy.aria.core.queue.pool.UploadSharePool;
|
||||||
import com.arialyy.aria.util.ALog;
|
import com.arialyy.aria.util.ALog;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -32,18 +34,29 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity>
|
abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity>
|
||||||
implements ITaskQueue<TASK, TASK_ENTITY> {
|
implements ITaskQueue<TASK, TASK_ENTITY> {
|
||||||
|
protected final int TYPE_D_QUEUE = 1;
|
||||||
|
protected final int TYPE_DG_QUEUE = 2;
|
||||||
|
protected final int TYPE_U_QUEUE = 3;
|
||||||
|
|
||||||
private final String TAG = "AbsTaskQueue";
|
private final String TAG = "AbsTaskQueue";
|
||||||
BaseCachePool<TASK> mCachePool;
|
BaseCachePool<TASK> mCachePool;
|
||||||
BaseExecutePool<TASK> mExecutePool;
|
BaseExecutePool<TASK> mExecutePool;
|
||||||
|
|
||||||
AbsTaskQueue() {
|
AbsTaskQueue() {
|
||||||
mCachePool = setCachePool();
|
switch (getQueueType()) {
|
||||||
mExecutePool = setExecutePool();
|
case TYPE_D_QUEUE:
|
||||||
|
case TYPE_DG_QUEUE:
|
||||||
|
mCachePool = DownloadSharePool.getInstance().cachePool;
|
||||||
|
mExecutePool = DownloadSharePool.getInstance().executePool;
|
||||||
|
break;
|
||||||
|
case TYPE_U_QUEUE:
|
||||||
|
mCachePool = UploadSharePool.getInstance().cachePool;
|
||||||
|
mExecutePool = UploadSharePool.getInstance().executePool;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract BaseCachePool<TASK> setCachePool();
|
abstract int getQueueType();
|
||||||
|
|
||||||
abstract BaseExecutePool<TASK> setExecutePool();
|
|
||||||
|
|
||||||
@Override public boolean taskIsRunning(String key) {
|
@Override public boolean taskIsRunning(String key) {
|
||||||
return mExecutePool.getTask(key) != null;
|
return mExecutePool.getTask(key) != null;
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ package com.arialyy.aria.core.queue;
|
|||||||
import com.arialyy.aria.core.AriaManager;
|
import com.arialyy.aria.core.AriaManager;
|
||||||
import com.arialyy.aria.core.download.DownloadGroupTask;
|
import com.arialyy.aria.core.download.DownloadGroupTask;
|
||||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||||
import com.arialyy.aria.core.queue.pool.BaseCachePool;
|
|
||||||
import com.arialyy.aria.core.queue.pool.BaseExecutePool;
|
|
||||||
import com.arialyy.aria.core.queue.pool.DownloadSharePool;
|
|
||||||
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
|
import com.arialyy.aria.core.scheduler.DownloadGroupSchedulers;
|
||||||
import com.arialyy.aria.util.ALog;
|
import com.arialyy.aria.util.ALog;
|
||||||
|
|
||||||
@@ -47,12 +44,8 @@ public class DownloadGroupTaskQueue
|
|||||||
private DownloadGroupTaskQueue() {
|
private DownloadGroupTaskQueue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override BaseCachePool<DownloadGroupTask> setCachePool() {
|
@Override int getQueueType() {
|
||||||
return DownloadSharePool.getInstance().cachePool;
|
return TYPE_DG_QUEUE;
|
||||||
}
|
|
||||||
|
|
||||||
@Override BaseExecutePool<DownloadGroupTask> setExecutePool() {
|
|
||||||
return DownloadSharePool.getInstance().executePool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int getMaxTaskNum() {
|
@Override public int getMaxTaskNum() {
|
||||||
|
|||||||
@@ -19,11 +19,7 @@ package com.arialyy.aria.core.queue;
|
|||||||
import com.arialyy.aria.core.AriaManager;
|
import com.arialyy.aria.core.AriaManager;
|
||||||
import com.arialyy.aria.core.download.DownloadTask;
|
import com.arialyy.aria.core.download.DownloadTask;
|
||||||
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
import com.arialyy.aria.core.download.DownloadTaskEntity;
|
||||||
import com.arialyy.aria.core.inf.AbsTask;
|
|
||||||
import com.arialyy.aria.core.inf.TaskSchedulerType;
|
import com.arialyy.aria.core.inf.TaskSchedulerType;
|
||||||
import com.arialyy.aria.core.queue.pool.BaseCachePool;
|
|
||||||
import com.arialyy.aria.core.queue.pool.BaseExecutePool;
|
|
||||||
import com.arialyy.aria.core.queue.pool.DownloadSharePool;
|
|
||||||
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
|
||||||
import com.arialyy.aria.util.ALog;
|
import com.arialyy.aria.util.ALog;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
@@ -50,12 +46,8 @@ public class DownloadTaskQueue extends AbsTaskQueue<DownloadTask, DownloadTaskEn
|
|||||||
private DownloadTaskQueue() {
|
private DownloadTaskQueue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override BaseCachePool<DownloadTask> setCachePool() {
|
@Override int getQueueType() {
|
||||||
return DownloadSharePool.getInstance().cachePool;
|
return TYPE_D_QUEUE;
|
||||||
}
|
|
||||||
|
|
||||||
@Override BaseExecutePool<DownloadTask> setExecutePool() {
|
|
||||||
return DownloadSharePool.getInstance().executePool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int getConfigMaxNum() {
|
@Override public int getConfigMaxNum() {
|
||||||
|
|||||||
@@ -17,9 +17,6 @@
|
|||||||
package com.arialyy.aria.core.queue;
|
package com.arialyy.aria.core.queue;
|
||||||
|
|
||||||
import com.arialyy.aria.core.AriaManager;
|
import com.arialyy.aria.core.AriaManager;
|
||||||
import com.arialyy.aria.core.queue.pool.BaseCachePool;
|
|
||||||
import com.arialyy.aria.core.queue.pool.BaseExecutePool;
|
|
||||||
import com.arialyy.aria.core.queue.pool.UploadSharePool;
|
|
||||||
import com.arialyy.aria.core.scheduler.UploadSchedulers;
|
import com.arialyy.aria.core.scheduler.UploadSchedulers;
|
||||||
import com.arialyy.aria.core.upload.UploadTask;
|
import com.arialyy.aria.core.upload.UploadTask;
|
||||||
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
import com.arialyy.aria.core.upload.UploadTaskEntity;
|
||||||
@@ -45,12 +42,8 @@ public class UploadTaskQueue extends AbsTaskQueue<UploadTask, UploadTaskEntity>
|
|||||||
private UploadTaskQueue() {
|
private UploadTaskQueue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override BaseCachePool<UploadTask> setCachePool() {
|
@Override int getQueueType() {
|
||||||
return UploadSharePool.getInstance().cachePool;
|
return TYPE_U_QUEUE;
|
||||||
}
|
|
||||||
|
|
||||||
@Override BaseExecutePool<UploadTask> setExecutePool() {
|
|
||||||
return UploadSharePool.getInstance().executePool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int getConfigMaxNum() {
|
@Override public int getConfigMaxNum() {
|
||||||
|
|||||||
@@ -75,6 +75,19 @@ import java.util.regex.Pattern;
|
|||||||
public class CommonUtil {
|
public class CommonUtil {
|
||||||
private static final String TAG = "CommonUtil";
|
private static final String TAG = "CommonUtil";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取分块文件的快大小
|
||||||
|
*
|
||||||
|
* @param fileLen 文件总长度
|
||||||
|
* @param blockId 分块id
|
||||||
|
* @param blockNum 分块数量
|
||||||
|
* @return 分块长度
|
||||||
|
*/
|
||||||
|
public static long getBlockLen(long fileLen, int blockId, int blockNum) {
|
||||||
|
final long averageLen = fileLen / blockNum;
|
||||||
|
return blockId == blockNum - 1 ? (fileLen - blockId * averageLen) : averageLen;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查SD内存空间是否充足
|
* 检查SD内存空间是否充足
|
||||||
*
|
*
|
||||||
@@ -945,7 +958,7 @@ public class CommonUtil {
|
|||||||
final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
|
final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
|
||||||
if (file.renameTo(to)) {
|
if (file.renameTo(to)) {
|
||||||
to.delete();
|
to.delete();
|
||||||
}else {
|
} else {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间;
|
3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间;
|
||||||
对于采用多线程的任务或旧任务,依然采用原来的文件空间占用方式;
|
对于采用多线程的任务或旧任务,依然采用原来的文件空间占用方式;
|
||||||
-->
|
-->
|
||||||
<threadNum value="1"/>
|
<threadNum value="3"/>
|
||||||
|
|
||||||
<!--设置下载队列最大任务数, 默认为2-->
|
<!--设置下载队列最大任务数, 默认为2-->
|
||||||
<maxTaskNum value="1"/>
|
<maxTaskNum value="1"/>
|
||||||
|
|||||||
@@ -55,13 +55,12 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
//"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip";
|
//"https://yizi-kejian.oss-cn-beijing.aliyuncs.com/qimeng/package1/qmtable11.zip";
|
||||||
//"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk";
|
//"http://rs.0.gaoshouyou.com/d/04/1e/400423a7551e1f3f0eb1812afa1f9b44.apk";
|
||||||
//"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
|
//"http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
|
||||||
//"https://static.donguo.me//video/ip/course/pfys_1.mp4";
|
"https://static.donguo.me//video/ip/course/pfys_1.mp4";
|
||||||
//"https://www.baidu.com/link?url=_LFCuTPtnzFxVJByJ504QymRywIA1Z_T5xUxe9ZLuxcGM0C_RcdpWyB1eGjbJC-e5wv5wAKM4WmLMAS5KeF6EZJHB8Va3YqZUiaErqK_pxm&wd=&eqid=e8583fe70002d126000000065a99f864";
|
//"https://www.baidu.com/link?url=_LFCuTPtnzFxVJByJ504QymRywIA1Z_T5xUxe9ZLuxcGM0C_RcdpWyB1eGjbJC-e5wv5wAKM4WmLMAS5KeF6EZJHB8Va3YqZUiaErqK_pxm&wd=&eqid=e8583fe70002d126000000065a99f864";
|
||||||
//"https://d.pcs.baidu.com/file/a02c89a2d479d4fd2756f3313d42491d?fid=4232431903-250528-1114369760340736&dstime=1525491372&rt=sh&sign=FDtAERVY-DCb740ccc5511e5e8fedcff06b081203-3C13vkOkuk4TqXvVYW05zj1K0ao%3D&expires=8h&chkv=1&chkbd=0&chkpc=et&dp-logid=8651730921842106225&dp-callid=0&r=165533013";
|
//"https://d.pcs.baidu.com/file/a02c89a2d479d4fd2756f3313d42491d?fid=4232431903-250528-1114369760340736&dstime=1525491372&rt=sh&sign=FDtAERVY-DCb740ccc5511e5e8fedcff06b081203-3C13vkOkuk4TqXvVYW05zj1K0ao%3D&expires=8h&chkv=1&chkbd=0&chkpc=et&dp-logid=8651730921842106225&dp-callid=0&r=165533013";
|
||||||
//"http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1";
|
//"http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1";
|
||||||
//"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
|
//"https://dl.genymotion.com/releases/genymotion-2.12.1/genymotion-2.12.1-vbox.exe";
|
||||||
//"http://9.9.9.59:5000/download/CentOS-7-x86_64-Minimal-1804.iso";
|
//"http://9.9.9.59:5000/download/CentOS-7-x86_64-Minimal-1804.iso";
|
||||||
"https://firmwareapi.azurewebsites.net/firmware-overview?name=A19_Filament_W_IMG0038_00102411-encrypted.ota";
|
|
||||||
@Bind(R.id.start) Button mStart;
|
@Bind(R.id.start) Button mStart;
|
||||||
@Bind(R.id.stop) Button mStop;
|
@Bind(R.id.stop) Button mStop;
|
||||||
@Bind(R.id.cancel) Button mCancel;
|
@Bind(R.id.cancel) Button mCancel;
|
||||||
@@ -197,11 +196,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath());
|
L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath());
|
||||||
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
|
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
|
||||||
L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL));
|
L.d(TAG, "data ==> " + Aria.download(this).getDownloadEntity(DOWNLOAD_URL));
|
||||||
Intent install = new Intent(Intent.ACTION_VIEW);
|
//Intent install = new Intent(Intent.ACTION_VIEW);
|
||||||
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
//install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
File apkFile = new File(task.getDownloadPath());
|
//File apkFile = new File(task.getDownloadPath());
|
||||||
install.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
|
//install.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
|
||||||
startActivity(install);
|
//startActivity(install);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +260,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
|||||||
Aria.download(SingleTaskActivity.this)
|
Aria.download(SingleTaskActivity.this)
|
||||||
.load(DOWNLOAD_URL)
|
.load(DOWNLOAD_URL)
|
||||||
//.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
|
//.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
|
||||||
.addHeader("Accept-Encoding", "gzip, deflate")
|
//.addHeader("Accept-Encoding", "gzip, deflate")
|
||||||
//.addHeader("DNT", "1")
|
//.addHeader("DNT", "1")
|
||||||
//.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0")
|
//.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0")
|
||||||
.useServerFileName(true)
|
.useServerFileName(true)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ task clean(type: Delete) {
|
|||||||
ext {
|
ext {
|
||||||
userOrg = 'arialyy'
|
userOrg = 'arialyy'
|
||||||
groupId = 'com.arialyy.aria'
|
groupId = 'com.arialyy.aria'
|
||||||
publishVersion = '3.5.2_dev_2'
|
publishVersion = '3.5.2_dev_3'
|
||||||
// publishVersion = '1.0.4' //FTP插件
|
// publishVersion = '1.0.4' //FTP插件
|
||||||
repoName='maven'
|
repoName='maven'
|
||||||
desc = 'android 下载框架'
|
desc = 'android 下载框架'
|
||||||
|
|||||||
@@ -16,6 +16,6 @@
|
|||||||
#org.gradle.daemon=true
|
#org.gradle.daemon=true
|
||||||
#org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
|
#org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
|
||||||
# gradle proxy https://chaosleong.github.io/2017/02/10/Configuring-Gradle-Proxy/
|
# gradle proxy https://chaosleong.github.io/2017/02/10/Configuring-Gradle-Proxy/
|
||||||
#systemProp.socksProxyHost=127.0.0.1
|
systemProp.socksProxyHost=127.0.0.1
|
||||||
#systemProp.socksProxyPort=1080
|
systemProp.socksProxyPort=1080
|
||||||
#systemprop.socksProxyVersion=5
|
systemprop.socksProxyVersion=5
|
||||||
Reference in New Issue
Block a user