List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:org.jberet.support.io.MappingJsonFactoryObjectFactory.java
static void configureCustomSerializersAndDeserializers(final ObjectMapper objectMapper, final String customSerializers, final String customDeserializers, final String customDataTypeModules, final ClassLoader classLoader) throws Exception { if (customDeserializers != null || customSerializers != null) { final SimpleModule simpleModule = new SimpleModule("custom-serializer-deserializer-module"); if (customSerializers != null) { final StringTokenizer st = new StringTokenizer(customSerializers, ", "); while (st.hasMoreTokens()) { final Class<?> aClass = classLoader.loadClass(st.nextToken()); simpleModule.addSerializer(aClass, (JsonSerializer) aClass.newInstance()); }//from w w w. java 2 s .co m } if (customDeserializers != null) { final StringTokenizer st = new StringTokenizer(customDeserializers, ", "); while (st.hasMoreTokens()) { final Class<?> aClass = classLoader.loadClass(st.nextToken()); simpleModule.addDeserializer(aClass, (JsonDeserializer) aClass.newInstance()); } } objectMapper.registerModule(simpleModule); } if (customDataTypeModules != null) { final StringTokenizer st = new StringTokenizer(customDataTypeModules, ", "); while (st.hasMoreTokens()) { final Class<?> aClass = classLoader.loadClass(st.nextToken()); objectMapper.registerModule((Module) aClass.newInstance()); } } }
From source file:de.pawlidi.openaletheia.utils.AletheiaUtils.java
/** * //from w w w. j ava 2 s. c o m * @return */ public static String getWindowsMacAddress() { final String ipConfigResponse = executeCommand("ipconfig", "/all"); if (ipConfigResponse == null) { return null; } String localHost = getLocalhostAddress(); if (localHost == null) { return null; } String lastMacAddressCandidate = null; StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n"); while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken().trim(); if ((line.indexOf(localHost) >= 0) && (lastMacAddressCandidate != null)) { return lastMacAddressCandidate; } int colon = line.indexOf(":"); if (colon <= 0) { continue; } String candidate = line.substring(colon + 1).trim(); if (isMacAddressCandidate(candidate)) { lastMacAddressCandidate = normalizeMacAddress(candidate); } } return lastMacAddressCandidate; }
From source file:cn.vlabs.duckling.vwb.VWBFilter.java
private static Locale getLocale(String lstr) { if (lstr == null || lstr.length() < 1) { return null; }/*from w w w .j ava 2 s .c o m*/ Locale locale = locales.get(lstr.toLowerCase()); if (locale != null) { return locale; } else { StringTokenizer localeTokens = new StringTokenizer(lstr, "_"); String lang = null; String country = null; if (localeTokens.hasMoreTokens()) { lang = localeTokens.nextToken(); } if (localeTokens.hasMoreTokens()) { country = localeTokens.nextToken(); } locale = new Locale(lang, country); Locale crtls[] = Locale.getAvailableLocales(); for (int i = 0; i < crtls.length; i++) { if (crtls[i].equals(locale)) { locale = crtls[i]; break; } } locales.put(lstr.toLowerCase(), locale); } return locale; }
From source file:ca.uhn.fhir.util.UrlUtil.java
private static void parseQueryString(String theQueryString, HashMap<String, List<String>> map) { String query = theQueryString; if (query.startsWith("?")) { query = query.substring(1);// w ww . j a v a 2s . c om } StringTokenizer tok = new StringTokenizer(query, "&"); while (tok.hasMoreTokens()) { String nextToken = tok.nextToken(); if (isBlank(nextToken)) { continue; } int equalsIndex = nextToken.indexOf('='); String nextValue; String nextKey; if (equalsIndex == -1) { nextKey = nextToken; nextValue = ""; } else { nextKey = nextToken.substring(0, equalsIndex); nextValue = nextToken.substring(equalsIndex + 1); } nextKey = unescape(nextKey); nextValue = unescape(nextValue); List<String> list = map.get(nextKey); if (list == null) { list = new ArrayList<String>(); map.put(nextKey, list); } list.add(nextValue); } }
From source file:XMLUtils.java
public static QName getNamespace(Map<String, String> namespaces, String str, String defaultNamespace) { String prefix = null;// ww w . j ava 2 s . c o m String localName = null; StringTokenizer tokenizer = new StringTokenizer(str, ":"); if (tokenizer.countTokens() == 2) { prefix = tokenizer.nextToken(); localName = tokenizer.nextToken(); } else if (tokenizer.countTokens() == 1) { localName = tokenizer.nextToken(); } String namespceURI = defaultNamespace; if (prefix != null) { namespceURI = (String) namespaces.get(prefix); } return new QName(namespceURI, localName); }
From source file:org.jberet.support.io.MappingJsonFactoryObjectFactory.java
static void configureMapperFeatures(final ObjectMapper objectMapper, final String features) { final StringTokenizer st = new StringTokenizer(features, ","); while (st.hasMoreTokens()) { final String[] pair = NoMappingJsonFactoryObjectFactory.parseSingleFeatureValue(st.nextToken().trim()); final String key = pair[0]; final String value = pair[1]; final MapperFeature feature; try {/*from www . j a va 2 s . com*/ feature = MapperFeature.valueOf(key); } catch (final Exception e1) { throw SupportMessages.MESSAGES.unrecognizedReaderWriterProperty(key, value); } if ("true".equals(value)) { if (!feature.enabledByDefault()) { objectMapper.configure(feature, true); } } else if ("false".equals(value)) { if (feature.enabledByDefault()) { objectMapper.configure(feature, false); } } else { throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, value, key); } } }
From source file:org.jberet.support.io.MappingJsonFactoryObjectFactory.java
static void configureSerializationFeatures(final ObjectMapper objectMapper, final String features) { final StringTokenizer st = new StringTokenizer(features, ","); while (st.hasMoreTokens()) { final String[] pair = NoMappingJsonFactoryObjectFactory.parseSingleFeatureValue(st.nextToken().trim()); final String key = pair[0]; final String value = pair[1]; final SerializationFeature feature; try {/*from w w w. j a v a2s. c o m*/ feature = SerializationFeature.valueOf(key); } catch (final Exception e1) { throw SupportMessages.MESSAGES.unrecognizedReaderWriterProperty(key, value); } if ("true".equals(value)) { if (!feature.enabledByDefault()) { objectMapper.configure(feature, true); } } else if ("false".equals(value)) { if (feature.enabledByDefault()) { objectMapper.configure(feature, false); } } else { throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, value, key); } } }
From source file:org.jberet.support.io.MappingJsonFactoryObjectFactory.java
static void configureDeserializationFeatures(final ObjectMapper objectMapper, final String features) { final StringTokenizer st = new StringTokenizer(features, ","); while (st.hasMoreTokens()) { final String[] pair = NoMappingJsonFactoryObjectFactory.parseSingleFeatureValue(st.nextToken().trim()); final String key = pair[0]; final String value = pair[1]; final DeserializationFeature feature; try {//from w w w . j a v a 2s. c o m feature = DeserializationFeature.valueOf(key); } catch (final Exception e1) { throw SupportMessages.MESSAGES.unrecognizedReaderWriterProperty(key, value); } if ("true".equals(value)) { if (!feature.enabledByDefault()) { objectMapper.configure(feature, true); } } else if ("false".equals(value)) { if (feature.enabledByDefault()) { objectMapper.configure(feature, false); } } else { throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, value, key); } } }
From source file:Which4J.java
/** * Iterate over the system classpath defined by "java.class.path" searching * for all occurrances of the given class name. * //from www. ja v a 2 s . co m * @param classname the fully qualified class name to search for */ private static void findIt(String classname) { try { // get the system classpath String classpath = System.getProperty("java.class.path", ""); if (classpath.equals("")) { System.err.println("error: classpath is not set"); } if (debug) { System.out.println("classname: " + classname); System.out.println("system classpath = " + classpath); } if (isPrimitiveOrVoid(classname)) { System.out.println("'" + classname + "' primitive"); return; } StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator); while (st.hasMoreTokens()) { String token = st.nextToken(); File classpathElement = new File(token); if (debug) System.out.println(classpathElement.isDirectory() ? "dir: " + token : "jar: " + token); URL[] url = { classpathElement.toURL() }; URLClassLoader cl = URLClassLoader.newInstance(url, null); String classnameAsResource = classname.replace('.', '/') + ".class"; URL it = cl.findResource(classnameAsResource); if (it != null) { System.out.println("found in: " + token); System.out.println(" url: " + it.toString()); System.out.println(""); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:StringUtils.java
public static List<String> explode(String s, String sep) { StringTokenizer st = new StringTokenizer(s, sep); List<String> v = new ArrayList<String>(); for (; st.hasMoreTokens();) { v.add(st.nextToken()); }/*from w w w . ja v a2s. co m*/ return v; }