Hi all,

This might be more of an NIO problem, but I'll try anyway. I'd like to
copy from one ByteBuffer to another, only copying either as much as is
available or as much as will fit. i.e. I'd like to call dest.put(src)
and have it copy the minimum of src.remaining() and dest.remaining().
Currently what happens is I'll get an overflow exception if
src.remaining() > dest.remaining(). I do actually need dest to be
fixed-size in this case. The two options that have occurred to me are:
use a view buffer on src in this case, copy from that and then call
src.skip(nCopied) afterwards, or to get the underlying byte[] and use
the put(byte[], offset, length) method. I suspect this latter option
may not work with direct buffers though, and both are pretty ugly.

Has anyone come up with an elegant solution to this?

Thanks,
Colin

Reply via email to