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 char[] copyOf(char[] data, int newLength) { char[] tmp = new char[newLength]; if (newLength < data.length) { System.arraycopy(data, 0, tmp, 0, newLength); } else {//from w w w. j av a2s.c o m System.arraycopy(data, 0, tmp, 0, data.length); } return tmp; }
From source file:Main.java
public static ParcelUuid[] toParcelUUids(Parcelable[] uuids) { if (uuids == null) { return null; }//from w ww . j av a2s.c om ParcelUuid[] uuids2 = new ParcelUuid[uuids.length]; System.arraycopy(uuids, 0, uuids2, 0, uuids.length); return uuids2; }
From source file:Main.java
public static boolean[] createCopy(boolean[] array, int dataSize, int newLength) { boolean[] newArray = new boolean[newLength]; if (dataSize > 0) { System.arraycopy(array, 0, newArray, 0, dataSize); }//w w w. j a v a 2 s. c o m return newArray; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T[] join(T[] head, T[] tail) { if (head == null) { return tail; }/* w ww . j a v a 2s . c o m*/ 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:Util.java
/** * Returns a new array that is the concatenation of a1 and a2. * //w w w.j a v a 2s .c o m * @param a1 * @param a2 * @return */ public static int[] append(int[] a1, int[] a2) { int[] ret = new int[a1.length + a2.length]; System.arraycopy(a1, 0, ret, 0, a1.length); System.arraycopy(a2, 0, ret, a1.length, a2.length); return ret; }
From source file:MainClass.java
private static int[] insertElement(int original[], int element, int index) { int length = original.length; int destination[] = new int[length + 1]; System.arraycopy(original, 0, destination, 0, index); destination[index] = element;//from w ww.j a v a 2 s .co m System.arraycopy(original, index, destination, index + 1, length - index); return destination; }
From source file:Main.java
public static Object cut(Object obj, int size) { int j;//from www . j a va2 s .c o m if ((j = Array.getLength(obj)) == 1) { return Array.newInstance(obj.getClass().getComponentType(), 0); } int k; if ((k = j - size - 1) > 0) { System.arraycopy(obj, size + 1, obj, size, k); } j--; Object obj1 = Array.newInstance(obj.getClass().getComponentType(), j); System.arraycopy(obj, 0, obj1, 0, j); return obj1; }
From source file:Main.java
public static byte[] copyOfRange(byte[] original, int from, int to) { int newLength = to - from; if (newLength < 0) { throw new IllegalArgumentException(from + " > " + to); }/* www .java 2 s .c o m*/ byte[] copy = new byte[newLength]; System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength)); return copy; }
From source file:com.lankr.tv_cloud.support.qcloud.image.PicProcessSign.java
public static String sign(int appId, String secret_id, String secret_key, String bucket, long expired, String url) {/*from w w w . j a v a2 s . co m*/ //a=[appid]&b=[bucket]&k=[SecretID]&t=[currenTime]&e=[expiredTime]&l=[url link] if (empty(secret_id) || empty(secret_key)) { return null; } long now = System.currentTimeMillis() / 1000; String plain_text = String.format("a=%d&b=%s&k=%s&t=%d&e=%d&l=%s", appId, bucket, secret_id, now, expired, url); byte[] bin = HmacUtils.hmacSha1(secret_key, plain_text); byte[] all = new byte[bin.length + plain_text.getBytes().length]; System.arraycopy(bin, 0, all, 0, bin.length); System.arraycopy(plain_text.getBytes(), 0, all, bin.length, plain_text.getBytes().length); all = Base64.encodeBase64(all); return new String(all); }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T[] delete(T[] array, int index) { int length = array.length; if (index < 0 || index >= length) { throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length); }//from www . ja v a 2s . c o m T[] result = (T[]) Array.newInstance(array.getClass().getComponentType(), length - 1); System.arraycopy(array, 0, result, 0, index); if (index < length - 1) { System.arraycopy(array, index + 1, result, index, length - index - 1); } return result; }