List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:Urls.java
/** * Returns the time when the document should be considered expired. * The time will be zero if the document always needs to be revalidated. * It will be <code>null</code> if no expiration time is specified. */// w ww . j a v a 2s.co m public static Long getExpiration(URLConnection connection, long baseTime) { String cacheControl = connection.getHeaderField("Cache-Control"); if (cacheControl != null) { StringTokenizer tok = new StringTokenizer(cacheControl, ","); while (tok.hasMoreTokens()) { String token = tok.nextToken().trim().toLowerCase(); if ("must-revalidate".equals(token)) { return new Long(0); } else if (token.startsWith("max-age")) { int eqIdx = token.indexOf('='); if (eqIdx != -1) { String value = token.substring(eqIdx + 1).trim(); int seconds; try { seconds = Integer.parseInt(value); return new Long(baseTime + seconds * 1000); } catch (NumberFormatException nfe) { logger.warning("getExpiration(): Bad Cache-Control max-age value: " + value); // ignore } } } } } String expires = connection.getHeaderField("Expires"); if (expires != null) { try { synchronized (PATTERN_RFC1123) { Date expDate = PATTERN_RFC1123.parse(expires); return new Long(expDate.getTime()); } } catch (java.text.ParseException pe) { int seconds; try { seconds = Integer.parseInt(expires); return new Long(baseTime + seconds * 1000); } catch (NumberFormatException nfe) { logger.warning("getExpiration(): Bad Expires header value: " + expires); } } } return null; }
From source file:com.intel.iotkitlib.utils.Utilities.java
public static Map.Entry<String, ?> getSensorMatch(String componentName) { Boolean found = false;/* w w w. jav a 2s . co m*/ Map.Entry<String, ?> sensorMatch = null; Map<String, ?> preferencesAll = Utilities.sharedPreferences.getAll(); for (Map.Entry<String, ?> entry : preferencesAll.entrySet()) { Log.d(TAG, entry.getKey() + " :" + entry.getValue().toString()); if (entry.getKey().contains("sensor")) { StringTokenizer tokenizer = new StringTokenizer(entry.getKey(), "-"); while (tokenizer.hasMoreElements()) { if (tokenizer.nextToken().equals(componentName)) { Log.d(TAG, "sensor/component found in shared preferences"); found = true; sensorMatch = entry; break; } } if (found) { break; } } } return sensorMatch; }
From source file:com.enonic.esl.io.FileUtil.java
public static String getFileName(FileItem fileItem) { String fileName = fileItem.getName(); StringTokenizer nameTokenizer = new StringTokenizer(fileName, "\\/:"); while (nameTokenizer.hasMoreTokens()) { fileName = nameTokenizer.nextToken(); }/*w w w . ja v a2 s.co m*/ return fileName; }
From source file:com.bluexml.side.framework.alfresco.shareLanguagePicker.LanguageSetter.java
private static String getLanguageFromBrowser(HttpServletRequest req) { // set language locale from browser header String acceptLang = req.getHeader(ACCEPT_LANGUAGE); String language = null;/* ww w. jav a2s. c om*/ if (acceptLang != null && acceptLang.length() != 0) { StringTokenizer t = new StringTokenizer(acceptLang, ",; "); // get language and convert to java locale format language = t.nextToken().replace('-', '_'); } else { language = Locale.getDefault().getLanguage(); } return language; }
From source file:fr.cls.atoll.motu.library.converter.jaxb.LocaleAdapter.java
/** * Tokenize the given String into a String array via a StringTokenizer. * <p>//from ww w.ja va 2 s .co m * The given delimiters string is supposed to consist of any number of delimiter characters. Each of those * characters can be used to separate tokens. A delimiter is always a single character; for * multi-character delimiters, consider using <code>delimitedListToStringArray</code> * * @param str the String to tokenize * @param delimiters the delimiter characters, assembled as String (each of those characters is * individually considered as delimiter) * @param trimTokens trim the tokens via String's <code>trim</code> * @param ignoreEmptyTokens omit empty tokens from the result array (only applies to tokens that are empty * after trimming; StringTokenizer will not consider subsequent delimiters as token in the * first place). * @return an array of the tokens (<code>null</code> if the input String was <code>null</code>) * @see java.util.StringTokenizer * @see java.lang.String#trim() * @see #delimitedListToStringArray */ private static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) { if (str == null) { return null; } StringTokenizer st = new StringTokenizer(str, delimiters); List tokens = new ArrayList(); while (st.hasMoreTokens()) { String token = st.nextToken(); if (trimTokens) { token = token.trim(); } if (!ignoreEmptyTokens || token.length() > 0) { tokens.add(token); } } return (String[]) tokens.toArray(new String[tokens.size()]); }
From source file:Main.java
/** * parses comma or space separated list. A null return value means a wildcard. * /* ww w .j av a2 s . co m*/ * @return List of tokens or null if the commaSeparatedListText is null, '*', or empty */ public static List<String> parseCommaSeparatedList(final String commaSeparatedListText) { List<String> entries = null; if (commaSeparatedListText != null && !"*".equals(commaSeparatedListText)) { final StringTokenizer tokenizer = new StringTokenizer(commaSeparatedListText, ", "); while (tokenizer.hasMoreTokens()) { if (entries == null) { entries = new ArrayList<String>(); } entries.add(tokenizer.nextToken()); } } return entries; }
From source file:Main.java
/** * Remove an element using XPath-quotation expressions. Path must not including * the context element, path elements can be separated by / or ., * and namespace is NOT supported./*from ww w . j a v a 2 s .c o m*/ * @param context Element to start the search from, cannot be null. * @param path XPath-quotation expression, cannot be null. * @return the removed element if there are matches, otherwise * return null. */ public static Element removeElementByPath(Element context, String path) { Element cur = context; StringTokenizer tokens = new StringTokenizer(path, "/"); String name = null; while (tokens.hasMoreTokens()) { name = tokens.nextToken(); cur = getElementByPath(cur, name); if (cur == null) { return null; } } if (name != null) { Element parent = (Element) cur.getParentNode(); return removeChildElement(parent, name); } return null; }
From source file:edu.umd.cfar.lamp.viper.geometry.Ellipse.java
/** * Constructs a new ellipse from the given string * @param S the string to parse - a space delimited list of four integers * @return the Ellipse represented by the string. * @throws BadAttributeDataException//from w ww .ja v a 2s.c o m */ public static Ellipse valueOf(String S) { try { StringTokenizer st = new StringTokenizer(S); return new Ellipse(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())); } catch (NoSuchElementException e1) { throw new BadAttributeDataException("Not enough integers for ellipse: " + S); } catch (NumberFormatException e2) { throw new BadAttributeDataException("Malformed ellipse string: " + S); } }
From source file:BitLottoVerify.java
public static Map<String, Long> getPaymentsBlockExplorer(String addr) throws Exception { URL u = new URL("http://blockexplorer.com/address/" + addr); Scanner scan = new Scanner(u.openStream()); TreeMap<String, Long> map = new TreeMap<String, Long>(); while (scan.hasNextLine()) { String line = scan.nextLine(); StringTokenizer stok = new StringTokenizer(line, "\"#"); while (stok.hasMoreTokens()) { String token = stok.nextToken(); if (token.startsWith("/tx/")) { String tx = token.substring(4); line = scan.nextLine();/*from w w w . j av a 2 s . co m*/ line = scan.nextLine(); StringTokenizer stok2 = new StringTokenizer(line, "<>"); stok2.nextToken(); double amt = Double.parseDouble(stok2.nextToken()); long amt_l = (long) Math.round(amt * 1e8); map.put(tx, amt_l); } } } return map; }
From source file:com.buaa.cfs.security.ShellBasedUnixGroupsMapping.java
/** * Get the current user's group list from Unix by running the command 'groups' NOTE. For non-existing user it will * return EMPTY list//w w w . ja va2 s. c om * * @param user user name * * @return the groups list that the <code>user</code> belongs to. The primary group is returned first. * * @throws IOException if encounter any error when running the command */ private static List<String> getUnixGroups(final String user) throws IOException { String result = ""; try { result = Shell.execCommand(Shell.getGroupsForUserCommand(user)); } catch (Shell.ExitCodeException e) { // if we didn't get the group - just return empty list; LOG.warn("got exception trying to get groups for user " + user + ": " + e.getMessage()); return new LinkedList<String>(); } StringTokenizer tokenizer = new StringTokenizer(result, Shell.TOKEN_SEPARATOR_REGEX); List<String> groups = new LinkedList<String>(); while (tokenizer.hasMoreTokens()) { groups.add(tokenizer.nextToken()); } // remove duplicated primary group if (!Shell.WINDOWS) { for (int i = 1; i < groups.size(); i++) { if (groups.get(i).equals(groups.get(0))) { groups.remove(i); break; } } } return groups; }