Java Array Move ArrayMove(byte b[], int srcOff, int dstOff, int Len)

Here you can find the source of ArrayMove(byte b[], int srcOff, int dstOff, int Len)

Description

Array Move

License

Open Source License

Declaration

public static void ArrayMove(byte b[], int srcOff, int dstOff, int Len) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static void ArrayMove(byte b[], int srcOff, int dstOff, int Len) {
        int i, j, k;

        if (null == b || 0 == b.length || Len <= 0) {
            return;
        }//from  www .ja  v a 2s  .c  o  m

        if (srcOff > dstOff) {
            if (b.length < srcOff + Len) {
                Len = b.length - srcOff;
            }

            k = srcOff + Len;
            for (i = srcOff, j = dstOff; i < k; i++, j++) {
                b[j] = b[i];
            }
        } else if (srcOff < dstOff) {
            if (b.length < dstOff + Len) {
                Len = b.length - dstOff;
            }

            k = dstOff + Len - 1;
            for (i = srcOff + Len - 1, j = k; i >= srcOff; i--, j--) {
                b[j] = b[i];
            }
        }
    }
}