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:Util.java

/*********************************************************************
* Appends an integer to an integer array.
*
* @param  intArray/* ww  w . jav a  2  s .  c  o m*/
*
*   May be null.
*********************************************************************/
public static int[] append(int[] intArray, int i)
//////////////////////////////////////////////////////////////////////
{
    if (intArray == null) {
        return new int[] { i };
    }

    int intArrayLength = intArray.length;

    int[] newIntArray = new int[intArrayLength + 1];

    System.arraycopy(intArray, 0, newIntArray, 0, intArrayLength);

    newIntArray[intArrayLength] = i;

    return newIntArray;
}

From source file:Main.java

@Deprecated
public static NdefRecord createExternal(String domain, String type, byte[] data) {
    if (domain == null)
        throw new NullPointerException("domain is null");
    if (type == null)
        throw new NullPointerException("type is null");

    domain = domain.trim().toLowerCase(Locale.US);
    type = type.trim().toLowerCase(Locale.US);

    if (domain.length() == 0)
        throw new IllegalArgumentException("domain is empty");
    if (type.length() == 0)
        throw new IllegalArgumentException("type is empty");

    byte[] byteDomain = domain.getBytes(Charset.forName("UTF_8"));
    byte[] byteType = type.getBytes(Charset.forName("UTF_8"));
    byte[] b = new byte[byteDomain.length + 1 + byteType.length];
    System.arraycopy(byteDomain, 0, b, 0, byteDomain.length);
    b[byteDomain.length] = ':';
    System.arraycopy(byteType, 0, b, byteDomain.length + 1, byteType.length);

    return new NdefRecord(NdefRecord.TNF_EXTERNAL_TYPE, b, new byte[0], data);
}

From source file:Main.java

public static <T> T[] append(final T[] first, final T[] second) {
    if (first == null)
        return second;
    if (second == null)
        return first;

    final 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 double[] copyOf(double[] original, int newLength) {
    double[] copy = new double[newLength];
    System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
    return copy;/*w w  w .  j  ava  2  s.  c  om*/
}

From source file:de.tudarmstadt.lt.utilities.ArrayUtils.java

public static <T> T[] getConcatinatedArray(T[] a, T[] b) {
    T[] c = Arrays.copyOf(a, a.length + b.length);
    System.arraycopy(b, 0, c, a.length, b.length);
    return c;// w w w. j  a v a2s  . co m
}

From source file:StringUtil.java

/**
 * concatenates two arrays of strings./*from w  w  w. ja va  2 s .  co  m*/
 *
 * @param s1 the first array of strings.
 * @param s2 the second array of strings.
 * @return the resulting array with all strings in s1 and s2
 */
public static final String[] concat(String[] s1, String[] s2) {
    String[] erg = new String[s1.length + s2.length];

    System.arraycopy(s1, 0, erg, 0, s1.length);
    System.arraycopy(s2, 0, erg, s1.length, s2.length);

    return erg;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T[] arrayMerge(final T[]... arrays) {
    int count = 0;
    for (final T[] array : arrays) {
        count += array.length;/*from  www  .  j  a  va2  s  .co m*/
    }

    final T[] mergedArray = (T[]) Array.newInstance(arrays[0][0].getClass(), count);
    int start = 0;
    for (final T[] array : arrays) {
        System.arraycopy(array, 0, mergedArray, start, array.length);
        start += array.length;
    }
    return mergedArray;
}

From source file:com.qcloud.sign.PicProcessSign.java

public static String sign(int appId, String secret_id, String secret_key, String bucket, long expired) {
    //a=[appid]&b=[bucket]&k=[SecretID]&t=[currenTime]&e=[expiredTime]
    if (empty(secret_id) || empty(secret_key)) {
        return null;
    }/*from   ww  w .  ja  v  a  2 s.c  o m*/

    long now = System.currentTimeMillis() / 1000;
    String plain_text = String.format("a=%d&b=%s&k=%s&t=%d&e=%d", appId, bucket, secret_id, now, expired);

    byte[] bin = HmacUtils.hmacSha1(secret_key, plain_text);

    byte[] all = new byte[bin.length + plain_text.getBytes().length];
    System.arraycopy(bin, 0, all, 0, bin.length);
    System.arraycopy(plain_text.getBytes(), 0, all, bin.length, plain_text.getBytes().length);

    all = Base64.encodeBase64(all);
    return new String(all);
}

From source file:Main.java

/**
 * Concatenate two {@link java.lang.String} arrays.
 *
 * @param a The first array// ww w  .  j a  v a  2 s.  c om
 * @param b The second array
 * @return A newly allocated {@link java.lang.String} array.
 */
public static String[] concat(String[] a, String[] b) {
    String[] result = new String[a.length + b.length];
    System.arraycopy(a, 0, result, 0, a.length);
    System.arraycopy(b, 0, result, a.length, b.length);
    return result;
}

From source file:Main.java

private static byte[] expand(int pos, int length, byte[] buffer) {
    byte[] newBuffer = null;
    int newSize = pos + length;

    if (buffer != null && newSize <= buffer.length) {
        return buffer;
    }//from   w w  w  .j a v a  2s .  c o  m

    newBuffer = new byte[newSize];
    if (buffer != null)
        System.arraycopy(buffer, 0, newBuffer, 0, pos);

    return newBuffer;
}