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 byte[] fullZore(String data, int blockSize) {
    byte[] dataBytes = data.getBytes();
    int plaintextLength = dataBytes.length;
    if (plaintextLength % blockSize != 0) {
        plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize));
    }// ww w .ja v  a2  s. c  o  m
    byte[] plaintext = new byte[plaintextLength];
    System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
    return plaintext;
}

From source file:Main.java

/**
 * Create a message from an array, first field of the message is the size of the array
 * @param array//from  www  . j a va  2  s . c  om
 * @return
 */
public static byte[] createMessageFromArray(ArrayList<byte[]> array) {

    byte[] buffer1 = new byte[4];
    System.arraycopy(ByteBuffer.allocate(4).putInt(array.size()).array(), 0, buffer1, 0, 4);

    byte[] buffer2 = compileMessages(array);

    return concatenateMessages(buffer1, buffer2);
}

From source file:Main.java

public static byte[] sysCopy(List<byte[]> srcArrays) {
    int len = 0;/* w w  w. j a v a  2 s.  co  m*/
    for (byte[] srcArray : srcArrays) {
        len += srcArray.length;
    }
    byte[] destArray = new byte[len];
    int destLen = 0;
    for (byte[] srcArray : srcArrays) {
        System.arraycopy(srcArray, 0, destArray, destLen, srcArray.length);
        destLen += srcArray.length;
    }
    return destArray;
}

From source file:Main.java

public static byte[] YV12toYUV420Planar(byte[] input, byte[] output, int width, int height) {

    /*/*from   w  ww .  ja va  2  s  .  c o  m*/
     * COLOR_FormatYUV420Planar is I420 which is like YV12, but with U and V
     * reversed. So we just have to reverse U and V.
     */
    final int frameSize = width * height;
    final int qFrameSize = frameSize / 4;

    System.arraycopy(input, 0, output, 0, frameSize); // Y
    System.arraycopy(input, frameSize, output, frameSize + qFrameSize, qFrameSize); // Cr
    // (V)
    System.arraycopy(input, frameSize + qFrameSize, output, frameSize, qFrameSize); // Cb
    // (U)

    return output;
}

From source file:Main.java

public static byte[] NV21toYUV420PackedPlanar(byte[] input, byte[] output, int width, int height) {
    /*//  ww  w  .j  ava 2  s  . c  o m
     * COLOR_FormatYUV420Planar is I420 which is like YV12, but with U and V reversed.
     * So we just have to reverse U and V.
     */
    final int frameSize = width * height;
    final int qFrameSize = frameSize / 4;

    System.arraycopy(input, 0, output, 0, frameSize); // Y

    for (int i = 0; i < qFrameSize; i++) {
        output[frameSize + i + qFrameSize] = input[frameSize + i * 2 + 1]; // Cb (U)
        output[frameSize + i] = input[frameSize + i * 2]; // Cr (V)
    }

    return output;
}

From source file:Main.java

public static <T> T[] concat(T[] first, T[]... rest) {
    int totalLength = first.length;
    for (T[] arr : rest) {
        totalLength += arr.length;//from www.j av a  2s .c  om
    }

    T[] result = (T[]) Array.newInstance(first.getClass(), totalLength);
    System.arraycopy(first, 0, result, 0, first.length);
    int pos = first.length;

    for (T[] arr : rest) {
        System.arraycopy(arr, 0, result, pos, arr.length);
        pos += arr.length;
    }

    return result;
}

From source file:Main.java

public static int[] copyOf(int[] original, int newLength) {
    int[] copy = new int[newLength];
    System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
    return copy;//from   w  w  w.  j ava  2  s. co m
}

From source file:Main.java

public static byte[] slice(byte[] array, int start, int len) {
    byte[] r = new byte[len];
    System.arraycopy(array, start, r, 0, len);
    return r;//from  w  ww.j ava2s.  c  o  m
}

From source file:Main.java

public static String[] join(String[] left, String[] right) {
    if (left == null) {
        return clone(right);
    } else if (right == null) {
        return clone(left);
    }//from  ww w .j ava  2 s .  c om
    String[] joined = (String[]) Array.newInstance(String.class, left.length + right.length);
    System.arraycopy(left, 0, joined, 0, left.length);
    System.arraycopy(right, 0, joined, left.length, right.length);
    return joined;
}

From source file:Main.java

public static <T> T[] concatArray(T[] array1, T[] array2) {
    if (array1 == null || array1.length == 0) {
        return array2;
    }//from  w ww.j a va  2s  .  co  m
    if (array2 == null || array2.length == 0) {
        return array1;
    }
    T[] result = Arrays.copyOf(array1, array1.length + array2.length);
    System.arraycopy(array2, 0, result, array1.length, array2.length);
    return result;
}