On 07/10/06, Colin Fleming <[EMAIL PROTECTED]> wrote:
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().
Has anyone come up with an elegant solution to this?

Could you do something like this:

int delta = src.remaining() - dest.remaining();
if (delta > 0)
{
   src.limit(src.limit() - delta);
}
dest.put(src);

I'm not sure if your use case means you need to reset the limit back
to its original value - if you do then it's obviously easy to do.

RG

Reply via email to