Java Utililty Methods ByteBuffer Clone

List of utility methods to do ByteBuffer Clone

Description

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

Method

ByteBufferclone(ByteBuffer original)
clone
ByteBuffer clone = ByteBuffer.allocate(original.capacity());
original.rewind();
clone.put(original);
original.rewind();
clone.flip();
return clone;
ByteBufferclone(final ByteBuffer buf)
clone
if (buf == null) {
    return null;
buf.rewind();
final ByteBuffer copy;
if (buf.isDirect()) {
    copy = createByteBuffer(buf.limit());
} else {
...
ByteBufferclone(final ByteBuffer original)
Clones a bytebuffer
final ByteBuffer clone = (original.isDirect()) ? ByteBuffer.allocateDirect(original.capacity())
        : ByteBuffer.allocate(original.capacity());
final ByteBuffer readOnlyCopy = original.asReadOnlyBuffer();
clone.put(readOnlyCopy);
return clone;
ByteBuffercloneAsDirectByteBuffer(byte[] input, int offset, int len)
Clone an input bytes array as direct ByteBuffer.
if (input == null) { 
    return null;
ByteBuffer directBuffer = ByteBuffer.allocateDirect(len);
directBuffer.put(input, offset, len);
directBuffer.flip();
return directBuffer;
ByteBuffercloneBuffer(ByteBuffer pesBuffer)
clone Buffer
ByteBuffer res = ByteBuffer.allocate(pesBuffer.remaining());
res.put(pesBuffer.duplicate());
res.clear();
return res;
ByteBuffercloneBufferData(ByteBuffer srcBuffer)
clone Buffer Data
ByteBuffer destBuffer;
byte[] bytesArr = new byte[srcBuffer.remaining()];
srcBuffer.mark();
srcBuffer.get(bytesArr);
srcBuffer.reset();
if (!srcBuffer.isDirect()) {
    destBuffer = ByteBuffer.wrap(bytesArr);
} else {
...
ByteBuffercloneByteBuffer(ByteBuffer buf)
clone Byte Buffer
ByteBuffer ret = ByteBuffer.allocate(buf.limit() - buf.position());
ret.put(buf);
ret.flip();
buf.flip();
return ret;
ByteBuffercloneByteBuffer(ByteBuffer buf)
Clones a ByteBuffer .
ByteBuffer ret = ByteBuffer.allocate(buf.limit() - buf.position());
if (buf.hasArray()) {
    ret.put(buf.array(), buf.position(), buf.limit() - buf.position());
} else {
    ret.put(buf);
ret.flip();
return ret;
...
ListcloneByteBufferList(List source)
clone Byte Buffer List
List<ByteBuffer> ret = new ArrayList<ByteBuffer>(source.size());
for (int k = 0; k < source.size(); k++) {
    ret.add(cloneByteBuffer(source.get(k)));
return ret;
ListcloneByteBufferList(List source)
Clones a list of ByteBuffer s.
List<ByteBuffer> ret = new ArrayList<>(source.size());
for (ByteBuffer b : source) {
    ret.add(cloneByteBuffer(b));
return ret;