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
private final static String encode(byte[] d) { if (d == null) return null; byte data[] = new byte[d.length + 2]; System.arraycopy(d, 0, data, 0, d.length); byte dest[] = new byte[(data.length / 3) * 4]; // 3-byte to 4-byte conversion for (int sidx = 0, didx = 0; sidx < d.length; sidx += 3, didx += 4) { dest[didx] = (byte) ((data[sidx] >>> 2) & 077); dest[didx + 1] = (byte) ((data[sidx + 1] >>> 4) & 017 | (data[sidx] << 4) & 077); dest[didx + 2] = (byte) ((data[sidx + 2] >>> 6) & 003 | (data[sidx + 1] << 2) & 077); dest[didx + 3] = (byte) (data[sidx + 2] & 077); }/*from w ww . j ava 2 s . co m*/ // 0-63 to ascii printable conversion for (int idx = 0; idx < dest.length; idx++) { if (dest[idx] < 26) dest[idx] = (byte) (dest[idx] + 'A'); else if (dest[idx] < 52) dest[idx] = (byte) (dest[idx] + 'a' - 26); else if (dest[idx] < 62) dest[idx] = (byte) (dest[idx] + '0' - 52); else if (dest[idx] < 63) dest[idx] = (byte) '+'; else dest[idx] = (byte) '/'; } // add padding for (int idx = dest.length - 1; idx > (d.length * 4) / 3; idx--) { dest[idx] = (byte) '='; } return new String(dest); }
From source file:Main.java
public static void flatten_2D_vector(float[][] src_vec, float[] target_vec) { int height = src_vec.length; int width = src_vec[0].length; for (int i = 0; i < height; i++) { System.arraycopy(src_vec[i], 0, target_vec, i * width, width); }// ww w. ja v a 2s . c om }
From source file:Main.java
public static byte[] insertBytes(byte[] target, int offset, int targetLength, byte[] insertion, int insertionLength) { byte result[] = new byte[(targetLength + insertionLength)]; System.arraycopy(target, 0, result, 0, offset); System.arraycopy(insertion, 0, result, offset, insertionLength); System.arraycopy(target, offset, result, (insertionLength + offset), (targetLength - offset)); return result; }
From source file:Main.java
public static byte[] appendRandomBytes(int len, byte... b) { byte[] ret = new byte[len + b.length]; System.arraycopy(b, 0, ret, 0, b.length); System.arraycopy(genRandomBytes(len), 0, ret, b.length, len); return ret;//from w w w . ja va 2s .c o m }
From source file:Main.java
static public Object extractArray(Object[] list, int pos, int n) { Class type = list.getClass().getComponentType(); Object temp = Array.newInstance(type, n); System.arraycopy(list, pos, temp, 0, n); return temp;/*from ww w .j ava 2 s .com*/ }
From source file:Main.java
/** * Returns a range of elements of source from start to end of the array. *//* w w w . j a v a2s. co m*/ public static int[] arraySlice(int[] source, int start, int count) { int[] slice = new int[count]; System.arraycopy(source, start, slice, 0, count); return slice; }
From source file:Main.java
public static void top_k_competition(float[] response_array, int size, int k) { float[] copy_of_array = new float[size]; System.arraycopy(response_array, 0, copy_of_array, 0, size); Arrays.sort(copy_of_array);/*from w w w . j a v a 2 s . c o m*/ for (int i = 0; i < size; i++) { if (response_array[i] < copy_of_array[size - k]) { response_array[i] = 0; } else { //response_array[i]= (response_array[i]- copy_of_array[size-k-1])/ // (copy_of_array[size-1]-copy_of_array[size-k-1]); response_array[i] = 1; } } }
From source file:Main.java
public static byte[] subArray(byte[] byteInput, int offset, int length) { if (offset < 0 || offset + length > byteInput.length) { return null; }/*from w w w . j a va 2 s . c o m*/ byte[] rtArray = new byte[length]; System.arraycopy(byteInput, offset, rtArray, 0, length); return rtArray; }
From source file:Main.java
private static char[] getPaddedBytes(String source) { char[] converted = source.toCharArray(); int requiredLength = 3 * ((converted.length + 2) / 3); char[] result = new char[requiredLength]; System.arraycopy(converted, 0, result, 0, converted.length); return result; }
From source file:Main.java
private static byte[] getPadded(BigInteger n, int length) { byte[] bs = n.toByteArray(); if (bs.length < length) { byte[] tmp = new byte[length]; System.arraycopy(bs, 0, tmp, length - bs.length, bs.length); bs = tmp;//from www.ja va2s .c o m } else if (bs.length > length) { //BigInteger bigger (probably due to 0 padding) byte[] tmp = new byte[length]; System.arraycopy(bs, bs.length - length, tmp, 0, length); bs = tmp; } return bs; }