List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:com.idega.util.FileLocalizer.java
public static void readFile(File fileToRead, Properties props) { BufferedReader in = null;// w w w. ja v a 2s. c o m try { if (fileToRead.isFile()) { in = new BufferedReader(new FileReader(fileToRead)); String input = in.readLine(); StringTokenizer st; String a, b; while (input != null) { int index = input.indexOf(stringToFind); if (index > -1) { int i1 = input.indexOf("(", index); int i2 = input.indexOf(")", index); if (i2 > -1) { a = input.substring(i1 + 2, i2 - 1); b = ""; st = new StringTokenizer(a, "\","); if (st.hasMoreTokens()) { a = st.nextToken(); if (st.hasMoreTokens()) { b = st.nextToken(); } if (!props.containsKey(a)) { props.setProperty(a, b); // System.err.println(a+"="+b); } } } } input = in.readLine(); } // while ends } else { return; } } catch (Exception ex) { ex.printStackTrace(); } finally { IOUtils.closeQuietly(in); } }
From source file:ru.anr.base.tests.GlassfishLoader.java
/** * Note: This part of code is taken from Apache Ant CommandLine * implementation.//from w w w. j av a2s .c o m * * Crack a command line. * * @param toProcess * the command line to process. * @return the command line broken into strings. An empty or null toProcess * parameter results in a zero sized array. */ public static String[] translateCommandline(String toProcess) { if (toProcess == null || toProcess.length() == 0) { // no command? no string return new String[0]; } // parse with a simple finite state machine final int normal = 0; final int inQuote = 1; final int inDoubleQuote = 2; int state = normal; final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true); final ArrayList<String> result = new ArrayList<String>(); final StringBuilder current = new StringBuilder(); boolean lastTokenHasBeenQuoted = false; while (tok.hasMoreTokens()) { String nextTok = tok.nextToken(); switch (state) { case inQuote: if ("\'".equals(nextTok)) { lastTokenHasBeenQuoted = true; state = normal; } else { current.append(nextTok); } break; case inDoubleQuote: if ("\"".equals(nextTok)) { lastTokenHasBeenQuoted = true; state = normal; } else { current.append(nextTok); } break; default: if ("\'".equals(nextTok)) { state = inQuote; } else if ("\"".equals(nextTok)) { state = inDoubleQuote; } else if (" ".equals(nextTok)) { if (lastTokenHasBeenQuoted || current.length() != 0) { result.add(current.toString()); current.setLength(0); } } else { current.append(nextTok); } lastTokenHasBeenQuoted = false; break; } } if (lastTokenHasBeenQuoted || current.length() != 0) { result.add(current.toString()); } if (state == inQuote || state == inDoubleQuote) { throw new ApplicationException("unbalanced quotes in " + toProcess); } return result.toArray(new String[result.size()]); }
From source file:de.xwic.sandbox.base.model.StringUtil.java
/** * @param strToSplit/*from w ww . j a v a2 s .c om*/ * @param tokens * @return */ public static List<String> splitString(String strToSplit, String tokens) { List<String> result = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(strToSplit, tokens); while (st.hasMoreTokens()) { result.add(st.nextToken()); } return result; }
From source file:com.thoughtworks.go.util.SelectorUtils.java
/** * Breaks a path up into a Vector of path elements, tokenizing on * * @param path Path to tokenize. Must not be <code>null</code>. * @param separator the separator against which to tokenize. * * @return a Vector of path elements from the tokenized path * @since Ant 1.6//from ww w . j av a 2 s . co m */ public static Vector tokenizePath(String path, String separator) { Vector ret = new Vector(); if (FileUtil.isAbsolutePath(path)) { String[] s = FileUtil.dissect(path); ret.add(s[0]); path = s[1]; } StringTokenizer st = new StringTokenizer(path, separator); while (st.hasMoreTokens()) { ret.addElement(st.nextToken()); } return ret; }
From source file:ch.entwine.weblounge.common.impl.request.Http11ProtocolHandler.java
/** * Method matchETag.//from w ww .ja v a 2 s .co m * * @param eTag * @param eTagList * @return boolean */ protected static boolean matchETag(String eTag, String eTagList) { if (eTagList == null || eTag == null) return false; String s = null; StringTokenizer t = new StringTokenizer(eTagList, ","); while (t.hasMoreTokens()) { s = t.nextToken().trim(); if ("*".equals(s) || s.equals(eTag)) return true; } return false; }
From source file:eu.thecoder4.gpl.pleftdroid.PleftBroker.java
/** * @return//from w w w . j a v a2s. c om */ protected static Map<String, String> getParamsFromURL(String url) { String hostpart = url.substring(0, url.lastIndexOf("/")); String valpart = url.substring(url.indexOf("?") + 1); StringTokenizer st = new StringTokenizer(valpart, "&"); Map<String, String> arr = new HashMap<String, String>(); arr.put("pserver", hostpart); while (st.hasMoreTokens()) { String pair = st.nextToken(); String lhs = pair.substring(0, pair.indexOf("=")); String rhs = pair.substring(pair.indexOf("=") + 1); arr.put(lhs, rhs); } return arr; }
From source file:gov.nih.nci.evs.browser.utils.ViewInHierarchyUtils.java
public static Vector<String> parseData(String line, String tab) { if (line == null) return null; Vector data_vec = new Vector(); StringTokenizer st = new StringTokenizer(line, tab); while (st.hasMoreTokens()) { String value = st.nextToken(); if (value.compareTo("null") == 0) value = " "; data_vec.add(value);/*from w w w . j av a 2 s .c om*/ } return data_vec; }
From source file:com.maverick.http.HttpClient.java
public static boolean isNonProxiedHost(String host) { String nonProxiedHosts = System.getProperty("com.maverick.ssl.https.HTTPProxyNonProxyHosts"); //$NON-NLS-1$ if (nonProxiedHosts == null || nonProxiedHosts.equals("")) { //$NON-NLS-1$ return false; }/*from w w w .j av a 2s.co m*/ StringTokenizer t = new StringTokenizer(nonProxiedHosts, "|"); //$NON-NLS-1$ while (t.hasMoreTokens()) { String token = t.nextToken(); int idx = token.indexOf('*'); if (idx != -1) { if (token.length() == 1) { return true; } String before = token.substring(0, idx); String after = token.substring(idx + 1); if (((before.length() == 0) || host.startsWith(before)) && ((after.length() == 0) || host.endsWith(after))) { return true; } } else { if (host.equalsIgnoreCase(token)) { return true; } } } return false; }
From source file:fr.paris.lutece.portal.service.util.AppPathService.java
/** * Gets available virtual hosts defined in the config.properties * * @return A reference list containing the key and the description of each * virtual host configuration. The list is empty if there is no * configuration defined./*from w w w .ja v a2s . co m*/ */ public static ReferenceList getAvailableVirtualHosts() { ReferenceList list = null; // Get keys list form config.properties String strKeysList = AppPropertiesService.getProperty(PROPERTY_VIRTUAL_HOST_KEYS); if (strKeysList != null) { list = new ReferenceList(); // Extracts each key (separated by a comma) StringTokenizer strTokens = new StringTokenizer(strKeysList, ","); while (strTokens.hasMoreTokens()) { String strHostKey = strTokens.nextToken(); String strHostKeyDescription = AppPropertiesService .getProperty(PROPERTY_VIRTUAL_HOST + strHostKey + SUFFIX_DESCRIPTION); list.addItem(strHostKey, strHostKeyDescription); } } return list; }
From source file:de.micromata.genome.util.text.TextSplitterUtils.java
/** * Verwendet einen StringTokenizer und liefert das Ergebnis als Liste. * * @param text the text//from w w w. j a v a 2 s . co m * @param delimiter the delimiter * @param returnDelimiter the return delimiter * @return the list */ public static List<String> parseStringTokens(String text, String delimiter, boolean returnDelimiter) { List<String> result = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(text != null ? text : "", delimiter, returnDelimiter); while (st.hasMoreTokens() == true) { result.add(st.nextToken()); } return result; }