0

fix buffered file

This commit is contained in:
2019-03-21 18:11:19 +03:00
parent 52bfd46ebd
commit 3010f10b43

View File

@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -54,12 +55,18 @@ public class UnpackLoader {
@Nullable
public static ByteBuffer loadFileAsByteBuffer(String path) {
byte[] bytes = loadFile(path);
if (bytes == null) {
File file = getFile(path);
if (file == 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) {