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 Object expand(Object a) {
    Class cl = a.getClass();/*from w  w  w.  j  a  v  a 2  s.  com*/

    if (!cl.isArray()) {
        return null;
    }

    int length = Array.getLength(a);
    int newLength = length + 1; // 50% more
    Class componentType = a.getClass().getComponentType();
    Object newArray = Array.newInstance(componentType, newLength);

    System.arraycopy(a, 0, newArray, 0, length);
    return newArray;
}

From source file:Main.java

public static byte[] TDesDec(byte[] key, byte[] in) throws Exception {

    Key deskey = null;/*from  w ww.j av a  2  s  . co  m*/
    byte[] tdesKey = new byte[24];
    if (key.length % 8 != 0)
        return null;

    if (key.length == 8) {
        System.arraycopy(key, 0, tdesKey, 0, 8);
        System.arraycopy(key, 0, tdesKey, 8, 8);
        System.arraycopy(key, 0, tdesKey, 16, 8);
    }

    if (key.length == 16) {
        System.arraycopy(key, 0, tdesKey, 0, 16);
        System.arraycopy(key, 0, tdesKey, 16, 8);
    }

    DESedeKeySpec spec = new DESedeKeySpec(tdesKey);
    SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
    deskey = keyfactory.generateSecret(spec);

    Cipher cipher = Cipher.getInstance("desede" + "/ECB/NoPadding");

    cipher.init(Cipher.DECRYPT_MODE, deskey);
    byte[] bOut = cipher.doFinal(in);

    return bOut;
}

From source file:Main.java

public static byte[] TDesEnc(byte[] key, byte[] in) throws Exception {

    Key deskey = null;//  www  .  j a  v a 2s.c o m
    byte[] tdesKey = new byte[24];
    if (key.length % 8 != 0)
        return null;

    if (key.length == 8) {
        System.arraycopy(key, 0, tdesKey, 0, 8);
        System.arraycopy(key, 0, tdesKey, 8, 8);
        System.arraycopy(key, 0, tdesKey, 16, 8);
    }

    if (key.length == 16) {
        System.arraycopy(key, 0, tdesKey, 0, 16);
        System.arraycopy(key, 0, tdesKey, 16, 8);
    }

    DESedeKeySpec spec = new DESedeKeySpec(tdesKey);
    SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
    deskey = keyfactory.generateSecret(spec);

    Cipher cipher = Cipher.getInstance("desede" + "/ECB/NoPadding");

    cipher.init(Cipher.ENCRYPT_MODE, deskey);
    byte[] bOut = cipher.doFinal(in);

    return bOut;
}

From source file:Main.java

public static byte[] int2bcd(int number) {
    byte[] bcdByte = new byte[10];
    int i = 0;//from   w  w w  . ja  v  a  2  s . c o m
    for (; number > 0; ++i) {
        bcdByte[i] = (byte) (number % 10);
        number /= 10;

        if (number > 0) {
            bcdByte[i] |= (byte) ((number % 10) << 4);
            number /= 10;
        }
    }
    byte[] bcdRet = new byte[i > 1 ? i : 1];
    System.arraycopy(bcdByte, 0, bcdRet, 0, i);
    return bcdRet;
}

From source file:Main.java

public static byte[] getBytes(ResultSet rs) throws Exception {
    byte[] res = {};

    int col = rs.getMetaData().getColumnCount();
    for (int i = 1; i <= col; i++) {
        System.out.println(i + ":" + rs.getMetaData().getColumnTypeName(i));
        byte[] obj = {};//rs.getBytes(i);
        byte[] n = new byte[res.length + obj.length];
        System.arraycopy(res, 0, n, 0, res.length);
        System.arraycopy(obj, 0, n, res.length, obj.length);
        res = n;// w  ww  . j a v  a2  s . c om
    }

    return res;
}

From source file:Main.java

public static String byteToString(byte[] data) {
    int index = data.length;
    for (int i = 0; i < data.length; i++) {
        if (data[i] == 0) {
            index = i;// ww  w.ja  va 2 s.co m
            break;
        }
    }
    byte[] temp = new byte[index];
    Arrays.fill(temp, (byte) 0);
    System.arraycopy(data, 0, temp, 0, index);
    String str;
    try {
        str = new String(temp, "GBK");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "";
    }
    return str;
}

From source file:Main.java

public static String sig(Class[] retvalParams) {
    Class[] justParams = new Class[retvalParams.length - 1];
    System.arraycopy(retvalParams, 1, justParams, 0, justParams.length);
    return sigParams(justParams) + ci(retvalParams[0]);
}

From source file:Main.java

public static byte[] YV12toYUV420PackedSemiPlanar(final byte[] input, final byte[] output, final int width,
        final int height) {
    /*/*from   w w w . j a  va2  s  . c o m*/
     * COLOR_TI_FormatYUV420PackedSemiPlanar is NV21
     * We convert by putting the corresponding U and V bytes together (interleaved).
     */
    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 * 2 + 1] = input[frameSize + i + qFrameSize]; // Cb (U)
        output[frameSize + i * 2] = input[frameSize + i]; // Cr (V)
    }
    return output;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T[] appendToArrayBegining(T[] array, T element, T... elements) {

    Class<?> componentType = array.getClass().getComponentType();

    Object newArray = Array.newInstance(componentType, array.length + 1 + elements.length);

    Array.set(newArray, 0, element);
    if (elements.length > 0) {
        System.arraycopy(elements, 0, newArray, 1, elements.length);
        System.arraycopy(array, 0, newArray, elements.length, array.length);
    } else {/*from  ww w .j  a va  2s .co  m*/
        System.arraycopy(array, 0, newArray, 1, array.length);

    }

    return (T[]) newArray;
}

From source file:Main.java

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

    /*/*from w  w w . ja  v a  2 s .  c  om*/
     * COLOR_TI_FormatYUV420PackedSemiPlanar is NV12 We convert by putting
     * the corresponding U and V bytes together (interleaved).
     */
    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 * 2] = input[frameSize + i + qFrameSize]; // Cb
        // (U)
        output[frameSize + i * 2 + 1] = input[frameSize + i]; // Cr (V)
    }
    return output;
}