List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:com.vmware.identity.rest.core.client.URIFactory.java
@SuppressWarnings("unchecked") public static URI buildURI(HostRetriever host, String path, Object... args) throws ClientException { Map<String, Object> parameters = null; if (args != null) { if (args[args.length - 1] instanceof Map) { parameters = (Map<String, Object>) args[args.length - 1]; args = Arrays.copyOf(args, args.length - 1); }/*from w w w. ja va 2s. c o m*/ } URIBuilder builder = host.getURIBuilder().setPath(String.format(path, args)); if (parameters != null && !parameters.isEmpty()) { for (Entry<String, Object> param : parameters.entrySet()) { if (param.getValue() instanceof Collection) { Collection<Object> list = (Collection<Object>) param.getValue(); Iterator<Object> iter = list.iterator(); while (iter.hasNext()) { builder.setParameter(param.getKey(), iter.next().toString()); } } else { builder.setParameter(param.getKey(), param.getValue().toString()); } } } try { return builder.build(); } catch (URISyntaxException e) { throw new ClientException("An error occurred while building the URI", e); } }
From source file:co.mitro.twofactor.TwoFactorSecretGenerator.java
public static String generateSecretKey() { byte[] buffer = new byte[SECRET_SIZE]; secureRandom.nextBytes(buffer);/*from w w w. j a v a2 s . c om*/ Base32 codec = new Base32(); byte[] secretKey = Arrays.copyOf(buffer, SECRET_SIZE); byte[] bEncodedKey = codec.encode(secretKey); String encodedKey = new String(bEncodedKey, Charsets.UTF_8); return encodedKey; }
From source file:de.erdesignerng.visual.Java3DUtils.java
private static void addLibraryPath(String pathToAdd) throws Exception { Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths"); usrPathsField.setAccessible(true);//from ww w . j a v a 2 s . c o m //get array of paths String[] paths = (String[]) usrPathsField.get(null); //check if the path to add is already present for (String path : paths) { if (path.equals(pathToAdd)) { return; } } //add the new path String[] newPaths = Arrays.copyOf(paths, paths.length + 1); newPaths[newPaths.length - 1] = pathToAdd; usrPathsField.set(null, newPaths); }
From source file:edu.zipcloud.cloudstreetmarket.core.util.ValidatorUtil.java
public static <T> Map<String, String> validate(T object, Class<?>... groups) { Class<?>[] args = Arrays.copyOf(groups, groups.length + 1); args[groups.length] = Default.class; return extractViolations(validator.validate(object, args)); }
From source file:Main.java
/** * Inserts an element into the array at the specified index, growing the array if there is no * more room.// w ww .j ava 2 s .co m * * @param array The array to which to append the element. Must NOT be null. * @param currentSize The number of elements in the array. Must be less than or equal to * array.length. * @param element The element to insert. * @return the array to which the element was appended. This may be different than the given * array. */ public static <T> T[] insert(T[] array, int currentSize, int index, T element) { assert currentSize <= array.length; if (currentSize + 1 <= array.length) { System.arraycopy(array, index, array, index + 1, currentSize - index); array[index] = element; return array; } @SuppressWarnings("unchecked") int newLength = growSize(currentSize); T[] newArray = Arrays.copyOf(array, newLength); // ArrayUtils.newUnpaddedArray((Class<T>)array.getClass().getComponentType(), // growSize(currentSize)); // System.arraycopy(array, 0, newArray, 0, index); newArray[index] = element; System.arraycopy(array, index, newArray, index + 1, array.length - index); return newArray; }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sort.java
/** * Sorts values statelessly in ascending order * @param v1 the values to sort (a native backed array) * @return tmp the sorted values/*from w ww .jav a 2s. c om*/ */ public static long[] stateless(long[] v1) { Validate.notNull(v1); long[] tmp = Arrays.copyOf(v1, v1.length); Arrays.sort(tmp); return tmp; }
From source file:com.yeetor.util.Util.java
public static byte[] mergeArray(byte[] a1, byte[] a2) { byte[] arr = Arrays.copyOf(a1, a1.length + a2.length); System.arraycopy(a2, 0, arr, a1.length, a2.length); return arr;//from w ww.ja va2s .c o m }
From source file:Main.java
/** * Returns an MD-5 digest of the database encryption password. * <blockquote>This algorithm performs an MD-5 hash on a UTF-8 representation of the password.</blockquote> * * @param pass The plain encryption password * * @return The database encryption password digest * * @throws NoSuchAlgorithmException If the platform doesn't support MD-5 */// ww w.j a v a 2s .com public static byte[] passToDigest(char[] pass) throws NoSuchAlgorithmException { // FIXME: Enhance security for this method Charset cs = Charset.forName("UTF-8"); MessageDigest md = MessageDigest.getInstance("MD5"); ByteBuffer bbuf = cs.encode(CharBuffer.wrap(pass)); byte[] bpass = Arrays.copyOf(bbuf.array(), bbuf.remaining()); return md.digest(bpass); }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.builder.AbstractBuilder.java
public static String encodeKeyBuffer(StaticBuffer input) { if (input == null || input.length() == 0) { return null; }/* www . j a v a 2s. c o m*/ ByteBuffer buf = input.asByteBuffer(); byte[] bytes = Arrays.copyOf(buf.array(), buf.limit()); return Hex.encodeHexString(bytes); }
From source file:Main.java
/** * Processes the given command + arguments and crafts a valid array of * arguments as expected by {@link #execve(String, String[], String[])}. * * @param command the command to run, cannot be <code>null</code>; * @param arguments the command line arguments, can be <code>null</code>. * @return a new arguments array, never <code>null</code>. *//*from w w w. j ava2 s . c o m*/ private static String[] processArgv(String command, String[] arguments) { final String[] argv; if (arguments == null) { argv = new String[] { command }; } else { if (!command.equals(arguments[0])) { argv = new String[arguments.length + 1]; argv[0] = command; System.arraycopy(arguments, 0, argv, 1, arguments.length); } else { argv = Arrays.copyOf(arguments, arguments.length); } } return argv; }