List of usage examples for java.util StringTokenizer StringTokenizer
public StringTokenizer(String str, String delim)
From source file:Main.java
/** * //from w w w .j a v a 2s .c o m * @param value * @return boolean[] */ public static boolean[] toBooleanArray(final String value) { if (value == null) { return new boolean[] {}; } final String strippedValue = value.replace(ARRAY_OPEN_TAG, EMPTY_STRING).replace(ARRAY_CLOSE_TAG, EMPTY_STRING); final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ELEMENT_SEPARATOR); final Collection<Boolean> intCollection = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { intCollection.add(Boolean.valueOf(tokenizer.nextToken().trim())); } return toBooleanArray(intCollection); }
From source file:ch.cyberduck.core.URIEncoder.java
/** * URL encode a path/*from w w w. j a v a 2 s.c om*/ * * @param p Path * @return URI encoded * @see java.net.URLEncoder#encode(String, String) */ public static String encode(final String p) { try { final StringBuilder b = new StringBuilder(); final StringTokenizer t = new StringTokenizer(p, "/"); if (!t.hasMoreTokens()) { return p; } if (StringUtils.startsWith(p, String.valueOf(Path.DELIMITER))) { b.append(Path.DELIMITER); } while (t.hasMoreTokens()) { b.append(URLEncoder.encode(t.nextToken(), "UTF-8")); if (t.hasMoreTokens()) { b.append(Path.DELIMITER); } } if (StringUtils.endsWith(p, String.valueOf(Path.DELIMITER))) { b.append(Path.DELIMITER); } // Because URLEncoder uses <code>application/x-www-form-urlencoded</code> we have to replace these // for proper URI percented encoding. return b.toString().replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); } catch (UnsupportedEncodingException e) { return p; } }
From source file:Main.java
/** * Creates a list of strings from a string within tokens. Empty tokens will * be omitted: If a string within tokens is <code>"a,,b,,c"</code> and the * delimiter string is <code>","</code>, the returned list of strings * contains the tree elements <code>"a", "b", "c"</code>. * * @param string String within tokens * @param delimiter Delimiter that separates the tokens. Every character * of the delimiter string is a separate delimiter. If * the string within tokens is <code>"I,like:ice"</code> * and the delimiter string is <code>",:"</code>, the * returned list of strings contains the three elements * <code>"I", "like", "ice"</code>. * @return List of strings/*ww w .jav a 2s . c o m*/ */ public static List<String> stringTokenToList(String string, String delimiter) { if (string == null) { throw new NullPointerException("string == null"); } if (delimiter == null) { throw new NullPointerException("delimiter == null"); } StringTokenizer tokenizer = new StringTokenizer(string, delimiter); List<String> list = new ArrayList<>(tokenizer.countTokens()); while (tokenizer.hasMoreTokens()) { list.add(tokenizer.nextToken()); } return list; }
From source file:com.kixeye.chassis.bootstrap.aws.UserData.java
public static UserData parse(String userData) { if (!StringUtils.isBlank(userData)) { StringTokenizer stringTokenizer = new StringTokenizer(userData, "\n"); while (stringTokenizer.hasMoreTokens()) { String line = stringTokenizer.nextToken(); int envStartIdx = line.indexOf(ENVIRONMENT_TEXT); if (envStartIdx >= 0) { String env = line.substring(envStartIdx + ENVIRONMENT_TEXT.length()); return new UserData(StringUtils.trimToNull(env)); }/* w w w . j av a2 s . com*/ } } throw new BootstrapException("Found no environment data in user-data " + userData); }
From source file:com.salesmanager.core.util.MerchantConfigurationUtil.java
/** * Strips all delimiters//from w ww . j a va 2s .c o m * * @param configurationLine * @return */ public static Collection getConfigurationList(String configurationLine, String delimiter) { List returnlist = new ArrayList(); StringTokenizer st = new StringTokenizer(configurationLine, delimiter); while (st.hasMoreTokens()) { String token = st.nextToken(); returnlist.add(token); } return returnlist; }
From source file:Main.java
/** * // w w w. j av a 2 s .c om * @param value * @return double[][] */ public static double[][] to2dDoubleArray(final String value) { final String strippedValue = value.replace(ARRAY_OPEN_TAG, EMPTY_STRING).replace(ARRAY_CLOSE_TAG, EMPTY_STRING); final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ARRAY_SEPARATOR); final double[][] array = new double[tokenizer.countTokens()][]; int i = 0; while (tokenizer.hasMoreTokens()) { array[i++] = toDoubleArray(tokenizer.nextToken()); } return array; }
From source file:org.apache.geode.geospatial.utils.ToolBox.java
public static void configureDefaultClientPool(ClientCacheFactory clientCacheFactory, String locators) { StringTokenizer stringTokenizer = new StringTokenizer(locators, ","); clientCacheFactory.setPoolMaxConnections(-1); clientCacheFactory.setPoolPRSingleHopEnabled(true); while (stringTokenizer.hasMoreTokens()) { String curr = stringTokenizer.nextToken(); DistributionLocatorId locatorId = new DistributionLocatorId(curr); String addr = locatorId.getBindAddress(); if (addr != null && addr.trim().length() > 0) { clientCacheFactory.addPoolLocator(addr, locatorId.getPort()); } else {/*ww w .ja va2s . c o m*/ clientCacheFactory.addPoolLocator(locatorId.getHost().getHostName(), locatorId.getPort()); } } clientCacheFactory.create(); }
From source file:com.vmware.identity.idm.STSSpnValidator.java
public static boolean validate(String spn) { // validate spn format, and service principal name and domain name are // valid strings. Validate.notNull(spn, "Service Princiapal Name cannot be null"); Validate.notEmpty(spn, "Service Principal Name cannot be empty"); StringTokenizer st = new StringTokenizer(spn, VALID_SPN_SEPARATORS); if (st.countTokens() != 2) { logAndThrow("Invalid service principal name format: " + spn); } else {//from w w w .j a v a 2 s . c om String servicePrincipalName = st.nextToken(); String domainName = st.nextToken(); if (null == servicePrincipalName) { logAndThrow(String.format("Service Name must be specfied before [%s]" + VALID_SPN_SEPARATORS)); } if (!servicePrincipalName.equalsIgnoreCase(SERVICE_PRINCIPAL_NAME)) { logAndThrow("Service name must be STS (case insensitive)"); } if (null == domainName || domainName.trim().isEmpty()) { logAndThrow(String.format("Domain Name must be specfied after [%s]" + VALID_SPN_SEPARATORS)); } } return true; }
From source file:Main.java
static byte[] decryptJWE(String jwe, Key privRsaKey) { // Log.d("","decryptJWE"); try {//w w w .ja v a 2 s. c o m // split jwe string StringTokenizer tokens = new StringTokenizer(jwe, "."); int count = tokens.countTokens(); // Log.d("","parts.length: "+count); if (count != 5) return null; String jweProtectedHeader64 = tokens.nextToken(); String jweEncrypted64 = tokens.nextToken(); String jweInitVector64 = tokens.nextToken(); String cryptedBytes64 = tokens.nextToken(); String auth_tag64 = tokens.nextToken(); // decrypt cek using private rsa key byte[] cek = decryptRsaB64(jweEncrypted64, privRsaKey); // check cek result byte array if (cek == null || cek.length == 0 || (cek.length % 2) != 0) return null; int keySize = cek.length / 2; Log.d("", "Decryption AES: " + keySize * 8); // build aes_key and hmac_key byte aes_key[] = new byte[keySize]; byte hmac_key[] = new byte[keySize]; System.arraycopy(cek, 0, hmac_key, 0, keySize); System.arraycopy(cek, keySize, aes_key, 0, keySize); // decode initialization vector byte[] iv_key = decodeB64(jweInitVector64); Log.d("", "hmac_key: " + bytesToHex(hmac_key)); Log.d("", "aes_key: " + bytesToHex(aes_key)); Log.d("", "iv_key: " + bytesToHex(iv_key)); // decrypt content using aes_key and iv_key byte[] cryptedBytes = decodeB64(cryptedBytes64); Cipher decrypt = Cipher.getInstance("AES/CBC/PKCS5Padding", "SC"); decrypt.init(Cipher.DECRYPT_MODE, new SecretKeySpec(aes_key, "AES"), new IvParameterSpec(iv_key)); byte[] decryptedBytes = decrypt.doFinal(cryptedBytes); Log.d("", "decryptedBytes:"); Log.d("", bytesToHex(decryptedBytes)); // validation verification byte[] aad = jweProtectedHeader64.getBytes(); long al = aad.length * 8; // concatenate aad, iv_key, cryptedBytes and al byte[] hmacData = new byte[aad.length + iv_key.length + cryptedBytes.length + 8]; int offset = 0; System.arraycopy(aad, offset, hmacData, 0, aad.length); offset += aad.length; System.arraycopy(iv_key, 0, hmacData, offset, iv_key.length); offset += iv_key.length; System.arraycopy(cryptedBytes, 0, hmacData, offset, cryptedBytes.length); offset += cryptedBytes.length; ByteBuffer buffer = ByteBuffer.allocate(8); buffer.putLong(al); System.arraycopy(buffer.array(), 0, hmacData, offset, 8); // compute hmac Mac hmac = Mac.getInstance("HmacSHA256", "SC"); hmac.init(new SecretKeySpec(hmac_key, "HmacSHA256")); byte[] hmacValue = hmac.doFinal(hmacData); // pick authentication tag byte[] authTag = Arrays.copyOf(hmacValue, 16); // validate authentication tag byte[] authTagRead = decodeB64(auth_tag64); for (int i = 0; i < 16; i++) { if (authTag[i] != authTagRead[i]) { Log.d("", "validation failed"); return decryptedBytes; } } Log.d("", "validation success"); // validation success return decryptedBytes; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.sonatype.nexus.perftest.RequestRate.java
private static int parseRate(String value) { StringTokenizer st = new StringTokenizer(value, " /"); int time = Integer.parseInt(st.nextToken()); TimeUnit unit = TimeUnit.valueOf(st.nextToken() + "S"); return (int) (unit.toMillis(1) / time); }