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

private static byte[] getMacSecret(byte[] combinedSecrets) {
    byte[] macSecret = new byte[20];
    System.arraycopy(combinedSecrets, 16, macSecret, 0, macSecret.length);
    return macSecret;
}

From source file:ArrayUtil.java

/**
 * Doubles the size of an array//from  w w  w  .ja  va2s  .  com
 * 
 * @param in
 * @return The new array
 */
public static int[] grow(int[] in) {
    int[] na = new int[in.length * 2];
    System.arraycopy(in, 0, na, 0, in.length);
    return na;
}

From source file:Main.java

/**
 * Will remove all occurrences of the characters '<', '>', '[', ']', '{' and '}'
 * from the input string and return the result. Beware: While <code>chopBraces()</code>
 * only removes those characters from the beginning and end of a string, <code>stripBraces()</code>
 * will remove characters from all positions in the string.
 * @param s/*w ww . jav a2s .c o  m*/
 * @return
 */
public static String stripBraces(String s) {
    char c[] = s.toCharArray();
    char tmp[] = new char[c.length];

    int id = 0;
    for (int i = 0; i < c.length; i++) {
        char cc = c[i];
        if (cc != '<' && cc != '>' && cc != '[' && cc != ']' && cc != '{' && cc != '}')
            tmp[id++] = c[i];
    }

    char res[] = new char[id];
    System.arraycopy(tmp, 0, res, 0, id);
    return new String(res);
    //      
    //      if(s==null || (s.indexOf('[')<0 && s.indexOf('{')<0)) return s;
    //      return s.substring(1,s.length()-1);      
}

From source file:Main.java

public static short[] duplicateArray(short[] array) {
    short[] copy = new short[array.length];
    System.arraycopy(array, 0, copy, 0, array.length);
    return copy;// w w w .ja v a  2s. c  o m
}

From source file:Main.java

/**
 * Concatenate two byte arrays.//from   w  w w. j a  v  a  2  s  .c o  m
 */
private static byte[] concat(final byte[] arrayA, final byte[] arrayB) {
    final byte[] result = new byte[arrayA.length + arrayB.length];
    System.arraycopy(arrayA, 0, result, 0, arrayA.length);
    System.arraycopy(arrayB, 0, result, arrayA.length, arrayB.length);

    return result;
}

From source file:Main.java

private static byte[] getEncryptionSecret(byte[] combinedSecrets) {
    byte[] encryptionSecret = new byte[16];
    System.arraycopy(combinedSecrets, 0, encryptionSecret, 0, encryptionSecret.length);
    return encryptionSecret;
}

From source file:Main.java

public static <T> T[] convertToSingleArray(T[][] a_arrayOfArrays, Class<T[]> a_destType)
/*     */ {// w  w w  .  ja  v  a  2s.  c om
    /* 230 */int iTotalLength = 0;
    /* 231 */for (Object[] srcArray : a_arrayOfArrays)
    /*     */ {
        /* 233 */if (srcArray == null)
            /*     */continue;
        /* 235 */iTotalLength += srcArray.length;
        /*     */}
    /*     */
    /* 242 */Object[] dest = (Object[]) (Object[]) Array.newInstance(a_destType.getComponentType(),
            iTotalLength);
    /*     */
    /* 245 */int iDestPointer = 0;
    /* 246 */for (Object[] srcArray : a_arrayOfArrays)
    /*     */ {
        /* 248 */if (srcArray == null)
            /*     */continue;
        /* 250 */System.arraycopy(srcArray, 0, dest, iDestPointer, srcArray.length);
        /* 251 */iDestPointer += srcArray.length;
        /*     */}
    /*     */
    /* 255 */return (T[]) dest;
    /*     */}

From source file:Main.java

/**
 * Strips null Strings from an array of Strings.
 * // w w  w .  j a  v a2s.c  o m
 * @param str
 *          Array to remove null strings from.
 * @return String array with null strings removed.
 */
public static String[] stripNullStrings(String[] str) {
    if (str == null)
        return null;

    // propagate null strings to the end
    for (int i = str.length - 1; i > 0; i--) {
        if (str[i] != null && str[i - 1] == null) {
            str[i - 1] = str[i];
            str[i] = null;
        }
    }

    int numvalid = 0;
    for (int i = 0; i < str.length; i++)
        if (str[i] != null)
            numvalid = i + 1;

    if (numvalid == 0)
        return null;

    String tmp[] = new String[numvalid];
    System.arraycopy(str, 0, tmp, 0, numvalid);
    return tmp;
}

From source file:Main.java

public static String[] concatStrArrays(String[] a1, String[] a2) {
    String[] retArr = new String[a1.length + a2.length];
    System.arraycopy(a1, 0, retArr, 0, a1.length);
    System.arraycopy(a2, 0, retArr, a1.length, a2.length);
    return retArr;
}

From source file:Main.java

public static long[] copy(long[] array) {
    if (array == null)
        return new long[0];
    long[] newArray = new long[array.length];
    System.arraycopy(array, 0, newArray, 0, array.length);
    return newArray;
}