List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:Main.java
/** * A method for gluing byte lists.// ww w . j ava2s . c o m * * @param first * the first array. * @param rest * the rest of the arrays. * @return */ public static byte[] arrCat(byte[] first, byte[]... rest) { int ttlLen = first.length; for (byte[] arr : rest) { ttlLen += arr.length; } byte[] result = Arrays.copyOf(first, ttlLen); int currOfst = first.length; for (byte[] arr : rest) { System.arraycopy(arr, 0, result, currOfst, arr.length); currOfst += arr.length; } return result; }
From source file:net.michaelpigg.xbeelib.protocol.XbeeAddress.java
public static XbeeAddress getAddress(byte[] address) { final byte[] addrBytes; if (address.length == 1) { addrBytes = new byte[] { 0x0, address[0] }; } else if (address.length == 2) { addrBytes = Arrays.copyOf(address, 2); } else if (address.length == 8) { addrBytes = Arrays.copyOf(address, 8); } else {// w w w .j a v a 2 s. c o m throw new IllegalArgumentException("Xbee addresses must either be 64 bit or 16 bit addresses."); } return (addrBytes.length == 8) ? new XbeeAddress64(addrBytes) : new XbeeAddress16(addrBytes); }
From source file:com.juicioenlinea.application.secutiry.Security.java
public static String encriptar(String texto) { final String secretKey = "hunter"; //llave para encriptar datos String encryptedString = null; try {/*w w w .j av a 2 s . c o m*/ MessageDigest md = MessageDigest.getInstance("SHA"); 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); encryptedString = new String(base64Bytes); } catch (NoSuchAlgorithmException | UnsupportedEncodingException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) { Logger.getLogger(Security.class.getName()).log(Level.SEVERE, null, ex); } return encryptedString; }
From source file:Main.java
public static String getParentMediaID(String mediaID) { String[] hierarchy = getHierarchy(mediaID); if (!isBrowseable(mediaID)) { return createMediaID(null, hierarchy); }// www .j a v a 2 s. c om if (hierarchy == null || hierarchy.length <= 1) { return MEDIA_ID_ROOT; } String[] parentHierarchy = Arrays.copyOf(hierarchy, hierarchy.length - 1); return createMediaID(null, parentHierarchy); }
From source file:Main.java
public static String getParentMediaID(String mediaID) { String[] hierarchy = getHierarchy(mediaID); if (!isBrowseable(mediaID)) { return createMediaID(null, hierarchy); }/*from w ww . j a v a 2 s .co m*/ if (hierarchy.length <= 1) { return MEDIA_ID_ROOT; } String[] parentHierarchy = Arrays.copyOf(hierarchy, hierarchy.length - 1); return createMediaID(null, parentHierarchy); }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Unique.java
/** * Uniques the data, duplicates are removed based on bitwise comparison of data. * @param data int[] the data to unique/*www . ja va 2 s. co m*/ * @return the int[] uniqued data */ public static int[] bitwise(int[] data) { Validate.notNull(data); int n = data.length; int[] sorteddata = Sort.stateless(data); int j = 0; for (int i = 1; i < n; i++) { if (sorteddata[i] != sorteddata[j]) { j++; sorteddata[j] = sorteddata[i]; } } return Arrays.copyOf(sorteddata, j + 1); }
From source file:Main.java
public static String getParentMediaID(@NonNull String mediaID) { String[] hierarchy = getHierarchy(mediaID); if (!isBrowseable(mediaID)) { return createMediaID(null, hierarchy); }/* w w w.j a v a2s . c om*/ if (hierarchy.length <= 1) { return MEDIA_ID_ROOT; } String[] parentHierarchy = Arrays.copyOf(hierarchy, hierarchy.length - 1); return createMediaID(null, parentHierarchy); }
From source file:Main.java
public static int[] growIfNecessary(int[] array, int minLength, int numAdditionalInts) { if (array.length >= minLength) { return array; }// www. j a va 2 s . c o m return Arrays.copyOf(array, minLength + numAdditionalInts); }
From source file:com.formatAdmin.utils.UtilsSecurity.java
public static String cifrarMD5(String texto) { String base64EncryptedString = ""; try {//from ww w .j ava2s. c o m MessageDigest md = MessageDigest.getInstance("MD5"); byte[] digestOfPassword = md.digest(SECRET_MD5_KEY.getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); SecretKey key = new SecretKeySpec(keyBytes, ENCRYPT_ALGORITHM); Cipher cipher = Cipher.getInstance(ENCRYPT_ALGORITHM); 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 (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException | BadPaddingException | IllegalBlockSizeException | NoSuchPaddingException ex) { } return base64EncryptedString; }
From source file:Main.java
public final static char[] safeTrim(final char[] ca, final int len) { if (len == ca.length) { return ca; } else {/* w w w. jav a 2s. com*/ return Arrays.copyOf(ca, len); } }