copy one ByteBuffer to another ByteBuffer - Java java.nio

Java examples for java.nio:ByteBuffer Copy

Description

copy one ByteBuffer to another ByteBuffer

Demo Code


//package com.java2s;

import java.nio.ByteBuffer;

public class Main {
    public final static int copy(final ByteBuffer from, final ByteBuffer to) {
        final int len = from.limit();
        return copy(from, 0, to, 0, len);
    }/*from w w w.  ja v  a2 s .c  o  m*/

    public final static int copy(final ByteBuffer from, final int offset1,
            final ByteBuffer to, final int offset2, final int len) {
        System.arraycopy(from.array(), offset1, to.array(), offset2, len);
        to.limit(offset2 + len);
        return len;
    }
}

Related Tutorials