fix: 修改部分情况下分包数据与总数据大小不一致的情况
This commit is contained in:
@@ -37,8 +37,8 @@ android {
|
|||||||
applicationId "com.navinfo.outdoor"
|
applicationId "com.navinfo.outdoor"
|
||||||
minSdkVersion 24
|
minSdkVersion 24
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
versionCode 55
|
versionCode 102
|
||||||
versionName "8.230518-正式版-OCR"
|
versionName "8.230605-正式版-OCR"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
ndk {
|
ndk {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import com.elvishew.xlog.XLog;
|
||||||
import com.github.lazylibrary.util.FileUtils;
|
import com.github.lazylibrary.util.FileUtils;
|
||||||
import com.github.lazylibrary.util.MD5;
|
import com.github.lazylibrary.util.MD5;
|
||||||
import com.github.lazylibrary.util.ZipUtil;
|
import com.github.lazylibrary.util.ZipUtil;
|
||||||
@@ -106,9 +107,14 @@ public class DataSaveUtils {
|
|||||||
poiEntity.setUploadMax(splitFiles.size());
|
poiEntity.setUploadMax(splitFiles.size());
|
||||||
sendRefreshItem(poiEntity);
|
sendRefreshItem(poiEntity);
|
||||||
List<Long> chunkSizeList = new ArrayList<>();
|
List<Long> chunkSizeList = new ArrayList<>();
|
||||||
|
long slipeFileSizeCount = 0;
|
||||||
for (File f: splitFiles) {
|
for (File f: splitFiles) {
|
||||||
chunkSizeList.add(f.length());
|
chunkSizeList.add(f.length());
|
||||||
|
slipeFileSizeCount+=f.length();
|
||||||
}
|
}
|
||||||
|
XLog.d("各个分包的数据和为:"+slipeFileSizeCount);
|
||||||
|
XLog.d("zip包的文件大小为:"+file.length());
|
||||||
|
XLog.d("是否一致:"+(Long.compare(slipeFileSizeCount, file.length())));
|
||||||
CommonResponse<String> response = createUploadTask(mContext, auditId, file.length(), chunkSizeList);
|
CommonResponse<String> response = createUploadTask(mContext, auditId, file.length(), chunkSizeList);
|
||||||
if (response!=null) {
|
if (response!=null) {
|
||||||
// 请求成功,获取需要上传的分包index
|
// 请求成功,获取需要上传的分包index
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import java.lang.Exception
|
|||||||
object FileSpliteMergeUtils {
|
object FileSpliteMergeUtils {
|
||||||
const val TAG = "FileUtils"
|
const val TAG = "FileUtils"
|
||||||
//默认切割文件的大小
|
//默认切割文件的大小
|
||||||
// private const val DEFAULT_CUT_SIZE: Long = 5*1024*1024//5MB
|
|
||||||
private const val DEFAULT_CUT_SIZE: Long = Constant.DEFAULT_CUT_SIZE//5MB
|
private const val DEFAULT_CUT_SIZE: Long = Constant.DEFAULT_CUT_SIZE//5MB
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,6 +69,32 @@ object FileSpliteMergeUtils {
|
|||||||
}
|
}
|
||||||
return singleFileList
|
return singleFileList
|
||||||
}
|
}
|
||||||
|
// @JvmStatic
|
||||||
|
// fun splitFile(file: File, chunkSize: Long = DEFAULT_CUT_SIZE): List<File> {
|
||||||
|
// val fileSize = file.length()
|
||||||
|
// val numChunks = (fileSize / chunkSize).toInt() + if (fileSize % chunkSize > 0) 1 else 0
|
||||||
|
// val chunks = mutableListOf<File>()
|
||||||
|
//
|
||||||
|
// RandomAccessFile(file, "r").use { raf ->
|
||||||
|
// for (i in 0 until numChunks) {
|
||||||
|
// val chunkFile = File(file.parent, "${file.nameWithoutExtension}_${i + 1}.tmp")
|
||||||
|
// if (chunkFile.exists()){
|
||||||
|
// chunkFile.delete()
|
||||||
|
// }
|
||||||
|
// RandomAccessFile(chunkFile, "rw").use { chunkRaf ->
|
||||||
|
// val start = i * chunkSize
|
||||||
|
// val end = if (i == numChunks - 1) fileSize else (i + 1) * chunkSize
|
||||||
|
// raf.seek(start)
|
||||||
|
// while (raf.filePointer < end) {
|
||||||
|
// chunkRaf.write(raf.read())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// chunks.add(chunkFile)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return chunks.toList()
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
private fun createSingleFile(sourceFile: File,index: Long): File{
|
private fun createSingleFile(sourceFile: File,index: Long): File{
|
||||||
val path = sourceFile.absolutePath.substringBeforeLast(".")
|
val path = sourceFile.absolutePath.substringBeforeLast(".")
|
||||||
@@ -90,18 +115,18 @@ object FileSpliteMergeUtils {
|
|||||||
val out = RandomAccessFile(single,"rw")
|
val out = RandomAccessFile(single,"rw")
|
||||||
var index = 0
|
var index = 0
|
||||||
try {
|
try {
|
||||||
val byte = ByteArray(1024)
|
val byte = ByteArray((end-begin).toInt())
|
||||||
inFile.seek(begin)
|
inFile.seek(begin)
|
||||||
while (inFile.read(byte).also { index = it } != -1 && inFile.filePointer <= end){
|
while (inFile.read(byte).also { index = it } != -1&&inFile.filePointer <= end){
|
||||||
out.write(byte,0,index)
|
out.write(byte,0,index)
|
||||||
|
endPointer = inFile.filePointer
|
||||||
}
|
}
|
||||||
endPointer = inFile.filePointer
|
|
||||||
}catch (e: Exception){
|
}catch (e: Exception){
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}finally {
|
}finally {
|
||||||
out.close()
|
out.close()
|
||||||
}
|
}
|
||||||
return endPointer - index // 减去最后一次读取的字节数,因为while循环中会先读取文件,导致filePointer字段向后移动index,但是后面的判断条件导致循环跳出,所以要将下次读取的offset向前移动
|
return endPointer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user