Closed GavinRay97 closed 1 year ago
Just a tip:
private static void testWrite(Path p) throws Exception { try (FileChannel fc = FileChannel.open(p, StandardOpenOption.WRITE, ExtendedOpenOption.DIRECT)) { FileStore fs = Files.getFileStore(p); int alignment = (int)fs.getBlockSize(); ByteBuffer src = ByteBuffer.allocateDirect(PAGE_SIZE + alignment - 1) .alignedSlice(alignment); for (int j = 0; j < SIZE; j++) { src.put((byte)0); } src.flip(); fc.write(src); } } private static void testRead(Path p) throws Exception { try (FileChannel fc = FileChannel.open(p, ExtendedOpenOption.DIRECT)) { FileStore fs = Files.getFileStore(p); int alignment = (int)fs.getBlockSize(); ByteBuffer dest = ByteBuffer.allocateDirect(PAGE_SIZE + alignment - 1) .alignedSlice(alignment); fc.read(dest); } }
@GavinRay97, I want to support Java 8, but this method was added in Java 9. It might not make much sense to support Java 8 and I will switch to Java 11 and use this method.
Anyway thanks:)
Just a tip: