|
@@ -5,6 +5,7 @@ import org.apache.commons.io.FilenameUtils
|
|
|
import java.io.File
|
|
|
import java.io.FileInputStream
|
|
|
import java.nio.ByteBuffer
|
|
|
+import java.nio.file.Files
|
|
|
|
|
|
/**
|
|
|
* 文件工具类
|
|
@@ -45,6 +46,7 @@ object FileUtil {
|
|
|
val fc = FileInputStream(file).channel
|
|
|
val buffer = ByteBuffer.allocate(chunkSize)
|
|
|
val fileSize = fc.size()
|
|
|
+ val lastModified = file.lastModified() / 1000 * 1000 // 由于jdk8的bug导致在linux上读取修改时间丢失精度
|
|
|
val chunks = Math.ceil(1.0 * fileSize / chunkSize).toInt() // 分块总数
|
|
|
|
|
|
var currentPos = 0 * chunkSize * 1L
|
|
@@ -69,7 +71,7 @@ object FileUtil {
|
|
|
retBuffer.put(byte)
|
|
|
retBuffer.put(byte2)
|
|
|
|
|
|
- val timeByteArray = ByteBuffer.allocate(8).putLong(file.lastModified()).array()
|
|
|
+ val timeByteArray = ByteBuffer.allocate(8).putLong(lastModified).array()
|
|
|
timeByteArray.reverse()
|
|
|
|
|
|
retBuffer.put(timeByteArray)
|
|
@@ -82,7 +84,7 @@ object FileUtil {
|
|
|
val retBuffer = ByteBuffer.allocate(byte.size + 8) // 8 为long占用字节数
|
|
|
retBuffer.put(byte)
|
|
|
|
|
|
- val timeByteArray = ByteBuffer.allocate(8).putLong(file.lastModified()).array()
|
|
|
+ val timeByteArray = ByteBuffer.allocate(8).putLong(lastModified).array()
|
|
|
timeByteArray.reverse()
|
|
|
|
|
|
retBuffer.put(timeByteArray)
|