Copying ByteBuffers

Hello,

this might eb another dumb question but I can’t find the solution immediatly … in my loader class I create the bytebuffers but after loading I want to extract the object from my loader with calling a copy contructor and here for I need to copy my bytebuffers as well, but well I just can’t seam to find a way to do it, except for knowing the length, which can’t be asked to the buffer and get all the bytes itself … isn’t there a better solution to this … ?

I use the ByteBuffer from java.nio and the methods:
array() is optional method and doesn’t always and the duplicate method only copies the reference I think …

You can use the following code:

ByteBuffer b1, b2;

// both buffers are created and b1 is filled with data

b1.rewind();
b2.put(b1);

Maybe this helps?
Cheers.