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

ByteBuffercopy(ByteBuffer bb, boolean forceDirect)
Performs a deep copy on a byte buffer.
int capacity = bb.limit();
int pos = bb.position();
ByteOrder order = bb.order();
ByteBuffer copy;
if (bb.isDirect() || forceDirect) {
    copy = ByteBuffer.allocateDirect(capacity);
} else {
    copy = ByteBuffer.allocate(capacity);
...
ByteBuffercopy(ByteBuffer buf)
copy
ByteBuffer ret;
if (buf.isDirect()) {
    ret = buf.allocateDirect(buf.remaining());
} else {
    ret = buf.allocate(buf.remaining());
ret.put(buf.duplicate());
ret.clear();
...
ByteBuffercopy(ByteBuffer buffer)
Copies the contents in the specified ByteBuffer , but not any of its attributes (e.g.
ByteBuffer copy = ByteBuffer.allocate(buffer.limit());
copy.put(buffer).flip();
buffer.flip();
return copy;
byte[]copy(ByteBuffer buffer)
Copy buffer to byte array
buffer.mark();
byte[] bytes = new byte[buffer.limit()];
buffer.get(bytes);
buffer.reset();
return bytes;
ByteBuffercopy(ByteBuffer buffer)
copy
if (buffer == null)
    return null;
ByteBuffer copy = ByteBuffer.allocate(buffer.remaining());
copy.put(buffer);
copy.flip();
return copy;
voidcopy(ByteBuffer from, ByteBuffer to)
copy
to.put(from);
to.flip();
ByteBuffercopy(ByteBuffer origin, int start, int end)
copy
ByteOrder order = origin.order();
ByteBuffer copy = origin.duplicate();
copy.position(start);
copy.limit(end);
copy = copy.slice();
copy.order(order);
return copy;
ByteBuffercopy(ByteBuffer source)
Creates a new ByteBuffer of length source.remaining(), and copies source into it.
ByteBuffer target = ByteBuffer.wrap(new byte[source.remaining()]);
int position = source.position();
target.put(source);
source.position(position);
return target;
ByteBuffercopy(ByteBuffer source, int byteCount)
copy
ByteBuffer duplicate = source.duplicate();
duplicate.position(0);
int copyLimit = Math.min(duplicate.capacity(), byteCount);
duplicate.limit(copyLimit);
ByteBuffer copy = createByteBuffer(byteCount);
copy.put(duplicate);
copy.position(0);
return copy;
...
intcopy(ByteBuffer src, ByteBuffer dst)
copy
int srcRemaining = src.remaining();
int dstRemaining = dst.remaining();
if (srcRemaining <= dstRemaining) {
    dst.put(src);
    return srcRemaining;
int srcLimit = src.limit();
src.limit(src.position() + dstRemaining);
...