Example usage for java.lang System arraycopy

List of usage examples for java.lang System arraycopy

Introduction

In this page you can find the example usage for java.lang System arraycopy.

Prototype

@HotSpotIntrinsicCandidate
public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length);

Source Link

Document

Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array.

Usage

From source file:Main.java

public static <T> T[] concat(T[] first, T[] second) {
    if (first == null || second == null)
        return null;
    T[] result = Arrays.copyOf(first, first.length + second.length);
    System.arraycopy(second, 0, result, first.length, second.length);
    return result;
}

From source file:Main.java

public static byte[] buildNalUnit(byte[] paramArrayOfByte, int paramInt1, int paramInt2) {
    byte[] arrayOfByte = new byte[NAL_START_CODE.length + paramInt2];
    System.arraycopy(NAL_START_CODE, 0, arrayOfByte, 0, NAL_START_CODE.length);
    System.arraycopy(paramArrayOfByte, paramInt1, arrayOfByte, NAL_START_CODE.length, paramInt2);
    return arrayOfByte;
}

From source file:Main.java

/**
 * Return a clone of the given char array. No null checks are performed.
 *
 * @param array the array to clone/*from  w w  w .  j a v  a 2  s. co m*/
 * @return the clone of the given array
 */
public static char[] clone(char[] array) {
    char[] result = new char[array.length];
    System.arraycopy(array, 0, result, 0, array.length);
    return result;
}

From source file:Main.java

public static int[] resizeArray(int[] array, int newsize) {
    if (null == array) {
        return null;
    }/*from w w w.  ja  v  a2  s.  c  o m*/
    int[] newArr = new int[newsize];
    if (newsize > array.length) {
        System.arraycopy(array, 0, newArr, 0, array.length);
    } else {
        System.arraycopy(array, 0, newArr, 0, newsize);
    }

    return newArr;
}

From source file:Main.java

static public String[] grow(String A[], int amount) {
    String B[] = new String[A.length + amount];
    System.arraycopy(A, 0, B, 0, A.length);
    return B;//w  ww .j a  va2s . co  m
}

From source file:Main.java

public static byte[] concatArrays(byte[]... arrays) {
    int resLength = countArraysLength(arrays);

    byte[] result = new byte[resLength];

    int position = 0;
    for (byte[] arr : arrays) {
        System.arraycopy(arr, 0, result, position, arr.length);
        position += arr.length;//from   w w  w. j  av a2 s.c om
    }
    return result;
}

From source file:Main.java

public static String[] appendSelectionArgs(String[] originalValues, String[] newValues) {
    if (originalValues == null || originalValues.length == 0) {
        return newValues;
    }/*from ww w  .jav  a2  s .  c  om*/
    String[] result = new String[(originalValues.length + newValues.length)];
    System.arraycopy(originalValues, 0, result, 0, originalValues.length);
    System.arraycopy(newValues, 0, result, originalValues.length, newValues.length);
    return result;
}

From source file:Main.java

public static byte[] appendByteArray(byte[] src, byte[] data) {
    if (src.length <= 0 || data.length <= 0) {
        throw new IllegalArgumentException("\u5b57\u8282\u6570\u7ec4\u53c2\u6570\u9519\u8bef");
    }/*from   ww w .j  av a  2  s  . c o  m*/
    byte[] ret = new byte[(src.length + data.length)];
    System.arraycopy(src, 0, ret, 0, src.length);
    System.arraycopy(data, 0, ret, src.length, data.length);
    return ret;
}

From source file:Main.java

/**
 * Returns a duplicates of an array.//from ww w.  j  a  va2 s .c  om
 */
public static Object duplicateArray(Object source) {

    int size = Array.getLength(source);
    Object newarray = Array.newInstance(source.getClass().getComponentType(), size);

    System.arraycopy(source, 0, newarray, 0, size);

    return newarray;
}

From source file:Main.java

public static byte[] getBigIntegerBytes(BigInteger value) {
    byte[] bytes = value.toByteArray();
    if (bytes.length > 256) {
        byte[] correctedAuth = new byte[256];
        System.arraycopy(bytes, 1, correctedAuth, 0, 256);
        return correctedAuth;
    } else if (bytes.length < 256) {
        byte[] correctedAuth = new byte[256];
        System.arraycopy(bytes, 0, correctedAuth, 256 - bytes.length, bytes.length);
        for (int a = 0; a < 256 - bytes.length; a++) {
            correctedAuth[a] = 0;/*from   w w  w  .j a  v  a 2 s. co m*/
        }
        return correctedAuth;
    }
    return bytes;
}