2 ms·
> I doubt, as that would break any FileChannel.write(ByteBuffer) that expects the buffer to be consumed (remaining()==0) You can't expect that with Asynchronou
by twic 3y ago
> I doubt, as that would break any FileChannel.write(ByteBuffer) that expects the buffer to be consumed (remaining()==0)
You can't expect that with AsynchronousFileChannel::write at the moment, though, because the buffer is consumed on a background thread. As the docs say [1]:
> Buffers are not safe for use by multiple concurrent threads so care should be taken to not access the buffer until the operation has completed.
And as the article says, on Windows, these writes are "truly" async at the OS level, so portable code already needs to deal with that.
[1] https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/channels/AsynchronousByteChannel.html#write(java.nio.ByteBuffer,A,java.nio.channels.CompletionHandler) https://docs.oracle.com/en/java/javase/17/docs/api/java.base...