List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:com.googlecode.jcimd.charset.GsmCharsetProvider.java
private static int init(BufferedReader reader) throws IOException { String line = null;/*from www . j a va2 s . co m*/ int count = 0; while ((line = reader.readLine()) != null) { if (line.startsWith("#")) { if (logger.isTraceEnabled()) { logger.trace("Skipping line starting with '#': " + line); } continue; } StringTokenizer tokenizer = new StringTokenizer(line, "\t"); String hex1 = null; String hex2 = null; if (tokenizer.hasMoreTokens()) { hex1 = tokenizer.nextToken(); } if (tokenizer.hasMoreTokens()) { hex2 = tokenizer.nextToken(); } if (hex1 == null || hex2 == null) { continue; } int bite = Integer.parseInt(hex1.substring(2), 16); byte index = (byte) (bite & 0xFF); char ch = (char) Integer.parseInt(hex2.substring(2), 16); CHAR_TO_BYTE_SMALL_C_CEDILLA[ch] = bite; if ((bite & 0xFF00) >> 8 == ESCAPE) { // escape to extension table BYTE_TO_CHAR_ESCAPED_DEFAULT[index] = ch; if (logger.isTraceEnabled()) { logger.trace(String.format("(escaped) %d == %s", index, (ch != 10 && ch != 12 && ch != 13) ? ch : (ch == 10 ? "\\n" : (ch == 12 ? "0x0C (form feed)" : "\\r")))); } } else { BYTE_TO_CHAR_SMALL_C_CEDILLA[index] = ch; if (logger.isTraceEnabled()) { logger.trace(String.format("%d == %s", index, (ch != 10 && ch != 13) ? ch : (ch == 10 ? "\\n" : "\\r"))); } } count++; } if (count < 128 && logger.isWarnEnabled()) { logger.warn("Character look-up initialized with only " + count + " value(s) (expecting 128 values)"); } return count; }
From source file:net.pms.formats.v2.SubtitleUtils.java
/** * Converts subtitle timing string to seconds. * * @param timingString in format OO:00:00.000 * @return seconds or null if conversion failed *//*from w w w .ja va 2s .c o m*/ static Double convertSubtitleTimingStringToTime(final String timingString) throws NumberFormatException { if (isBlank(timingString)) { throw new IllegalArgumentException("timingString should not be blank."); } final StringTokenizer st = new StringTokenizer(timingString, ":"); try { int h = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); double s = Double.parseDouble(replace(st.nextToken(), ",", ".")); if (h >= 0) { return h * 3600 + m * 60 + s; } else { return h * 3600 - m * 60 - s; } } catch (NumberFormatException nfe) { logger.debug("Failed to convert timing string \"" + timingString + "\"."); throw nfe; } }
From source file:ch.cyberduck.core.URIEncoder.java
/** * URL encode a path//from ww w . ja va2 s .c o m * * @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:com.collabnet.ccf.pi.qc.v90.QCRequirement.java
public static List<String> getFieldValues(String fieldValue) { List<String> fieldValues = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(fieldValue, ";"); while (st.hasMoreTokens()) { String thisFieldValue = st.nextToken(); fieldValues.add(thisFieldValue); }/*from w w w . j a v a 2 s . c o m*/ return fieldValues; }
From source file:com.salesmanager.core.service.common.impl.ModuleManagerImpl.java
/** * Properties are 1) Production(1) - Test(2) 2) Pre-Auth(1) - Capture (2) - * Sale (0) 3) No CCV (1) - With CCV (2) * /*from w w w . j av a2 s . co m*/ * @param configvalue * @return */ public static IntegrationProperties stripProperties(String configvalue) { if (configvalue == null) return new IntegrationProperties(); StringTokenizer st = new StringTokenizer(configvalue, ";"); int i = 1; IntegrationProperties keys = new IntegrationProperties(); while (st.hasMoreTokens()) { String value = st.nextToken(); if (i == 1) { keys.setProperties1(value); } else if (i == 2) { keys.setProperties2(value); } else if (i == 3) { keys.setProperties3(value); } else { keys.setProperties4(value); } i++; } return keys; }
From source file:TextUtilities.java
/** * Parses the specified list of integers delimited by the specified * delimiters.// w ww.j a v a2 s . c o m */ public static int[] parseIntList(String text, String delimiters) { StringTokenizer tokenizer = new StringTokenizer(text, delimiters); int[] tokens = new int[tokenizer.countTokens()]; for (int i = 0; i < tokens.length; i++) tokens[i] = Integer.parseInt(tokenizer.nextToken()); return tokens; }
From source file:lirmm.inria.fr.data.DataMatrix.java
public static DataMatrix createDataMatrix(String file) throws FileNotFoundException, IOException { FileInputStream fstream;/*from w w w. j a v a 2s. c o m*/ Set<String> listI = new HashSet<>(); Set<String> listJ = new HashSet(); fstream = new FileInputStream(file); double max = 0; // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String str; while ((str = br.readLine()) != null) { str = str.trim(); if (str.startsWith("#")) { continue; } if (str.trim().length() == 0) { continue; } StringTokenizer st = new StringTokenizer(str); String i = st.nextToken(); String j = st.nextToken(); double rating = Double.parseDouble(st.nextToken()); if (max < rating) { max = rating; } if (!listI.contains(i)) { listI.add(i); } if (!listJ.contains(j)) { listJ.add(j); } } return new DataMatrix(file, listI.size(), listJ.size(), max); }
From source file:TreeUtil.java
public static TreePath makeTreePath(String path, DefaultMutableTreeNode parentNode) { DefaultMutableTreeNode tempNode = parentNode; TreePath res = new TreePath(parentNode); StringTokenizer tok = new StringTokenizer(path, "."); String currentPath = null;/*from w w w .jav a 2s . c o m*/ while (tok.hasMoreTokens()) { String myTok = tok.nextToken(); currentPath = (currentPath == null) ? myTok : currentPath + "." + myTok; for (int j = 0; j < tempNode.getChildCount(); j++) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) tempNode.getChildAt(j); if (childNode.toString().equals(myTok)) { tempNode = childNode; res = res.pathByAddingChild(tempNode); break; } } } return res; }
From source file:com.cnksi.core.web.utils.Servlets.java
/** * ?? If-None-Match Header, Etag?.// ww w. j av a2 s. c o m * * Etag, checkIfNoneMatchfalse, 304 not modify status. * * @param etag ETag. */ public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response, String etag) { String headerValue = request.getHeader(HttpHeaders.IF_NONE_MATCH); if (headerValue != null) { boolean conditionSatisfied = false; if (!"*".equals(headerValue)) { StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ","); while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { String currentToken = commaTokenizer.nextToken(); if (currentToken.trim().equals(etag)) { conditionSatisfied = true; } } } else { conditionSatisfied = true; } if (conditionSatisfied) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.setHeader(HttpHeaders.ETAG, etag); return false; } } return true; }
From source file:com.legstar.codegen.tasks.SourceToXsdCobolTask.java
/** * Converts a URI into a package name. We assume a hierarchical, * server-based URI with the following syntax: * [scheme:][//host[:port]][path][?query][#fragment] * The package name is derived from host, path and fragment. * /* ww w . j a v a 2 s .c om*/ * @param namespaceURI the input namespace URI * @return the result package name */ public static String packageFromURI(final URI namespaceURI) { StringBuilder result = new StringBuilder(); URI nURI = namespaceURI.normalize(); boolean firstToken = true; /* * First part of package name is built from host with tokens in * reverse order. */ if (nURI.getHost() != null && nURI.getHost().length() != 0) { Vector<String> v = new Vector<String>(); StringTokenizer t = new StringTokenizer(nURI.getHost(), "."); while (t.hasMoreTokens()) { v.addElement(t.nextToken()); } for (int i = v.size(); i > 0; i--) { if (!firstToken) { result.append('.'); } else { firstToken = false; } result.append(v.get(i - 1)); } } /* Next part of package is built from the path tokens */ if (nURI.getPath() != null && nURI.getPath().length() != 0) { Vector<String> v = new Vector<String>(); StringTokenizer t = new StringTokenizer(nURI.getPath(), "/"); while (t.hasMoreTokens()) { v.addElement(t.nextToken()); } for (int i = 0; i < v.size(); i++) { String token = v.get(i); /* ignore situations such as /./../ */ if (token.equals(".") || token.equals("..")) { continue; } if (!firstToken) { result.append('.'); } else { firstToken = false; } result.append(v.get(i)); } } /* Finally append any fragment */ if (nURI.getFragment() != null && nURI.getFragment().length() != 0) { if (!firstToken) { result.append('.'); } else { firstToken = false; } result.append(nURI.getFragment()); } /* * By convention, namespaces are lowercase and should not contain * invalid Java identifiers */ String s = result.toString().toLowerCase(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { Character c = s.charAt(i); if (Character.isJavaIdentifierPart(c) || c.equals('.')) { sb.append(c); } else { sb.append("_"); } } return sb.toString(); }