List of usage examples for java.lang System arraycopy
@HotSpotIntrinsicCandidate public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length);
From source file:Main.java
public static byte[] concat(byte[] a, byte b) { int aLen = a.length; byte[] c = new byte[aLen + 1]; System.arraycopy(a, 0, c, 0, aLen); c[aLen] = b;// w w w .jav a2s . com return c; }
From source file:Main.java
/** * Concatenate two byte arrays. No null checks are performed. * * @param x1 the first array/*from w w w . jav a 2 s . c om*/ * @param x2 the second array * @return (x2||x1) (little-endian order, i.e. x1 is at lower memory * addresses) */ public static byte[] concatenate(byte[] x1, byte[] x2) { byte[] result = new byte[x1.length + x2.length]; System.arraycopy(x1, 0, result, 0, x1.length); System.arraycopy(x2, 0, result, x1.length, x2.length); return result; }
From source file:Main.java
public static byte[] concat(byte[] first, byte[] second) { byte[] 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 byte[] NV21toYUV420SemiPlanar(final byte[] input, final byte[] output, final int width, final int height) { /*/*from ww w. j a va 2 s . c o m*/ * COLOR_FormatYUV420SemiPlanar 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 * 2 + 1]; // Cb (U) output[frameSize + i * 2 + 1] = input[frameSize + i * 2]; // Cr (V) } return output; }
From source file:Main.java
public static byte[] YV12toYUV420SemiPlanar(final byte[] input, final byte[] output, final int width, final int height) { /*/*from www . j av a2 s . com*/ * COLOR_FormatYUV420SemiPlanar 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; }
From source file:Main.java
public static String getNewString(String str) { byte[] data = str.getBytes(); int index = data.length; for (int i = 0; i < data.length; i++) { if (data[i] < 48 || data[i] > 57) { index = i;// w w w. j a va2 s. c o m break; } } byte[] temp = new byte[index]; System.arraycopy(data, 0, temp, 0, index); String res; try { res = new String(temp, "GBK"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } return res; }
From source file:Main.java
public static <T> T[] join(T[] head, T[] tail) { if (head == null) { return tail; }/*from www . ja v a 2s. c om*/ if (tail == null) { return head; } Class<?> type = head.getClass().getComponentType(); T[] result = (T[]) Array.newInstance(type, head.length + tail.length); System.arraycopy(head, 0, result, 0, head.length); System.arraycopy(tail, 0, result, head.length, tail.length); return result; }
From source file:Main.java
/** * Works with two arrays of the same class type. * /*ww w .ja v a2 s .c o m*/ * @param a * @param b * @return */ public static <T> T[] concatArrays(T[] a, T[] b) { final int alen = a.length; final int blen = b.length; @SuppressWarnings("unchecked") final T[] result = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), alen + blen); System.arraycopy(a, 0, result, 0, alen); System.arraycopy(b, 0, result, alen, blen); return result; }
From source file:Main.java
private static byte[] generateKey(String strSrc) { MessageDigest digest;//from w ww . ja v a 2 s.c o m byte[] keyBytes = new byte[32]; try { digest = MessageDigest.getInstance("SHA-256"); digest.update(strSrc.getBytes("UTF-8")); System.arraycopy(digest.digest(), 0, keyBytes, 0, keyBytes.length); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return keyBytes; }
From source file:Main.java
/** * Return a clone of the given byte array (performs null check beforehand). * * @param array the array to clone/*ww w. j a v a2s . co m*/ * @return the clone of the given array, or <tt>null</tt> if the array is * <tt>null</tt> */ public static byte[] clone(byte[] array) { if (array == null) { return null; } byte[] result = new byte[array.length]; System.arraycopy(array, 0, result, 0, array.length); return result; }