List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:Main.java
/** * Concatenates a list of float arrays into a single array. * /*from w ww . j av a 2s. c o m*/ * @param arrays The arrays. * @return The concatenated array. * * @see {@link http://stackoverflow.com/questions/80476/how-to-concatenate-two-arrays-in-java} */ public static float[] concatAllFloat(float[]... arrays) { int totalLength = 0; final int subArrayCount = arrays.length; for (int i = 0; i < subArrayCount; ++i) { totalLength += arrays[i].length; } float[] result = Arrays.copyOf(arrays[0], totalLength); int offset = arrays[0].length; for (int i = 1; i < subArrayCount; ++i) { System.arraycopy(arrays[i], 0, result, offset, arrays[i].length); offset += arrays[i].length; } return result; }
From source file:Main.java
/** * Concatenates a list of double arrays into a single array. * /*ww w . ja v a2s . c o m*/ * @param arrays The arrays. * @return The concatenated array. * * @see {@link http://stackoverflow.com/questions/80476/how-to-concatenate-two-arrays-in-java} */ public static double[] concatAllDouble(double[]... arrays) { int totalLength = 0; final int subArrayCount = arrays.length; for (int i = 0; i < subArrayCount; ++i) { totalLength += arrays[i].length; } double[] result = Arrays.copyOf(arrays[0], totalLength); int offset = arrays[0].length; for (int i = 1; i < subArrayCount; ++i) { System.arraycopy(arrays[i], 0, result, offset, arrays[i].length); offset += arrays[i].length; } return result; }
From source file:Main.java
public static <T> T[] append(T[] array, T element) { final int N = array.length; array = Arrays.copyOf(array, N + 1); array[N] = element;//from w ww. j av a 2s . c om return array; }
From source file:Main.java
private static void product(List<String[]> results, List<List<String>> lists, int depth, String[] current) { for (int i = 0; i < lists.get(depth).size(); i++) { current[depth] = lists.get(depth).get(i); if (depth < lists.size() - 1) product(results, lists, depth + 1, current); else {//from w w w .j a va 2 s. c o m results.add(Arrays.copyOf(current, current.length)); } } }
From source file:Main.java
public static void testChecksum(String inputString, String expectedSum) throws Exception { byte[] sample = Hex.decodeHex(inputString.toCharArray()); byte[] sampleCheckSum = Hex.decodeHex(expectedSum.toCharArray()); char checksum = checkSum(sample); byte[] result = { (byte) (checksum & 0xFF), (byte) ((checksum >> 8) & 0xFF) }; System.out.println("Calculated checksum: " + byteArrayToString(result) + " vs expected: " + expectedSum); // Confirmation char checksumComp = (char) (checksum ^ 0xFFFF); byte verifySample[] = Arrays.copyOf(sample, sample.length + 2); verifySample[verifySample.length - 4] = (byte) (checksumComp & 0xFF); verifySample[verifySample.length - 3] = (byte) (checksumComp >> 8); char verifier = checkSum(verifySample); byte[] verifierResult = { (byte) (verifier & 0xFF), (byte) ((verifier >> 8) & 0xFF) }; System.out.println("Verifier = " + byteArrayToString(verifierResult)); }
From source file:Main.java
/** * * @param original an array we want to start with as prefix * @param additional an array we want to append as suffix * @return a new array consisting from original and afterwards additional * *//*w w w . j a v a2 s .c o m*/ public static <T> T[] combineArrays(T[] original, T... additional) { final T[] ret = Arrays.copyOf(original, original.length + additional.length); for (int i = 0; i < additional.length; i++) { ret[original.length + i] = additional[i]; } return ret; }
From source file:BD.Encriptador.java
public static String Encriptar(String texto) { String secretKey = "qualityinfosolutions"; //llave para encriptar datos String base64EncryptedString = ""; try {/*from w w w . j a va 2 s . co m*/ MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); Cipher cipher = Cipher.getInstance("DESede"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] plainTextBytes = texto.getBytes("utf-8"); byte[] buf = cipher.doFinal(plainTextBytes); byte[] base64Bytes = Base64.encodeBase64(buf); base64EncryptedString = new String(base64Bytes); } catch (Exception ex) { } return base64EncryptedString; }
From source file:Main.java
public static <T> T[] append(final T[] first, final T[] second) { if (first == null) return second; if (second == null) return first; final T[] result = Arrays.copyOf(first, first.length + second.length); System.arraycopy(second, 0, result, first.length, second.length); return result; }
From source file:controlpac.EncryptHelper.java
public static String Encriptar(String texto) { String base64EncryptedString = ""; try {/*from w w w .j a va2s.c om*/ MessageDigest md = MessageDigest.getInstance("MD5"); //Crea un hash con la clave elegida byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, "DESede"); //Crea la clave Cipher cipher = Cipher.getInstance("DESede"); cipher.init(Cipher.ENCRYPT_MODE, key);//Inicializa el cifrado con la clave byte[] plainTextBytes = texto.getBytes("utf-8"); byte[] buf = cipher.doFinal(plainTextBytes);//Cifra el texto byte[] base64Bytes = Base64.encodeBase64(buf);//Encodea el texto en base64 base64EncryptedString = new String(base64Bytes); } catch (Exception ex) { } return base64EncryptedString; }
From source file:Main.java
/** * Adds all of the specified {@link Component components} with the given * constraints, then calls {@link #validate(Container)} on <tt>to</tt>. * //from ww w .ja va 2 s . c o m * @param to * - the {@link Container} to add to * @param comps * - the components to add * @param constraints * - the constraints. If <tt>null</tt>, a new array of size * <tt>comps.length</tt> is created. * @see #validate(Container) */ public static void addAllAndValidate(Container to, Component[] comps, Object[] constraints) { if (constraints == null) { constraints = new Object[comps.length]; } else if (constraints.length < comps.length) { constraints = Arrays.copyOf(constraints, comps.length); } for (int i = 0; i < comps.length; i++) { to.add(comps[i], constraints[i]); } validate(to); }