0

Java's FileChannel supports writing from an array of buffers to a channel in a gathering write with int write(ByteBuffer[] src).

It does not however support an equivalent of the write with offset method write(ByteBuffer src, long position). There seems to be no way to do a gathering write to a specified offset without locking the channel, changing the position, writing to that position, then unlocking the channel.

It appears that ultimately java uses the writev system call to perform gathering writes. The pwritev command appears to do exactly what one would want and expect it to do.

Is there any good reason why there is no gathering write method with offset? Are there any libraries that implement this?

tvoss
  • 11
  • 1

1 Answers1

0

It does exist, but with an extra parameter to make it even more general.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Despite the parameters' names,that doesn't actually write to offset within the channel. Instead, the offset specified refers to the **buffer array** and not the position within the channel to write to. – tvoss Dec 31 '15 at 09:01