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
static int[] predictor_decompress_fir_adapt(int[] error_buffer, int output_size, int readsamplesize, int[] predictor_coef_table, int predictor_coef_num, int predictor_quantitization) { int buffer_out_idx = 0; int[] buffer_out; int bitsmove = 0; /* first sample always copies */ buffer_out = error_buffer;// w w w .j a v a2s .c om if (predictor_coef_num == 0) { if (output_size <= 1) return (buffer_out); int sizeToCopy = 0; sizeToCopy = (output_size - 1) * 4; System.arraycopy(error_buffer, 1, buffer_out, 1, sizeToCopy); return (buffer_out); } if (predictor_coef_num == 0x1f) // 11111 - max value of predictor_coef_num { /* second-best case scenario for fir decompression, * error describes a small difference from the previous sample only */ if (output_size <= 1) return (buffer_out); for (int i = 0; i < (output_size - 1); i++) { int prev_value = 0; int error_value = 0; prev_value = buffer_out[i]; error_value = error_buffer[i + 1]; bitsmove = 32 - readsamplesize; buffer_out[i + 1] = (((prev_value + error_value) << bitsmove) >> bitsmove); } return (buffer_out); } /* read warm-up samples */ if (predictor_coef_num > 0) { for (int i = 0; i < predictor_coef_num; i++) { int val = 0; val = buffer_out[i] + error_buffer[i + 1]; bitsmove = 32 - readsamplesize; val = ((val << bitsmove) >> bitsmove); buffer_out[i + 1] = val; } } /* general case */ if (predictor_coef_num > 0) { buffer_out_idx = 0; for (int i = predictor_coef_num + 1; i < output_size; i++) { int j; int sum = 0; int outval; int error_val = error_buffer[i]; for (j = 0; j < predictor_coef_num; j++) { sum += (buffer_out[buffer_out_idx + predictor_coef_num - j] - buffer_out[buffer_out_idx]) * predictor_coef_table[j]; } outval = (1 << (predictor_quantitization - 1)) + sum; outval = outval >> predictor_quantitization; outval = outval + buffer_out[buffer_out_idx] + error_val; bitsmove = 32 - readsamplesize; outval = ((outval << bitsmove) >> bitsmove); buffer_out[buffer_out_idx + predictor_coef_num + 1] = outval; if (error_val > 0) { int predictor_num = predictor_coef_num - 1; while (predictor_num >= 0 && error_val > 0) { int val = buffer_out[buffer_out_idx] - buffer_out[buffer_out_idx + predictor_coef_num - predictor_num]; int sign = ((val < 0) ? (-1) : ((val > 0) ? (1) : (0))); predictor_coef_table[predictor_num] -= sign; val *= sign; // absolute value error_val -= ((val >> predictor_quantitization) * (predictor_coef_num - predictor_num)); predictor_num--; } } else if (error_val < 0) { int predictor_num = predictor_coef_num - 1; while (predictor_num >= 0 && error_val < 0) { int val = buffer_out[buffer_out_idx] - buffer_out[buffer_out_idx + predictor_coef_num - predictor_num]; int sign = -((val < 0) ? (-1) : ((val > 0) ? (1) : (0))); predictor_coef_table[predictor_num] -= sign; val *= sign; // neg value error_val -= ((val >> predictor_quantitization) * (predictor_coef_num - predictor_num)); predictor_num--; } } buffer_out_idx++; } } return (buffer_out); }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T, U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) { T[] copy = ((Object) newType == (Object) Object[].class) ? (T[]) new Object[newLength] : (T[]) Array.newInstance(newType.getComponentType(), newLength); System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength)); return copy;/*from w w w .j a v a2 s .c o m*/ }
From source file:Main.java
public static int[] appendInt(final int[] cur, final int val) { if (cur == null) { return new int[] { val }; }// www. j a v a 2 s. c om final int N = cur.length; for (int i = 0; i < N; i++) { if (cur[i] == val) { return cur; } } final int[] ret = new int[N + 1]; System.arraycopy(cur, 0, ret, 0, N); ret[N] = val; return ret; }
From source file:Main.java
/** * Iterate over the elements in the <code>subset</code> and set the first * elements to <code>-1</code> in the <code>multiset</code> which equals the * subset elements. Return a new reduced multiset <code>int[]</code> array * where the <code>-1</code> values are deleted. * /*from ww w.j a va 2s . c om*/ * @param multiset * a multiset containing equals or greater than elements as the * subset. * @param subset * a subset with the elements which should be deleted. * @return */ public static int[] deleteSubset(int[] multiset, int[] subset) { int size = multiset.length; int[] setClone = new int[size];// multiset.clone(); System.arraycopy(multiset, 0, setClone, 0, size); int k = 0; for (int j = 0; j < subset.length; j++) { for (int i = k; i < setClone.length; i++) { if (subset[j] == setClone[i]) { setClone[i] = -1; size--; k = i + 1; break; } } } int[] result = new int[size]; k = 0; for (int i = 0; i < setClone.length; i++) { if (setClone[i] != -1) { result[k++] = setClone[i]; } } return result; }
From source file:Main.java
public static byte[] concat(byte single, byte[] array) { byte[] result = new byte[1 + array.length]; result[0] = single;/*from w w w.java 2 s . c om*/ System.arraycopy(array, 0, result, 1, array.length); return result; }
From source file:Main.java
/** * Fragments a byte buffer into smaller fragments of (max.) frag_size. * Example: a byte buffer of 1024 bytes and a frag_size of 248 gives 4 fragments * of 248 bytes each and 1 fragment of 32 bytes. * @return An array of byte buffers (<code>byte[]</code>). *///from w w w . j a v a 2s .com public static byte[][] fragmentBuffer(byte[] buf, int frag_size, final int length) { byte[] retval[]; int accumulated_size = 0; byte[] fragment; int tmp_size = 0; int num_frags; int index = 0; num_frags = length % frag_size == 0 ? length / frag_size : length / frag_size + 1; retval = new byte[num_frags][]; while (accumulated_size < length) { if (accumulated_size + frag_size <= length) tmp_size = frag_size; else tmp_size = length - accumulated_size; fragment = new byte[tmp_size]; System.arraycopy(buf, accumulated_size, fragment, 0, tmp_size); retval[index++] = fragment; accumulated_size += tmp_size; } return retval; }
From source file:Main.java
public static int[] duplicateArray(int[] array) { int[] copy = new int[array.length]; System.arraycopy(array, 0, copy, 0, array.length); return copy;/* w w w . j a va 2 s.c o m*/ }
From source file:Main.java
/** * Convert a 2-dimensional byte array into a 1-dimensional byte array by * concatenating all entries.//from w w w . j a va 2s .c o m * * @param array a 2-dimensional byte array * @return the concatenated input array */ public static byte[] concatenate(byte[][] array) { int rowLength = array[0].length; byte[] result = new byte[array.length * rowLength]; int index = 0; for (int i = 0; i < array.length; i++) { System.arraycopy(array[i], 0, result, index, rowLength); index += rowLength; } return result; }
From source file:Main.java
public static byte[] TriDesEncryption(byte[] byteKey, byte[] dec) { try {// w w w.j a v a 2 s.co 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); } SecretKeySpec key = new SecretKeySpec(en_key, "DESede"); Cipher ecipher = Cipher.getInstance("DESede/ECB/NoPadding"); ecipher.init(Cipher.ENCRYPT_MODE, key); byte[] en_b = ecipher.doFinal(dec); return en_b; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Util.java
/** * Returns a new array containing all of a, with additional extra space added (zero initialized). * @param a//from www . j a va 2 s. com * @param additional * @return */ public static int[] extend(int[] a, int additional) { int[] ret = new int[a.length + additional]; System.arraycopy(a, 0, ret, 0, a.length); return ret; }