List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:Main.java
private static List<String> splitTokens(String sentenceTosearch) { StringTokenizer tokenizer = new StringTokenizer(sentenceTosearch, "'", true); List<String> tokens = new ArrayList<>(); while (tokenizer.hasMoreElements()) { tokens.add(tokenizer.nextToken()); }/*from ww w . j a v a 2s. c o m*/ return tokens; }
From source file:com.jadyounan.Packager.java
/** * Servlet handler , should listen on the callback URL (as in webServiceURL) * @param requestPath/* ww w .j a v a2 s .c o m*/ * @param req * @param servletRequest * @param servletResponse * @throws Exception */ public static void handle(String requestPath, Request req, HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception { StringTokenizer st = new StringTokenizer(requestPath, "/"); st.nextToken(); String companyDomain = st.nextToken(); String version = st.nextToken(); byte bytes[] = new byte[] {}; switch (st.nextToken().toLowerCase()) { case "log": { bytes = new byte[] {}; byte r[] = org.eclipse.jetty.util.IO.readBytes(servletRequest.getInputStream()); System.out.println("LOG " + new String(r)); } break; case "devices": { String deviceID = st.nextToken(); String authToken = req.getHeader("Authorization").split(" ")[1]; // use the authToken to get the userID who started the request switch (servletRequest.getMethod().toUpperCase()) { case "DELETE": //handle deleting the token from your database break; default: { //handle adding the token/deviceID to your database } break; } FLUSH.updatePushDevices(userID); bytes = new byte[] {}; } break; case "pushpackages": { /** * Safari requests the pacakge */ String id = st.nextToken(); JSONObject obj = new JSONObject( new String(org.eclipse.jetty.util.IO.readBytes(servletRequest.getInputStream()))); String userID = obj.getString("user_id"); String authenticationToken = "..a random string so you can later identify the user who started the request"; bytes = createPackageFile(authenticationToken); } break; default: bytes = new byte[] {}; break; } servletResponse.setStatus(200); servletResponse.setContentLength(bytes.length); try (OutputStream out = servletResponse.getOutputStream()) { out.write(bytes); out.flush(); } }
From source file:com.yanzhenjie.andserver.util.HttpRequestParser.java
/** * Split http params./*w w w .j a v a2 s. c o m*/ * * @param content target content. * @param lowerCaseNames Whether to put all keys are converted to lowercase. * @return parameter key-value pairs. */ public static Map<String, String> splitHttpParams(String content, boolean lowerCaseNames) { Map<String, String> paramMap = new HashMap<String, String>(); StringTokenizer tokenizer = new StringTokenizer(content, "&"); while (tokenizer.hasMoreElements()) { String keyValue = tokenizer.nextToken(); int index = keyValue.indexOf("="); if (index > 0) { String key = keyValue.substring(0, index); if (lowerCaseNames) key = key.toLowerCase(Locale.ENGLISH); paramMap.put(key, keyValue.substring(index + 1)); } } return paramMap; }
From source file:ca.uhn.fhir.rest.method.ElementsParameter.java
public static Set<String> getElementsValueOrNull(RequestDetails theRequest) { String[] summary = theRequest.getParameters().get(Constants.PARAM_ELEMENTS); if (summary != null && summary.length > 0) { Set<String> retVal = new HashSet<String>(); for (String next : summary) { StringTokenizer tok = new StringTokenizer(next, ","); while (tok.hasMoreTokens()) { String token = tok.nextToken(); if (isNotBlank(token)) { retVal.add(token);/*from w ww. j ava 2 s. c o m*/ } } } if (retVal.isEmpty()) { return null; } // Always include the meta element even for subsetted values retVal.add("meta"); return retVal; } else { return null; } }
From source file:net.sf.j2ep.requesthandlers.RequestHandlerBase.java
/** * Adds all the headers in the input to the list * of banned headers. The input string should be * comma separated e.g. "Server,Connection,Via" * //from w ww . j a v a2 s . co m * This method is normally called by the factory that * is using this request handler. * * @param headers The headers that are banned */ @SuppressWarnings("unchecked") public static void addBannedHeaders(String headers) { StringTokenizer tokenizer = new StringTokenizer(headers, ","); while (tokenizer.hasMoreTokens()) { bannedHeaders.add(tokenizer.nextToken().trim().toLowerCase()); } }
From source file:com.stratuscom.harvester.Utils.java
public static String[] splitOnWhitespace(String input) { List<String> strings = new ArrayList<String>(); StringTokenizer tok = new StringTokenizer(Strings.WHITESPACE_SEPARATORS); while (tok.hasMoreTokens()) { strings.add(tok.nextToken()); }// ww w . jav a 2s . co m return (String[]) strings.toArray(new String[0]); }
From source file:DateParser.java
private static boolean check(StringTokenizer st, String token) { try {//from ww w .j a v a 2 s . c o m if (st.nextToken().equals(token)) { return true; } else { throw new RuntimeException("Missing [" + token + "]"); } } catch (NoSuchElementException ex) { return false; } }
From source file:com.bluexml.side.Framework.alfresco.languagepicker.MyWebScriptServlet.java
/** * Apply Client and Repository language locale based on the * 'Accept-Language' request header/*from w ww .j a va 2 s . c om*/ */ public static String getLanguageFromRequestHeader(HttpServletRequest req) { // 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('-', '_'); return language; } return null; }
From source file:Main.java
public static void initializeMap(InputStream is, boolean isPositive) { try {/*w w w .ja va2 s.c om*/ BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); String line = null; while ((line = reader.readLine()) != null) { StringTokenizer tokenizer = new StringTokenizer(line, "\t\n", false); String key = null; Vector<String> tokens = new Vector<String>(); if (tokenizer.hasMoreTokens()) key = tokenizer.nextToken(); while (tokenizer.hasMoreTokens()) { tokens.add(tokenizer.nextToken()); } if (key != null) { if (isPositive) posMap.put(key, tokens); else negMap.put(key, tokens); } } } catch (Exception e) { } }
From source file:Util.java
/** * Split "str" into tokens by delimiters and optionally remove white spaces * from the splitted tokens./*from ww w.j a v a 2 s . co m*/ * * @param trimTokens if true, then trim the tokens */ public static String[] split(String str, String delims, boolean trimTokens) { StringTokenizer tokenizer = new StringTokenizer(str, delims); int n = tokenizer.countTokens(); String[] list = new String[n]; for (int i = 0; i < n; i++) { if (trimTokens) { list[i] = tokenizer.nextToken().trim(); } else { list[i] = tokenizer.nextToken(); } } return list; }