The list of methods to do ByteBuffer Copy are organized into topic(s).
ByteBuffer
copy(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);
...
ByteBuffer
copy(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();
...
ByteBuffer
copy(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;
ByteBuffer
copy(ByteBuffer buffer) copy
if (buffer == null)
return null;
ByteBuffer copy = ByteBuffer.allocate(buffer.remaining());
copy.put(buffer);
copy.flip();
return copy;
ByteBuffer
copy(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;
ByteBuffer
copy(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;
ByteBuffer
copy(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;
...
int
copy(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);
...