List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:com.gistlabs.mechanize.impl.MechanizeInitializer.java
static List<String> getClassNames(final String forSystemProperty, final String orDefaultValue) { List<String> result = new ArrayList<String>(); String propertyValue = System.getProperty(forSystemProperty); if (propertyValue == null || "".equals(propertyValue)) propertyValue = orDefaultValue;//from ww w .j a v a 2 s. c o m StringTokenizer tokenizer = new StringTokenizer(propertyValue, ","); while (tokenizer.hasMoreTokens()) result.add(tokenizer.nextToken().trim()); return result; }
From source file:Main.java
public static void initializeIrregularVerbMap() { try {/*from ww w . ja v a2s.co m*/ BufferedReader reader = new BufferedReader(new FileReader(new File(FILE_NAME_IRREGULAR_VERB))); String line = null; while ((line = reader.readLine()) != null) { StringTokenizer tokenizer = new StringTokenizer(line, "\t\n", false); String root = null; if (tokenizer.hasMoreTokens()) root = tokenizer.nextToken().trim(); while (tokenizer.hasMoreTokens()) { irregularVerbMap.put(tokenizer.nextToken().trim(), root); } } } catch (FileNotFoundException e) { System.out.println("File not found in the system."); } catch (IOException e1) { System.out.println("IOException"); } }
From source file:Main.java
private static String[] split(String s, String delim, boolean includeDelim) { StringTokenizer tok = new StringTokenizer(s, delim, includeDelim); String[] parts = new String[tok.countTokens()]; for (int i = 0; tok.hasMoreTokens(); i++) { parts[i] = tok.nextToken();// w ww.j a v a2 s . c o m } return parts; }
From source file:Main.java
protected static List<String> splitTrimmed(String text, String separator) { List<String> parts = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(text, separator); while (st.hasMoreTokens()) { String token = st.nextToken().trim(); if (token.length() > 0) { parts.add(token);//from ww w .ja va 2s. co m } } return parts; }
From source file:Main.java
protected static String replaceNewLineWithLineBreak(String source) { String str = null;/*from w ww . j a v a 2 s .c o m*/ if (source != null) { StringBuffer sbuffer = new StringBuffer(); StringTokenizer tkzer = new StringTokenizer(source, "\n", true); String token = null; while (tkzer.hasMoreTokens()) { token = tkzer.nextToken(); if ("\n".equals(token)) { sbuffer.append("<text:line-break/>"); } else { sbuffer.append(token); } } str = sbuffer.toString(); } return str; }
From source file:Main.java
public static String decodePath(String path, String delimiter, String characterSet) throws UnsupportedEncodingException { final StringTokenizer tokenizer = new StringTokenizer(path, delimiter); final StringBuilder builder = new StringBuilder(path.length()); while (tokenizer.hasMoreTokens()) { builder.append(URLDecoder.decode(tokenizer.nextToken(), characterSet)); builder.append(delimiter);//from ww w . j a v a 2s.c om } builder.delete(builder.length() - delimiter.length(), builder.length()); return builder.toString(); }
From source file:Main.java
public static String encodePath(String path, String delimiter, String characterSet) throws UnsupportedEncodingException { final StringTokenizer tokenizer = new StringTokenizer(path, delimiter); final StringBuilder builder = new StringBuilder(path.length()); while (tokenizer.hasMoreTokens()) { builder.append(URLEncoder.encode(tokenizer.nextToken(), characterSet)); builder.append(delimiter);//w ww .j av a 2s . c o m } builder.delete(builder.length() - delimiter.length(), builder.length()); return builder.toString(); }
From source file:Main.java
public static String[] split(final String string, final String tag) { StringTokenizer str = new StringTokenizer(string, tag); String[] result = new String[str.countTokens()]; int index = 0; for (; str.hasMoreTokens();) { result[index++] = str.nextToken(); }/*from w ww . jav a2s . c o m*/ return result; }
From source file:Main.java
public static String encodeUrl(String url, String charset) throws UnsupportedEncodingException { if (url == null) { return ""; }/* www .j a v a 2 s .c om*/ int index = url.indexOf("?"); if (index >= 0) { String result = url.substring(0, index + 1); String paramsPart = url.substring(index + 1); StringTokenizer tokenizer = new StringTokenizer(paramsPart, "&"); while (tokenizer.hasMoreTokens()) { String definition = tokenizer.nextToken(); int eqIndex = definition.indexOf("="); if (eqIndex >= 0) { String paramName = definition.substring(0, eqIndex); String paramValue = definition.substring(eqIndex + 1); result += paramName + "=" + encodeUrlParam(paramValue, charset) + "&"; } else { result += encodeUrlParam(definition, charset) + "&"; } } if (result.endsWith("&")) { result = result.substring(0, result.length() - 1); } return result; } return url; }
From source file:Main.java
/** * gets the character encoding from the String representation of an XML file. * @param sXml// w ww . ja v a 2s .c o m * @return the encoding specified in the String, or "UTF-8" (default encoding for XML files) if none is specified. * @postcondition result != null */ public static String getXMLEncoding(String sXml) { final int iEncodingStart = sXml.indexOf("encoding="); String result = null; if (iEncodingStart > 0) { final String encbuf = sXml.substring(iEncodingStart); final StringTokenizer tokenizer = new StringTokenizer(encbuf, "\"'", true); boolean encfound = false; while (tokenizer.hasMoreTokens()) { sXml = tokenizer.nextToken(); if (sXml.equals("'") || sXml.equals("\"")) { encfound = true; } else { if (encfound) { result = sXml; break; } } } } if (result == null) { result = "UTF-8"; } assert result != null; return result; }