0

fix buffered file

(cherry picked from commit 3010f10b43)
This commit is contained in:
2019-06-04 12:23:40 +03:00
parent 4f24485e2c
commit 62a1985db3

View File

@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.*; import java.io.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
@@ -54,12 +55,18 @@ public class UnpackLoader {
@Nullable @Nullable
public static ByteBuffer loadFileAsByteBuffer(String path) { public static ByteBuffer loadFileAsByteBuffer(String path) {
byte[] bytes = loadFile(path); File file = getFile(path);
if (bytes == null) { if (file == null) {
return null; return null;
} }
return ByteBuffer.wrap(bytes); try {
RandomAccessFile raf = new RandomAccessFile(file, "r");
return raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length());
} catch (IOException e) {
log.error("Can't load file '{}' as ByteBuffer: {}", file.getPath(), e.getMessage());
return null;
}
} }
public static RandomAccessFile loadFileAsRAF(String path) { public static RandomAccessFile loadFileAsRAF(String path) {