修复 线程重启,导致进度错误的问题 https://github.com/AriaLyy/Aria/issues/145
This commit is contained in:
@@ -133,6 +133,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
||||
synchronized (AriaManager.LOCK) {
|
||||
mChildCurrentLocation += len;
|
||||
STATE.CURRENT_LOCATION += len;
|
||||
//mIncrement += len;
|
||||
if (System.currentTimeMillis() - mLastSaveTime > 5000) {
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
new Thread(new Runnable() {
|
||||
@@ -223,7 +224,8 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
|
||||
mFailNum++;
|
||||
Log.w(TAG,
|
||||
"任务【" + mConfig.TEMP_FILE.getName() + "】thread__" + mConfig.THREAD_ID + "__正在重试");
|
||||
final long retryLocation = mChildCurrentLocation;
|
||||
final long retryLocation =
|
||||
mChildCurrentLocation == 0 ? mConfig.START_LOCATION : mChildCurrentLocation;
|
||||
mConfig.START_LOCATION = retryLocation;
|
||||
AbsThreadTask.this.run();
|
||||
}
|
||||
|
@@ -42,6 +42,8 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
//当前子线程的下载位置
|
||||
mChildCurrentLocation = mConfig.START_LOCATION;
|
||||
FTPClient client = null;
|
||||
InputStream is = null;
|
||||
BufferedRandomAccessFile file = null;
|
||||
@@ -72,8 +74,7 @@ class FtpThreadTask extends AbsFtpThreadTask<DownloadEntity, DownloadTaskEntity>
|
||||
file.seek(mConfig.START_LOCATION);
|
||||
byte[] buffer = new byte[mBufSize];
|
||||
int len;
|
||||
//当前子线程的下载位置
|
||||
mChildCurrentLocation = mConfig.START_LOCATION;
|
||||
|
||||
while ((len = is.read(buffer)) != -1) {
|
||||
if (STATE.isCancel) break;
|
||||
if (STATE.isStop) break;
|
||||
|
@@ -48,6 +48,8 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
||||
HttpURLConnection conn = null;
|
||||
BufferedInputStream is = null;
|
||||
BufferedRandomAccessFile file = null;
|
||||
//当前子线程的下载位置
|
||||
mChildCurrentLocation = mConfig.START_LOCATION;
|
||||
try {
|
||||
URL url = new URL(CommonUtil.convertUrl(mConfig.URL));
|
||||
conn = ConnectionHelp.handleConnection(url);
|
||||
@@ -78,8 +80,6 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
|
||||
file.seek(mConfig.START_LOCATION);
|
||||
byte[] buffer = new byte[mBufSize];
|
||||
int len;
|
||||
//当前子线程的下载位置
|
||||
mChildCurrentLocation = mConfig.START_LOCATION;
|
||||
while ((len = is.read(buffer)) != -1) {
|
||||
if (STATE.isCancel) break;
|
||||
if (STATE.isStop) break;
|
||||
|
@@ -44,6 +44,8 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
//当前子线程的下载位置
|
||||
mChildCurrentLocation = mConfig.START_LOCATION;
|
||||
FTPClient client = null;
|
||||
BufferedRandomAccessFile file = null;
|
||||
try {
|
||||
@@ -56,8 +58,6 @@ class FtpThreadTask extends AbsFtpThreadTask<UploadEntity, UploadTaskEntity> {
|
||||
+ ",结束位置:"
|
||||
+ mConfig.END_LOCATION
|
||||
+ "】");
|
||||
//当前子线程的下载位置
|
||||
mChildCurrentLocation = mConfig.START_LOCATION;
|
||||
client = createClient();
|
||||
if (client == null) return;
|
||||
initPath();
|
||||
|
Reference in New Issue
Block a user