Java ByteBuffer Copy copy(ByteBuffer src, int srcStartindex, ByteBuffer dest, int destStartIndex, int length)

Here you can find the source of copy(ByteBuffer src, int srcStartindex, ByteBuffer dest, int destStartIndex, int length)

Description

copy

License

Apache License

Parameter

Parameter Description
src a parameter
srcStartindex a parameter
dest a parameter
destStartIndex a parameter
length a parameter

Declaration

public static void copy(ByteBuffer src, int srcStartindex, ByteBuffer dest, int destStartIndex, int length) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;

public class Main {
    /**/*from w  ww  .java 2s .com*/
     * 
     * @param src
     * @param srcStartindex
     * @param dest
     * @param destStartIndex
     * @param length
     */
    public static void copy(ByteBuffer src, int srcStartindex, ByteBuffer dest, int destStartIndex, int length) {
        System.arraycopy(src.array(), srcStartindex, dest.array(), destStartIndex, length);
    }

    public static ByteBuffer copy(ByteBuffer src, int startindex, int endindex) {
        int size = endindex - startindex;
        int initPosition = src.position();
        int initLimit = src.limit();

        src.position(startindex);
        src.limit(endindex);
        ByteBuffer ret = ByteBuffer.allocate(size);
        ret.put(src);
        ret.flip();

        src.position(initPosition);
        src.limit(initLimit);
        return ret;
    }

    public static ByteBuffer copy(ByteBuffer src) {
        int startindex = src.position();
        int endindex = src.limit();
        return copy(src, startindex, endindex);
    }
}

Related

  1. copy(ByteBuffer origin, int start, int end)
  2. copy(ByteBuffer source)
  3. copy(ByteBuffer source, int byteCount)
  4. copy(ByteBuffer src, ByteBuffer dst)
  5. copy(ByteBuffer src, ByteBuffer dst, int length)
  6. copy(ByteBuffer src, int startindex, int endindex)
  7. copy(final ByteBuffer from, final ByteBuffer to)
  8. copy2Buffer(byte[] src, int srcOff, int srcLen, ByteBuffer dst, int dstOff)
  9. copyBinary(final ByteBuffer orig)