-
This code fails: final Path p = Path.of("pom.xml");
final FileStore fs = Files.getFileStore(p);
try (FileChannel channel = FileChannel.open(p, ExtendedOpenOption.DIRECT)) {
final int alignment = (int) fs.getBlockSize();
final ByteBuf bytes = Unpooled.directBuffer(alignment);
bytes.writeBytes(channel, 0, alignment);
System.out.println("bytes: " + bytes.readCharSequence(alignment, StandardCharsets.UTF_8));
}
|
Beta Was this translation helpful? Give feedback.
Answered by
chrisvest
Feb 19, 2024
Replies: 1 comment 1 reply
-
The netty/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java Lines 265 to 267 in 68b0989 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
tisonkun
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
Unpooled
allocator cannot specify alignment.You need to use the
PooledByteBufAllocator
and construct it with an alignment requirement for direct buffers:netty/buffer/src/main/java/io/netty/buffer/PooledByteBufAllocator.java
Lines 265 to 267 in 68b0989