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 Bitmap ARGBToBitmap(int width, int height, int[] data) {
    int ilength = data.length;
    int[] colors = new int[ilength];
    System.arraycopy(data, 0, colors, 0, ilength);
    Bitmap bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    return bmp;/*from  w  w  w .j av a 2  s.c  o  m*/
}

From source file:Main.java

public static <T> T[] addElement(T[] array, T element) {
    Class<?> ct = array.getClass().getComponentType();
    T[] newArray = (T[]) Array.newInstance(ct, array.length + 1);
    System.arraycopy(array, 0, newArray, 0, array.length);
    newArray[newArray.length - 1] = element;
    return newArray;
}

From source file:Main.java

public static byte[] cutBytes(byte[] src, int begin, int end) {
    byte[] result = null;
    if (src != null && begin >= 0 && end < src.length && begin < end) {
        result = new byte[end - begin + 1];
        System.arraycopy(src, begin, result, 0, end + 1 - begin);
    }/*from   www.j  av a2s.c o  m*/
    return result;
}

From source file:Main.java

public static byte[] bytesReplace(byte[] originalBytes, int offset, int len, byte[] replaceBytes) {
    byte[] newBytes = new byte[originalBytes.length + (replaceBytes.length - len)];
    System.arraycopy(originalBytes, 0, newBytes, 0, offset);
    System.arraycopy(replaceBytes, 0, newBytes, offset, replaceBytes.length);
    System.arraycopy(originalBytes, offset + len, newBytes, offset + replaceBytes.length,
            originalBytes.length - offset - len);
    return newBytes;
}

From source file:Main.java

private static byte[] make_kb(String strKey, int size) {
    byte[] kb = new byte[size];
    byte[] bytes = strKey.getBytes();
    System.arraycopy(bytes, 0, kb, 0, bytes.length > size ? size : bytes.length);
    return kb;/*from  w  w  w .j a  va  2  s . c  om*/
}

From source file:Main.java

public static byte[] copyOfRange(byte[] original, int from, int to) {
    int newLength = to - from;
    if (newLength < 0)
        throw new IllegalArgumentException("");
    byte[] copy = new byte[newLength];
    System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));

    return copy;//from   w  ww  .  java 2s.  c o  m

}

From source file:Main.java

public static int[] offsetArray(int[] array, int offset) {
    int length = array.length;
    int moveLength = length - offset;
    int[] temp = Arrays.copyOfRange(array, moveLength, length);
    System.arraycopy(array, 0, array, offset, moveLength);
    System.arraycopy(temp, 0, array, 0, offset);
    return array;
}

From source file:Main.java

public static byte[] addByte(byte[] a, byte b) {
    byte[] c;//from  w w w  .  j a  v  a  2 s.  c  o m
    if (a == null) {
        c = new byte[1];
    } else {
        c = new byte[a.length + 1];
    }

    if (a != null) {
        System.arraycopy(a, 0, c, 0, a.length);
        System.arraycopy(new byte[] { b }, 0, c, a.length, 1);
    } else {
        c[0] = b;
    }

    return c;
}

From source file:Main.java

public static byte[] concat(byte[] firstArray, byte[] secondArray) {
    if (firstArray == null || secondArray == null) {
        return null;
    }/*from  w  w  w  . j a v  a 2 s.c  om*/
    byte[] bytes = new byte[firstArray.length + secondArray.length];
    System.arraycopy(firstArray, 0, bytes, 0, firstArray.length);
    System.arraycopy(secondArray, 0, bytes, firstArray.length, secondArray.length);
    return bytes;
}

From source file:Main.java

/**
 * Creates duplicate of given array//from ww w .j  ava  2s .  co  m
 *
 * @param src The array to duplicate.
 * @return A copy of the array.
 */
public static byte[] duplicate(final byte[] src) {
    final byte[] result = new byte[src.length];
    System.arraycopy(src, 0, result, 0, src.length);
    return result;
}