|
|
|
@ -168,24 +168,38 @@ public class FileUtil { |
|
|
|
|
|
|
|
try { |
|
|
|
String fileTotalLength = response.headers().get("Content-Range"); |
|
|
|
//获取请求数据的总大小
|
|
|
|
fileTotalLength = fileTotalLength.substring(fileTotalLength.lastIndexOf("/") + 1); |
|
|
|
File tempFile = new File(localPath); |
|
|
|
//读取本地保存文件大小
|
|
|
|
String tempFileLength = String.valueOf(tempFile.length()); |
|
|
|
//二者大小一致时 修改文件后缀名
|
|
|
|
if (tempFile.length()!=0 &&fileTotalLength.equals(tempFileLength)) { |
|
|
|
String targetPath = localPath.substring(0, localPath.lastIndexOf(".")); |
|
|
|
if(targetPath.contains("?")){ |
|
|
|
String[] split = targetPath.split("[?]"); |
|
|
|
targetPath=split[0]; |
|
|
|
if( StringUtil.isEmpty(fileTotalLength)){ |
|
|
|
if(tempFile.length() > 10){ |
|
|
|
String targetPath = localPath.substring(0, localPath.lastIndexOf(".")); |
|
|
|
if(targetPath.contains("?")){ |
|
|
|
String[] split = targetPath.split("[?]"); |
|
|
|
targetPath=split[0]; |
|
|
|
} |
|
|
|
File targetFile = new File(targetPath); |
|
|
|
tempFile.renameTo(targetFile); |
|
|
|
}else{ |
|
|
|
tempFile.delete(); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//获取请求数据的总大小
|
|
|
|
fileTotalLength = fileTotalLength.substring(fileTotalLength.lastIndexOf("/") + 1); |
|
|
|
//读取本地保存文件大小
|
|
|
|
String tempFileLength = String.valueOf(tempFile.length()); |
|
|
|
//二者大小一致时 修改文件后缀名
|
|
|
|
if (tempFile.length()!=0 &&fileTotalLength.equals(tempFileLength)) { |
|
|
|
String targetPath = localPath.substring(0, localPath.lastIndexOf(".")); |
|
|
|
if(targetPath.contains("?")){ |
|
|
|
String[] split = targetPath.split("[?]"); |
|
|
|
targetPath=split[0]; |
|
|
|
} |
|
|
|
File targetFile = new File(targetPath); |
|
|
|
tempFile.renameTo(targetFile); |
|
|
|
} else{ |
|
|
|
Log.e("下载失败", localPath); |
|
|
|
//本地文件大于待下载文件时 表示断点下载异常 删除已下载文件
|
|
|
|
tempFile.delete(); |
|
|
|
} |
|
|
|
File targetFile = new File(targetPath); |
|
|
|
tempFile.renameTo(targetFile); |
|
|
|
} else if (Integer.valueOf(tempFileLength) > Integer.valueOf(fileTotalLength) || tempFile.length()==0) { |
|
|
|
Log.e("下载失败", localPath); |
|
|
|
//本地文件大于待下载文件时 表示断点下载异常 删除已下载文件
|
|
|
|
tempFile.delete(); |
|
|
|
} |
|
|
|
} catch (Throwable t) { |
|
|
|
LoggerUtil.e("downloadSuccess", StringUtil.getThrowableStr(t)); |
|
|
|
|