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[] clone(byte[] data) {
    if (data == null) {
        return null;
    }//from  w ww.j av a 2s .  c  o m
    byte[] copy = new byte[data.length];

    System.arraycopy(data, 0, copy, 0, data.length);

    return copy;
}

From source file:Main.java

/**
 * @comment_sp Saca XMLNamespace/*from  w w w. j  a  va 2 s.c  o  m*/
 * @comment_ko removeXMLNamespace
 * @param source
 * @return
 */
public static byte[] removeXMLNamespace(byte source[]) {
    byte oldContent[] = new byte[source.length];
    System.arraycopy(source, 0, oldContent, 0, source.length);
    String s = new String(oldContent);
    int startIndex = s.indexOf("xmlns");
    int endIndex = s.indexOf(">", startIndex);
    StringBuffer sb = new StringBuffer(s);
    sb = sb.delete(startIndex - 1, endIndex);
    String input = new String(sb);
    return input.getBytes();
}

From source file:Main.java

public static byte[] combine(byte[]... bs) {
    int length = 0;
    for (byte[] b : bs) {
        length += b.length;//from w  ww.ja  va  2s .  co  m
    }
    byte[] rt = new byte[length];

    length = 0;

    for (byte[] b : bs) {
        System.arraycopy(b, 0, rt, length, b.length);
        length += b.length;
    }

    return rt;
}

From source file:Main.java

public static byte[] intsToBytes(int[] ints) {
    int len = ints.length;
    byte[] bytes = new byte[len * 4];
    for (int i = 0; i < len; i++) {
        byte[] b = intToBytes(ints[i]);
        System.arraycopy(b, 0, bytes, i * 4, 4);
    }//from  w w w.  j  a va 2 s .c  o m
    return bytes;
}

From source file:Main.java

public static byte[] YV12toI420(byte[] input, int width, int height) {
    final int frameSize = width * height;
    final int qFrameSize = frameSize / 4;
    System.arraycopy(input, 0, preAllocatedBufferColor, 0, frameSize); // Y
    System.arraycopy(input, frameSize + qFrameSize, preAllocatedBufferColor, frameSize, qFrameSize); // Cb (U)
    System.arraycopy(input, frameSize, preAllocatedBufferColor, frameSize + qFrameSize, qFrameSize); // Cr (V)
    return preAllocatedBufferColor;
}

From source file:Main.java

public static void copyMoveSegment(Object source, Object dest, int size, int index, int segmentSize,
        int destIndex) {

    boolean forward = index < destIndex;
    int sliceSize = forward ? index : destIndex;

    System.arraycopy(source, 0, dest, 0, sliceSize);

    sliceSize = forward ? size - destIndex - segmentSize : size - index - segmentSize;

    int sliceIndex = forward ? destIndex + segmentSize : index + segmentSize;

    System.arraycopy(source, sliceIndex, dest, sliceIndex, sliceSize);
    System.arraycopy(source, index, dest, destIndex, segmentSize);

    sliceSize = Math.abs(index - destIndex);
    sliceIndex = forward ? index + segmentSize : destIndex;

    int targetSliceIndex = forward ? index : destIndex + segmentSize;

    System.arraycopy(source, sliceIndex, dest, targetSliceIndex, sliceSize);
}

From source file:Main.java

public static String[] contact(String[] strs1, String[] strs2) {
    if (strs1 == null || strs2 == null) {
        return null;
    }//ww w. ja v a  2 s.  c o  m
    String[] result = Arrays.copyOf(strs1, strs1.length + strs2.length);
    System.arraycopy(strs2, 0, result, strs1.length, strs2.length);
    return result;
}

From source file:Main.java

public static byte[] YV12toNV21(byte[] input, int width, int height) {
    final int frameSize = width * height;
    final int qFrameSize = frameSize / 4;
    System.arraycopy(input, 0, preAllocatedBufferColor, 0, frameSize); // Y
    for (int i = 0; i < qFrameSize; i++) {
        preAllocatedBufferColor[frameSize + i * 2 + 1] = input[frameSize + i + qFrameSize]; // Cb (U)
        preAllocatedBufferColor[frameSize + i * 2] = input[frameSize + i]; // Cr (V)
    }//from ww  w  . j  av a 2s .  co  m
    return preAllocatedBufferColor;
}

From source file:Main.java

public static byte[] NV21toI420(byte[] input, int width, int height) {
    final int frameSize = width * height;
    final int qFrameSize = frameSize / 4;
    System.arraycopy(input, 0, preAllocatedBufferColor, 0, frameSize); // Y
    for (int i = 0; i < qFrameSize; i++) {
        preAllocatedBufferColor[frameSize + i] = input[frameSize + i * 2 + 1]; // Cb (U)
        preAllocatedBufferColor[frameSize + i + qFrameSize] = input[frameSize + i * 2]; // Cr (V)
    }//from www . ja  va2s  .c o m
    return preAllocatedBufferColor;
}

From source file:Main.java

public static byte[] YV12toNV12(byte[] input, int width, int height) {
    final int frameSize = width * height;
    final int qFrameSize = frameSize / 4;
    System.arraycopy(input, 0, preAllocatedBufferColor, 0, frameSize); // Y
    for (int i = 0; i < qFrameSize; i++) {
        preAllocatedBufferColor[frameSize + i * 2] = input[frameSize + i + qFrameSize]; // Cb (U)
        preAllocatedBufferColor[frameSize + i * 2 + 1] = input[frameSize + i]; // Cr (V)
    }//ww w .  j a  v  a  2  s .  co m
    return preAllocatedBufferColor;
}