This commit is contained in:
@@ -86,8 +86,8 @@ public class RecordHandler implements IRecordHandler {
|
||||
mTaskRecord.threadNum = mAdapter.initTaskThreadNum();
|
||||
initRecord(false);
|
||||
}
|
||||
mAdapter.handlerTaskRecord(mTaskRecord);
|
||||
}
|
||||
mAdapter.handlerTaskRecord(mTaskRecord);
|
||||
}
|
||||
saveRecord();
|
||||
return mTaskRecord;
|
||||
@@ -145,7 +145,7 @@ public class RecordHandler implements IRecordHandler {
|
||||
}
|
||||
mTaskRecord.threadRecords.add(tRecord);
|
||||
}
|
||||
mConfigFile.delete();
|
||||
FileUtil.deleteFile(mConfigFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,10 @@ import com.arialyy.aria.core.ThreadRecord;
|
||||
import com.arialyy.aria.core.inf.IRecordHandler;
|
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
import com.arialyy.aria.util.ALog;
|
||||
import com.arialyy.aria.util.BufferedRandomAccessFile;
|
||||
import com.arialyy.aria.util.FileUtil;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 任务记录帮助类,用于处理统一的逻辑
|
||||
@@ -39,6 +42,44 @@ public class RecordHelper {
|
||||
mTaskRecord = record;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理非分块的,多线程任务
|
||||
*/
|
||||
public void handleMutilRecord() {
|
||||
// 默认线程分块长度
|
||||
long blockSize = mWrapper.getEntity().getFileSize() / mTaskRecord.threadRecords.size();
|
||||
File temp = new File(mTaskRecord.filePath);
|
||||
boolean fileExists = false;
|
||||
if (!temp.exists()) {
|
||||
BufferedRandomAccessFile tempFile = null;
|
||||
try {
|
||||
tempFile = new BufferedRandomAccessFile(temp, "rw");
|
||||
tempFile.setLength(mWrapper.getEntity().getFileSize());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else {
|
||||
fileExists = true;
|
||||
}
|
||||
// 处理文件被删除的情况
|
||||
if (fileExists) {
|
||||
for (int i = 0; i < mTaskRecord.threadNum; i++) {
|
||||
long startL = i * blockSize, endL = (i + 1) * blockSize;
|
||||
ThreadRecord tr = mTaskRecord.threadRecords.get(i);
|
||||
tr.startLocation = startL;
|
||||
tr.isComplete = false;
|
||||
|
||||
//最后一个线程的结束位置即为文件的总长度
|
||||
if (tr.threadId == (mTaskRecord.threadNum - 1)) {
|
||||
endL = mWrapper.getEntity().getFileSize();
|
||||
}
|
||||
tr.endLocation = endL;
|
||||
}
|
||||
}
|
||||
mWrapper.setNewTask(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理分块任务的记录,分块文件(blockFileLen)长度必须需要小于等于线程区间(threadRectLen)的长度
|
||||
*/
|
||||
|
||||
@@ -367,8 +367,8 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
|
||||
|| isNotNetRetry) && !isBreak()) {
|
||||
ALog.w(TAG, String.format("ts切片【%s】正在重试", getFileName()));
|
||||
mFailTimes++;
|
||||
mConfig.tempFile.delete();
|
||||
FileUtil.createFile(mConfig.tempFile.getPath());
|
||||
FileUtil.deleteFile(mConfig.tempFile);
|
||||
FileUtil.createFile(mConfig.tempFile);
|
||||
ThreadTaskManager.getInstance().retryThread(this);
|
||||
} else {
|
||||
sendFailMsg(null);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class ErrorHelp {
|
||||
try {
|
||||
File file = new File(getLogPath());
|
||||
if (!file.exists()) {
|
||||
FileUtil.createFile(file.getPath());
|
||||
FileUtil.createFile(file);
|
||||
}
|
||||
writer = new PrintWriter(new FileWriter(file.getPath(), true));
|
||||
writer.append(stringBuffer);
|
||||
|
||||
@@ -86,22 +86,23 @@ public class FileUtil {
|
||||
ALog.e(TAG, "文件路径不能为null");
|
||||
return false;
|
||||
}
|
||||
File file = new File(path);
|
||||
return createFile(new File(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件 当文件不存在的时候就创建一个文件。 如果文件存在,先删除原文件,然后重新创建一个新文件
|
||||
*
|
||||
* @return {@code true} 创建成功、{@code false} 创建失败
|
||||
*/
|
||||
public static boolean createFile(File file) {
|
||||
if (file.getParentFile() == null || !file.getParentFile().exists()) {
|
||||
ALog.d(TAG, "目标文件所在路径不存在,准备创建……");
|
||||
if (!createDir(file.getParent())) {
|
||||
ALog.d(TAG, "创建目录文件所在的目录失败!文件路径【" + path + "】");
|
||||
}
|
||||
}
|
||||
// 创建目标文件
|
||||
if (file.exists()) {
|
||||
final File to = new File(file.getAbsolutePath() + System.currentTimeMillis());
|
||||
if (file.renameTo(to)) {
|
||||
to.delete();
|
||||
} else {
|
||||
file.delete();
|
||||
ALog.d(TAG, "创建目录文件所在的目录失败!文件路径【" + file.getPath() + "】");
|
||||
}
|
||||
}
|
||||
// 文件存在,删除文件
|
||||
deleteFile(file);
|
||||
try {
|
||||
if (file.createNewFile()) {
|
||||
//ALog.d(TAG, "创建文件成功:" + file.getAbsolutePath());
|
||||
@@ -327,7 +328,7 @@ public class FileUtil {
|
||||
ALog.d(TAG, String.format("block = %s", block));
|
||||
File subFile = new File(subPath);
|
||||
if (!subFile.exists()) {
|
||||
subFile.createNewFile();
|
||||
createFile(subFile);
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(subFile);
|
||||
FileChannel sfoc = fos.getChannel();
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
<resources>
|
||||
<string name="app_name">PublicComponent</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user