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
/** * Expands an array of floats to double its current size. * * @param f Array to be expanded./*from w w w .ja va 2 s .co m*/ * @return Array of floats with f.length*2 length. */ static public float[] resizeArrayFloat(float[] f, int newSize) { float[] newf = new float[newSize]; System.arraycopy(f, 0, newf, 0, Math.min(f.length, newSize)); return newf; }
From source file:Main.java
public static byte[] newByteArrayWithDateInfo(int second, byte[] data2) { byte[] data1 = createDateInfo(second).getBytes(); byte[] retdata = new byte[data1.length + data2.length]; System.arraycopy(data1, 0, retdata, 0, data1.length); System.arraycopy(data2, 0, retdata, data1.length, data2.length); return retdata; }
From source file:Main.java
/** * @comment_sp Agrega XMLNamespace// ww w . ja v a 2s.com * @comment_ko addXMLNamespace * @param source * @param xmlNamespace * @return */ public static byte[] addXMLNamespace(byte source[], String xmlNamespace) { byte oldContent[] = new byte[source.length]; System.arraycopy(source, 0, oldContent, 0, source.length); String s = new String(oldContent); String inputNamespace = " xmlns=\"" + xmlNamespace + "\""; int start = s.indexOf("?>"); int fromIndex = s.indexOf("<", start); int toIndex = s.indexOf(">", fromIndex); StringBuffer sb = new StringBuffer(s); sb.insert(toIndex, inputNamespace); String input = new String(sb); return input.getBytes(); }
From source file:Main.java
public static void flatten_3D_vector(float[][][] src_vec, float[] target_vec) { int depth = src_vec.length; int height = src_vec[0].length; int width = src_vec[0][0].length; for (int i = 0; i < depth; i++) { for (int j = 0; j < height; j++) { System.arraycopy(src_vec[i][j], 0, target_vec, (i * height + j) * width, width); }// w w w .j av a 2s . c om } }
From source file:Main.java
public static byte[] copyOfRange(byte[] data, int from, int to) { int newLength = getLength(from, to); byte[] tmp = new byte[newLength]; if (data.length - from < newLength) { System.arraycopy(data, from, tmp, 0, data.length - from); } else {/*from ww w .j ava2s . com*/ System.arraycopy(data, from, tmp, 0, newLength); } return tmp; }
From source file:Main.java
public static byte[] TriDesDecryption(byte[] byteKey, byte[] dec) { try {/*from w w w . jav a 2s . c o m*/ byte[] en_key = new byte[24]; if (byteKey.length == 16) { System.arraycopy(byteKey, 0, en_key, 0, 16); System.arraycopy(byteKey, 0, en_key, 16, 8); } SecretKey key = new SecretKeySpec(en_key, "DESede"); Cipher dcipher = Cipher.getInstance("DESede/ECB/NoPadding"); dcipher.init(Cipher.DECRYPT_MODE, key); byte[] de_b = dcipher.doFinal(dec); return de_b; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T[] addToArray(T[] array1, T[] array2) { Class<?> componentType = array1.getClass().getComponentType(); final Object newArray = Array.newInstance(componentType, array1.length + array2.length); System.arraycopy(array1, 0, newArray, 0, array1.length); System.arraycopy(array2, 0, newArray, array1.length, array2.length); return (T[]) newArray; }
From source file:Main.java
public static byte[] concatenate(byte[] a, byte[] b) { if (a != null && b != null) { byte[] rv = new byte[a.length + b.length]; System.arraycopy(a, 0, rv, 0, a.length); System.arraycopy(b, 0, rv, a.length, b.length); return rv; } else if (b != null) { return clone(b); } else {/*from w w w .j ava2 s. co m*/ return clone(a); } }
From source file:Main.java
public static <T> T[] ensureMinLength(T[] array, int length) { if (array.length >= length) { return array; }//from w w w .ja v a2s . co m T[] newArray = (T[]) Array.newInstance(array.getClass().getComponentType(), length); if (array.length > 0) { System.arraycopy(array, 0, newArray, 0, Math.min(array.length, length)); } return newArray; }
From source file:Main.java
public static double[] padWithZeros(double[] input, int len, double[] output) { if (len <= input.length) { return input; } else {/*from w ww. j a v a 2s.c o m*/ if (output == null || output.length != len) { output = new double[len]; } System.arraycopy(input, 0, output, 0, input.length); Arrays.fill(output, input.length, output.length, 0); return output; } }