List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:de.tudarmstadt.lt.utilities.ArrayUtils.java
public static <T> T[] getConcatinatedArray(T[] a, T[] b) { T[] c = Arrays.copyOf(a, a.length + b.length); System.arraycopy(b, 0, c, a.length, b.length); return c;/*from ww w. j a va 2 s.co m*/ }
From source file:Main.java
@SafeVarargs public static <T> List<T> list(T... t) { return Collections.unmodifiableList(Arrays.asList(Arrays.copyOf(t, t.length))); }
From source file:lib.clases_cripto.java
public static String Encriptar(String texto) { String secretKey = "qualityinfosolutions"; //llave para encriptar datos String base64EncryptedString = ""; try {/*from ww w . java 2 s . co m*/ MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(texto.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); Md5Crypt.md5Crypt(keyBytes); 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:com.basp.trabajo_al_minuto.model.business.BusinessSecurity.java
/** * Se encarga de encriptar la contrasea ingresada por el usuario * *//*from w ww .j a va2s .c o m*/ public static String encrypt(String value) throws BusinessException { String secretKey = "e-business"; String base64EncryptedString = ""; try { 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 = value.getBytes("utf-8"); byte[] buf = cipher.doFinal(plainTextBytes); byte[] base64Bytes = Base64.encodeBase64(buf); base64EncryptedString = new String(base64Bytes); } catch (Exception ex) { throw new BusinessException(ex); } return base64EncryptedString; }
From source file:aes_encryption.AES_Encryption.java
public static void setKey(String myKey) { MessageDigest sha = null;/*from ww w. j a v a 2 s. co m*/ try { key = myKey.getBytes("UTF-8"); System.out.println(key.length); sha = MessageDigest.getInstance("SHA-1"); key = sha.digest(key); key = Arrays.copyOf(key, 16); //change the bits later 128 then 256 System.out.println(key.length); System.out.println(new String(key, "UTF-8")); secretKey = new SecretKeySpec(key, "AES"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:com.diversityarrays.util.CombinationsAndPermutations.java
static public <T> void combinations(T[] names, int nPerCombination, Closure<T[]> collector) { T[] namesBeforeNameIndex = Arrays.copyOf(names, nPerCombination); for (int i = 0; i < names.length; ++i) { namesBeforeNameIndex[0] = names[i]; combinations(namesBeforeNameIndex, 1, names, i + 1, collector); }// w w w .j a va 2s . com }
From source file:Main.java
public static byte[] growIfNecessary(byte[] array, int minLength, int numAdditionalBytes) { if (array.length >= minLength) { return array; }//from w w w. j a v a 2 s . c om return Arrays.copyOf(array, minLength + numAdditionalBytes); }
From source file:Main.java
static String[] getTransitionProperties(String[] parentTransitionProperties) { if (parentTransitionProperties == null || parentTransitionProperties.length == 0) { return new String[] { PROPNAME_ROUNDING_PROGRESS }; }/*from ww w . j a va2s. c o m*/ // ...and tack our own at the end String[] transitionProperties = Arrays.copyOf(parentTransitionProperties, parentTransitionProperties.length + 1); transitionProperties[transitionProperties.length - 1] = PROPNAME_ROUNDING_PROGRESS; return transitionProperties; }
From source file:Main.java
private static void skipStartCode(ByteBuffer prefixedSpsBuffer) { byte[] prefix3 = new byte[3]; prefixedSpsBuffer.get(prefix3);/*from w w w. ja v a2 s .c om*/ if (Arrays.equals(prefix3, AVC_START_CODE_3)) return; byte[] prefix4 = Arrays.copyOf(prefix3, 4); prefix4[3] = prefixedSpsBuffer.get(); if (Arrays.equals(prefix4, AVC_START_CODE_4)) return; throw new IllegalStateException("AVC NAL start code does not found in csd."); }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) public static int[] arrayCopyOf(int[] array, int length) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { return Arrays.copyOf(array, length); } else {//from w ww .j a va2s.c om int[] newArray = new int[length]; System.arraycopy(array, 0, newArray, 0, length); return newArray; } }