List of usage examples for java.util StringTokenizer StringTokenizer
public StringTokenizer(String str, String delim)
From source file:com.aol.one.patch.PathTokens.java
public void populate() throws PatchException { if (StringUtils.isBlank(path)) { throw new PatchException(ERR_INVALID_PATH, path); }/* ww w. j a v a 2s .c o m*/ this.clear(); if (!path.startsWith(SLASH_STR)) { throw new PatchRuntimeException(ERR_UNKNOWN, "path does not start with: " + SLASH_STR); } StringTokenizer tokenizer = new StringTokenizer(path, SLASH_STR); while (tokenizer.hasMoreTokens()) { this.add(tokenizer.nextToken()); } }
From source file:com.opensymphony.xwork2.config.ConfigurationUtil.java
/** * Splits the string into a list using a comma as the token separator. * @param parent The comma separated string. * @return A list of tokens from the specified string. *//*from w w w. j av a 2s . c o m*/ public static List<String> buildParentListFromString(String parent) { if (StringUtils.isEmpty(parent)) { return Collections.emptyList(); } StringTokenizer tokenizer = new StringTokenizer(parent, ","); List<String> parents = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { String parentName = tokenizer.nextToken().trim(); if (StringUtils.isNotEmpty(parentName)) { parents.add(parentName); } } return parents; }
From source file:cooccurrence.emf.java
/** * Outer Method to read the file content and populate it in the cooccur * hashmap/*from w w w . j a va2 s . com*/ * * @param filePath * @param cooccur * @return */ private static long readFileContents(String filePath, HashMap<String, HashMap<String, Double>> cooccur) { long totalCount = 0; try { BufferedReader br = new BufferedReader(new FileReader(filePath)); String line = ""; while ((line = br.readLine()) != null) { StringTokenizer tok = new StringTokenizer(line, "\t"); if (tok.countTokens() == 3) { String from = tok.nextToken(); String to = tok.nextToken(); Double count = Double.parseDouble(tok.nextToken()); totalCount += count; addToMatrix(from, to, count, cooccur); } } } catch (FileNotFoundException ex) { Logger.getLogger(pmi.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(pmi.class.getName()).log(Level.SEVERE, null, ex); } return totalCount; }
From source file:JNDIUtil.java
/** * Create a context path recursively./*from w w w . j a va 2 s. c om*/ */ public static Context createContext(Context c, String path) throws NamingException { Context crtContext = c; for (StringTokenizer st = new StringTokenizer(path, "/"); st.hasMoreTokens();) { String tok = st.nextToken(); try { Object o = crtContext.lookup(tok); if (!(o instanceof Context)) { throw new NamingException("Path " + path + " overwrites and already bound object"); } crtContext = (Context) o; continue; } catch (NameNotFoundException e) { // OK } crtContext = crtContext.createSubcontext(tok); } return crtContext; }
From source file:com.enonic.vertical.adminweb.handlers.xmlbuilders.ContentFileXMLBuilder.java
public void buildContentTypeXML(User user, Document doc, Element contentdata, ExtendedMap formItems) throws VerticalAdminException { // Name// w w w . ja v a 2 s . co m Element tempElement = XMLTool.createElement(doc, contentdata, "name", formItems.getString("name")); // Description tempElement = XMLTool.createElement(doc, contentdata, "description"); XMLTool.createCDATASection(doc, tempElement, formItems.getString("description", "")); // Keywords Element keywords = XMLTool.createElement(doc, contentdata, "keywords"); if (formItems.containsKey("keywords")) { StringTokenizer stringTok = new StringTokenizer(formItems.getString("keywords"), " "); while (stringTok.hasMoreElements()) { tempElement = XMLTool.createElement(doc, keywords, "keyword", (String) stringTok.nextElement()); } } // File size int fileSize = formItems.getInt("filesize"); XMLTool.createElement(doc, contentdata, "filesize", String.valueOf(fileSize)); tempElement = XMLTool.createElement(doc, contentdata, "binarydata"); tempElement.setAttribute("key", (String) formItems.get("binarydatakey")); }
From source file:com.espertech.esper.regression.dataflow.MyTokenizerCounter.java
public void onInput(String line) { StringTokenizer tokenizer = new StringTokenizer(line, " \t"); int wordCount = tokenizer.countTokens(); int charCount = 0; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); charCount += token.length();/* w w w . ja v a 2 s .co m*/ } log.debug("Submitting stat words[" + wordCount + "] chars[" + charCount + "] for line '" + line + "'"); graphContext.submit(new Object[] { 1, wordCount, charCount }); }
From source file:azkaban.utils.FileIOUtils.java
public static String getSourcePathFromClass(Class<?> containedClass) { File file = new File(containedClass.getProtectionDomain().getCodeSource().getLocation().getPath()); if (!file.isDirectory() && file.getName().endsWith(".class")) { String name = containedClass.getName(); StringTokenizer tokenizer = new StringTokenizer(name, "."); while (tokenizer.hasMoreTokens()) { tokenizer.nextElement();/*from ww w . j a va 2 s.co m*/ file = file.getParentFile(); } return file.getPath(); } else { return containedClass.getProtectionDomain().getCodeSource().getLocation().getPath(); } }
From source file:com.bluexml.side.Framework.alfresco.shareLanguagePicker.CustomDispatcherServlet.java
public static void setLanguageFromLayoutParam(HttpServletRequest req) { String urlLang = req.getParameter("shareLang"); HttpSession currentSession = req.getSession(); String sessionLang = (String) currentSession.getAttribute("shareLang"); //1st option: Select the url param shareLang if (urlLang != null) { I18NUtil.setLocale(I18NUtil.parseLocale(urlLang)); currentSession.setAttribute("shareLang", urlLang); } else if (sessionLang != null) { I18NUtil.setLocale(I18NUtil.parseLocale(sessionLang)); } else {/* www . j av a 2s . c o m*/ // set language locale from browser header String acceptLang = req.getHeader("Accept-Language"); if (acceptLang != null && acceptLang.length() != 0) { StringTokenizer t = new StringTokenizer(acceptLang, ",; "); // get language and convert to java locale format String language = t.nextToken().replace('-', '_'); I18NUtil.setLocale(I18NUtil.parseLocale(language)); } } }
From source file:com.sonatype.nexus.perftest.maven.HttpdLogParser.java
@JsonCreator public HttpdLogParser(@JsonProperty("logfile") File logfile) throws IOException { ArrayList<String> paths = new ArrayList<>(); try (BufferedReader br = new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream(logfile))))) { String str;//from ww w. j a v a 2 s . c o m while ((str = br.readLine()) != null) { StringTokenizer st = new StringTokenizer(str, "[]\" "); st.nextToken(); // ip st.nextToken(); // not sure st.nextToken(); // username st.nextToken(); // [date:time st.nextToken(); // timezoneoffset] String method = st.nextToken(); // "METHOD if ("GET".equals(method)) { String path = st.nextToken(); // path if (path.startsWith(PREFIX)) { paths.add(path.substring(PREFIX.length())); } } } } this.paths = Collections.unmodifiableList(paths); }
From source file:com.htmlhifive.tools.rhino.comment.js.JSDocCommentNodeParser.java
public JSDocRoot parse(String comment) { StringTokenizer lineSeparator = new StringTokenizer(comment, "\n\r"); int currentLineNum = 0; int currentIndexNum = 0; tokenList = new ArrayList<Token>(); while (lineSeparator.hasMoreTokens()) { // ?//from w ww .j ava 2s. com String lineStr = lineSeparator.nextToken(); // ? StringTokenizer tokenSeparator = new StringTokenizer(lineStr); while (tokenSeparator.hasMoreTokens()) { // token? String tokenStr = tokenSeparator.nextToken(); Token token = new Token(TokenUtil.resolveType(tokenStr), tokenStr); // token?? token.setLineNum(currentLineNum); // token???? token.setIndexNum(currentIndexNum); tokenList.add(token); currentIndexNum = currentIndexNum + tokenStr.length() + 1; } currentIndexNum = 0; currentLineNum++; } return resolveJsDoc(); }