Java Utililty Methods ByteBuffer Copy

List of utility methods to do ByteBuffer Copy

Description

The list of methods to do ByteBuffer Copy are organized into topic(s).

Method

ByteBufferdeepCopyVisible(ByteBuffer orig)
deep Copy Visible
int pos = orig.position();
try {
    ByteBuffer toReturn;
    if (orig.isDirect()) {
        toReturn = ByteBuffer.allocateDirect(orig.remaining());
    } else {
        toReturn = ByteBuffer.allocate(orig.remaining());
    toReturn.put(orig);
    toReturn.order(orig.order());
    return (ByteBuffer) toReturn.position(0);
} finally {
    orig.position(pos);
ByteBufferduplicate(ByteBuffer bb)
duplicate
ByteBuffer out = ByteBuffer.allocate(bb.remaining());
out.put(bb.duplicate());
out.flip();
return out;
ByteBufferduplicate(ByteBuffer buffer)
Duplicate a byte buffer for storing for future use.
ByteBuffer newBuffer = ByteBuffer.allocate(buffer.remaining() * 2);
newBuffer.put(buffer);
newBuffer.flip();
return newBuffer;
ByteBuffer[]duplicate(ByteBuffer[] buffers)
duplicates the byte buffer array
if (buffers == null) {
    return null;
ByteBuffer[] copy = new ByteBuffer[buffers.length];
for (int i = 0; i < copy.length; i++) {
    copy[i] = duplicate(buffers[i]);
return copy;
...
ByteBuffer[]duplicate(ByteBuffer[] byteBuffers)
duplicate
ByteBuffer[] newByteBuffers = new ByteBuffer[byteBuffers.length];
for (int i = 0; i < byteBuffers.length; i++) {
    newByteBuffers[i] = byteBuffers[i].duplicate();
return newByteBuffers;
voidmemcpy(ByteBuffer dstBuffer, int dstByteOffset, ByteBuffer srcBuffer, int srcByteOffset, int length)
memcpy
ByteBuffer dstDup = dstBuffer.duplicate();
dstDup.position(dstByteOffset);
dstDup.limit(dstByteOffset + length);
ByteBuffer srcDup = srcBuffer.duplicate();
srcDup.position(srcByteOffset);
srcDup.limit(srcByteOffset + length);
dstDup.put(srcDup);