public static ByteBuffer clone(ByteBuffer buf) {
        if (buf == null) {
            return null;
        }
        buf.rewind();

        ByteBuffer copy;
        if (isDirect(buf)) {
            copy = createByteBuffer(buf.limit());
        } else {
            copy = ByteBuffer.allocate(buf.limit());
        }
        copy.put(buf);

        return copy;
    }
Creates a new ByteBuffer with the same contents as the given ByteBuffer.
The new ByteBuffer is separate from the old one and changes are not
reflected across. If you want to reflect changes, consider using
Buffer.duplicate().

@param buf
           the ByteBuffer to copy
@return the copy
jme3-core/src/main/java/com/jme3/util/BufferUtils.java