Tr : System.arraycopy(...) equivalents for ByteBuffer/FileChannel
Alan Bateman
Alan.Bateman at oracle.com
Fri Oct 12 04:07:55 PDT 2012
On 10/10/2012 22:27, Jeff Hain wrote:
> >For example, if wanting to copy bytes from a concurrently-read
> >DirectByteBuffer (can't touch its position), to another ByteBuffer,
> >one can only do a byte-loop (unless using disk as temp).
> Just thought about using ByteBuffer.duplicate()
> to avoid trouble with concurrent usage of position(),
> but the general point still remains if FileChannel is involved,
> and to avoid the boilerplate I'm doing.
> -Jeff
Right, ByteBuffers have a position, limit and mark and were not designed
for concurrent access like you are doing. Using duplicate or slice as
you have found is probably okay, assuming that the buffer contents is
not changing.
I didn't quite get how FileChannel is an issue you can read and write to
different parts of a file concurrently (I am aware that we have an issue
on Windows where these methods actually work sequentially but other
platforms should be okay).
-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20121012/24060640/attachment.html
More information about the nio-dev
mailing list