FileUtils { public static ByteBuffer readFile(@NotNull File file, long offset, long length) { ByteBuffer byteBuffer = ByteBuffer.allocate((int) length); int bytesRead = 0; try { while ((bytesRead = file.getFileChannel().read(byteBuffer, offset)) != -1) { if (!byteBuffer.hasRemaining()) { byteBuffer.flip(); return byteBuffer; } offset += bytesRead; } } catch (Exception e) { log.error("Can't read file", e); } if (bytesRead < byteBuffer.capacity()) { String error = String.format("File read error for file %s", file); log.error(error); throw new IllegalArgumentException(error); } byteBuffer.flip(); return byteBuffer; } private  FileUtils(); static boolean isFileEmpty(@NotNull File file, @NotNull IndexElt elt); static long getCrc(byte[] data); static long getCrc(@NotNull File file); static java.io.File getDiskPathByDisk(@NotNull FileConfiguration configuration, int disk); static java.io.File getFilePathByPartition(@NotNull FileConfiguration configuration, int disk, int partition); static java.io.File getFilePathByPartition(@NotNull FileConfiguration configuration, @NotNull Partition partition); static File getOrCreateFile(@NotNull FileConfiguration configuration, @NotNull Partition partition); static ByteBuffer readFile(@NotNull File file, long offset, long length); static int writeFile(@NotNull File file, byte[] bytes, long offset); @NotNull static ByteBuffer readFile(@NotNull java.io.File javaFile); @NotNull static String readFileToString(@NotNull java.io.File javaFile); @NotNull static SortedMap<Long, Block> readBlob(@NotNull IndexService indexService, @NotNull File blob, @NotNull Partition partition); @NotNull static MerkleTree buildMerkleTree(
            @NotNull IndexService indexService,
            @NotNull File blob,
            @NotNull Partition partition
    ); static int getPercentOfDeleted(
            @NotNull FileConfiguration configuration,
            @NotNull IndexService indexService,
            @NotNull Partition partition
    );  }
@Test public void readFile() throws IOException { java.io.File dataFile1 = getFilePathByPartition(configuration, 0, 0); Files.touch(dataFile1); partitionService.setActive(new Partition(0, 0)); File file = fileListService.getFile(0, 0); byte[] data = new byte[]{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9}; file.getFileChannel().write(ByteBuffer.wrap(data), 0); assertEquals(Bytes.getArray(FileUtils.readFile(file, 0, 1))[0], 0x0); assertEquals(Bytes.getArray(FileUtils.readFile(file, 3, 1))[0], 0x3); assertEquals(Bytes.getArray(FileUtils.readFile(file, 0, 1))[0], 0x0); file.close(); }