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

voidcopy(ByteBuffer src, ByteBuffer dst, int length)
copy
int srcLimit = src.limit();
int dstLimit = dst.limit();
src.limit(src.position() + length);
dst.limit(dst.position() + length);
dst.put(src);
src.limit(srcLimit);
dst.limit(dstLimit);
voidcopy(ByteBuffer src, int srcStartindex, ByteBuffer dest, int destStartIndex, int length)
copy
System.arraycopy(src.array(), srcStartindex, dest.array(), destStartIndex, length);
ByteBuffercopy(ByteBuffer src, int startindex, int endindex)
copy
int size = endindex - startindex;
ByteBuffer ret = ByteBuffer.allocate(size);
src.position(startindex);
for (int i = 0; i < size; i++) {
    ret.put(src.get());
return ret;
intcopy(final ByteBuffer from, final ByteBuffer to)
copy
final int len = from.limit();
return copy(from, 0, to, 0, len);
voidcopy2Buffer(byte[] src, int srcOff, int srcLen, ByteBuffer dst, int dstOff)
copy Buffer
dst.reset(); 
dst.position(dst.position() + dstOff);
dst.put(src, srcOff, srcLen);
dst.reset();
ByteBuffercopyBinary(final ByteBuffer orig)
copy Binary
if (orig == null) {
    return null;
ByteBuffer copy = ByteBuffer.wrap(new byte[orig.remaining()]);
if (orig.hasArray()) {
    System.arraycopy(orig.array(), orig.arrayOffset() + orig.position(), copy.array(), 0, orig.remaining());
} else {
    orig.slice().get(copy.array());
...
voidcopyBuffer(ByteBuffer dest, int pos1, ByteBuffer src, int len)
copy Buffer
Objects.requireNonNull(dest);
Objects.requireNonNull(src);
if (pos1 >= 0 && len >= 0) {
    for (int i = 0; i < len && src.hasRemaining(); ++i)
        dest.put(pos1 + i, src.get());
voidcopyBufferToStream(OutputStream out, ByteBuffer in, int offset, int length)
Copy data from a buffer to an output stream.
if (in.hasArray()) {
    out.write(in.array(), in.arrayOffset() + offset, length);
} else {
    for (int i = 0; i < length; ++i) {
        out.write(in.get(offset + i));
ByteBuffercopyByteBuffer(ByteBuffer buf)
copy Byte Buffer
ByteBuffer dest = newByteBuffer(buf.remaining());
buf.mark();
dest.put(buf);
buf.reset();
dest.rewind();
return dest;
ByteBuffercopyByteBuffer(ByteBuffer src)
Make a copy of an existing buffer (src) to a new buffer (dest)
ByteBuffer dest = newByteBuffer(src.capacity());
src.rewind();
dest.put(src);
return dest;