|
|
@ -40,6 +40,9 @@ import java.util.concurrent.Executors; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>> |
|
|
|
public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>> |
|
|
|
implements Runnable, IUtil { |
|
|
|
implements Runnable, IUtil { |
|
|
|
|
|
|
|
public static final String STATE = "_state_"; |
|
|
|
|
|
|
|
public static final String RECORD = "_record_"; |
|
|
|
|
|
|
|
|
|
|
|
private final String TAG = "AbsFileer"; |
|
|
|
private final String TAG = "AbsFileer"; |
|
|
|
protected IEventListener mListener; |
|
|
|
protected IEventListener mListener; |
|
|
|
protected TASK_ENTITY mTaskEntity; |
|
|
|
protected TASK_ENTITY mTaskEntity; |
|
|
@ -265,19 +268,22 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte |
|
|
|
for (Object key : keys) { |
|
|
|
for (Object key : keys) { |
|
|
|
String str = String.valueOf(key); |
|
|
|
String str = String.valueOf(key); |
|
|
|
Object state = pro.getProperty(str); |
|
|
|
Object state = pro.getProperty(str); |
|
|
|
if (str.contains("_record_")) { |
|
|
|
if (str.contains(RECORD)) { |
|
|
|
num++; |
|
|
|
num++; |
|
|
|
} else if (state != null && str.contains("_state_") && Integer.parseInt(state + "") == 1) { |
|
|
|
} else if (state != null && str.contains(STATE) && Integer.parseInt(state + "") == 1) { |
|
|
|
|
|
|
|
int i = Integer.parseInt(str.substring(str.length() - 1, str.length())); |
|
|
|
|
|
|
|
if (pro.getProperty(mTempFile.getName() + RECORD + i) != null) { |
|
|
|
mCompleteThreadNum++; |
|
|
|
mCompleteThreadNum++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (num == 0) { |
|
|
|
if (num == 0) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
mStartThreadNum = num; |
|
|
|
mStartThreadNum = num; |
|
|
|
for (int i = 0; i < mStartThreadNum; i++) { |
|
|
|
for (int i = 0; i < mStartThreadNum; i++) { |
|
|
|
if (pro.getProperty(mTempFile.getName() + "_record_" + i) == null) { |
|
|
|
if (pro.getProperty(mTempFile.getName() + RECORD + i) == null) { |
|
|
|
Object state = pro.getProperty(mTempFile.getName() + "_state_" + i); |
|
|
|
Object state = pro.getProperty(mTempFile.getName() + STATE + i); |
|
|
|
if (state != null && Integer.parseInt(state + "") == 1) { |
|
|
|
if (state != null && Integer.parseInt(state + "") == 1) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
@ -348,13 +354,13 @@ public abstract class AbsFileer<ENTITY extends AbsNormalEntity, TASK_ENTITY exte |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i = 0; i < mTotalThreadNum; i++) { |
|
|
|
for (int i = 0; i < mTotalThreadNum; i++) { |
|
|
|
long startL = i * blockSize, endL = (i + 1) * blockSize; |
|
|
|
long startL = i * blockSize, endL = (i + 1) * blockSize; |
|
|
|
Object state = pro.getProperty(mTempFile.getName() + "_state_" + i); |
|
|
|
Object state = pro.getProperty(mTempFile.getName() + STATE + i); |
|
|
|
if (state != null && Integer.parseInt(state + "") == 1) { //该线程已经完成
|
|
|
|
Object record = pro.getProperty(mTempFile.getName() + RECORD + i); |
|
|
|
|
|
|
|
if (state != null && Integer.parseInt(state + "") == 1 && record != null) { //该线程已经完成
|
|
|
|
if (resumeRecordLocation(i, startL, endL)) return; |
|
|
|
if (resumeRecordLocation(i, startL, endL)) return; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
//分配下载位置
|
|
|
|
|
|
|
|
Object record = pro.getProperty(mTempFile.getName() + "_record_" + i); |
|
|
|
|
|
|
|
//如果有记录,则恢复下载
|
|
|
|
//如果有记录,则恢复下载
|
|
|
|
if (!isNewTask && record != null && Long.parseLong(record + "") >= 0) { |
|
|
|
if (!isNewTask && record != null && Long.parseLong(record + "") >= 0) { |
|
|
|
Long r = Long.parseLong(record + ""); |
|
|
|
Long r = Long.parseLong(record + ""); |
|
|
|