List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:at.jps.sanction.core.util.TokenTool.java
public static List<String> getTokenList(final String text, final String delimiters, final String deadCharacters, final int minlength, final Collection<String> excludeList, final boolean filterTokens) { final List<String> textTokens = new ArrayList<>(10); if ((text != null) && (text.length() > minlength)) { String oriText = text.toUpperCase(); // remove dead characters if (deadCharacters != null) { for (int i = 0; i < deadCharacters.length(); i++) { oriText = StringUtils.remove(oriText, deadCharacters.charAt(i)); // oriText.replace(deadCharacters.charAt(i), ' '); }/* ww w. j ava2s. co m*/ } // TODO: transliterate // remove stopwords - !! dead characters MUST NOT exist in stopwords !! // must be sorted by length !! if (!filterTokens) { if (excludeList != null) { for (final String stopword : excludeList) { oriText = oriText.replace(stopword.toUpperCase(), ""); } } } // maybe preserve original formatted text ? // StrTokenizer textTokenizer = new StrTokenizer(oriText, delimiters); // textTokenizer.setEmptyTokenAsNull(false); // textTokenizer.setIgnoreEmptyTokens(true); // feature !! if (delimiters != null) { final StringTokenizer textTokenizer = new StringTokenizer(oriText, delimiters); while (textTokenizer.hasMoreTokens()) { final String token = textTokenizer.nextToken().trim(); if ((token != null) && (token.length() >= minlength)) { // TODO: clear tokens ( deadchars...) if (filterTokens) { if ((excludeList == null) || (!excludeList.contains(token))) { if (!textTokens.contains(token)) { textTokens.add(token); } } } else { if (!textTokens.contains(token)) { textTokens.add(token); } } } } } else { textTokens.add(oriText); } } return textTokens; }
From source file:ClassPath.java
private static final void getPathComponents(String path, List list) { if (path != null) { StringTokenizer tok = new StringTokenizer(path, File.pathSeparator); while (tok.hasMoreTokens()) { String name = tok.nextToken(); File file = new File(name); if (file.exists()) { list.add(name);//from www .j av a 2 s .c o m } } } }
From source file:com.baifendian.swordfish.execserver.utils.OsUtil.java
public static Map<?, ?> cpuinfo() { InputStreamReader inputs = null; BufferedReader buffer = null; Map<String, Object> map = new HashMap<>(); try {//w ww. ja v a 2 s.co m inputs = new InputStreamReader(new FileInputStream("/proc/stat")); buffer = new BufferedReader(inputs); String line = ""; while (true) { line = buffer.readLine(); if (line == null) { break; } if (line.startsWith("cpu")) { StringTokenizer tokenizer = new StringTokenizer(line); List<String> temp = new ArrayList<>(); while (tokenizer.hasMoreElements()) { String value = tokenizer.nextToken(); temp.add(value); } map.put("user", temp.get(1)); map.put("nice", temp.get(2)); map.put("system", temp.get(3)); map.put("idle", temp.get(4)); map.put("iowait", temp.get(5)); map.put("irq", temp.get(6)); map.put("softirq", temp.get(7)); map.put("stealstolen", temp.get(8)); break; } } } catch (Exception e) { logger.error("get cpu usage error", e); } finally { try { buffer.close(); inputs.close(); } catch (Exception e) { logger.error("get cpu usage error", e); } } return map; }
From source file:ca.on.gov.jus.icon.common.util.JDBCUtils.java
/** * Checks a String for single-quote characters and escapes * them with another single-quote. This is necessary for any * String used as a parameter in an SQL query. * * @param parameter The String checked for single-quote characters. * @return The String with escaped single-quote characters. *//* w w w. j a va2 s . c om*/ static public String toDBString(String parameter) { final String delimiter = "'"; boolean returnDelims = true; StringBuffer buffer = null; StringTokenizer tokenizer = null; String dbString = null; if (parameter != null) { buffer = new StringBuffer(); tokenizer = new StringTokenizer(parameter, delimiter, returnDelims); // Iterater through each occurance or a single-quote. while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); buffer.append(token); // Check if the current token is the single-quote, // and escape it with another single-quote. if (token.equals(delimiter)) { buffer.append(delimiter); } } dbString = buffer.toString(); } return dbString; }
From source file:io.datenwelt.cargo.rest.utils.Rfc2047.java
public static String encodeHeader(String input) { StringTokenizer tokenizer = new StringTokenizer(input, "\t ,;:-/=+#*", true); CharsetEncoder charsetEncoder = Charset.forName(CharEncoding.ISO_8859_1).newEncoder(); QCodec qcodec = new QCodec(Charset.forName(CharEncoding.UTF_8)); StringBuilder encoded = new StringBuilder(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (!charsetEncoder.canEncode(token)) { try { encoded.append(qcodec.encode(token)); } catch (EncoderException ex) { LOG.debug("Skipping the Q encoding of header value for non ISO-8859-1 string: {}", input, ex); encoded.append(token);//from w w w .j a v a2 s .c o m } } else { encoded.append(token); } } return encoded.toString(); }
From source file:com.cloud.utils.UriUtils.java
private static List<NameValuePair> getUserDetails(String query) { List<NameValuePair> details = new ArrayList<NameValuePair>(); if (query != null && !query.isEmpty()) { StringTokenizer allParams = new StringTokenizer(query, "&"); while (allParams.hasMoreTokens()) { String param = allParams.nextToken(); details.add(new BasicNameValuePair(param.substring(0, param.indexOf("=")), param.substring(param.indexOf("=") + 1))); }/* w w w.j a va 2s . com*/ } return details; }
From source file:au.org.intersect.dms.bookinggw.impl.BookingGatewayServiceImpl.java
/** * Calculate initials from name parts.//w ww.ja v a 2 s . c om * * @param fname * the first name. * @param mname * the middle name. * @param lname * the last name. * @return initials */ private static String calculateInitials(String fname, String mname, String lname) { StringTokenizer tokenizer = new StringTokenizer(fname + SPACE + mname + SPACE + lname); StringBuffer sb = new StringBuffer(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.length() > 0) { sb.append(Character.toUpperCase(token.charAt(0))); } } return sb.toString(); }
From source file:elaborate.util.StringUtil.java
@SuppressWarnings("boxing") public static String replace(String originalTerm, String replacementTerm, String body, List<Integer> occurrencesToReplace, boolean preserveCase) { StringTokenizer tokenizer = new StringTokenizer(body, DELIM, true); // Log.info("body:[{}]", body); StringBuilder replaced = new StringBuilder(body.length()); int occurrence = 1; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); DelimiterDetector delimiterDetector = new DelimiterDetector(token); String strippedToken = delimiterDetector.getStripped(); if (strippedToken.equalsIgnoreCase(originalTerm)) { String replacement = preserveCase ? TextCase.detectCase(strippedToken).applyTo(replacementTerm) : replacementTerm;/* www .j av a2 s .co m*/ replaced.append(occurrencesToReplace.contains(occurrence) ? delimiterDetector.getPreDelimiters() + replacement + delimiterDetector.getPostDelimiters() : token); occurrence++; } else { replaced.append(token); } } // Log.info("replaced:[{}]", replaced); return replaced.toString(); }
From source file:I18NUtil.java
/** * Factory method to create a Locale from a <tt>lang_country_variant</tt> string. * /*w w w. j av a2 s . c o m*/ * @param localeStr e.g. fr_FR * @return Returns the locale instance, or the {@link Locale#getDefault() default} if the * string is invalid */ public static Locale parseLocale(String localeStr) { if (localeStr == null) { return null; } Locale locale = Locale.getDefault(); StringTokenizer t = new StringTokenizer(localeStr, "_"); int tokens = t.countTokens(); if (tokens == 1) { locale = new Locale(t.nextToken()); } else if (tokens == 2) { locale = new Locale(t.nextToken(), t.nextToken()); } else if (tokens == 3) { locale = new Locale(t.nextToken(), t.nextToken(), t.nextToken()); } return locale; }
From source file:com.meterware.httpunit.HttpUnitUtils.java
/** * Returns the content type and encoding as a pair of strings. * If no character set is specified, the second entry will be null. * @param header the header to parse//from w w w .j a va 2 s .co m * @return a string array with the content type and the content charset **/ public static String[] parseContentTypeHeader(String header) { String[] result = new String[] { "text/plain", null }; StringTokenizer st = new StringTokenizer(header, ";="); result[0] = st.nextToken(); while (st.hasMoreTokens()) { String parameter = st.nextToken(); if (st.hasMoreTokens()) { String value = stripQuotes(st.nextToken()); if (parameter.trim().equalsIgnoreCase("charset")) { result[1] = value; } } } return result; }