List of usage examples for java.util StringTokenizer hasMoreElements
public boolean hasMoreElements()
From source file:com.baifendian.swordfish.execserver.utils.OsUtil.java
public static Map<?, ?> cpuinfo() { InputStreamReader inputs = null; BufferedReader buffer = null; Map<String, Object> map = new HashMap<>(); try {/* ww w . j a v a 2s.c o m*/ inputs = new InputStreamReader(new FileInputStream("/proc/stat")); buffer = new BufferedReader(inputs); String line = ""; while (true) { line = buffer.readLine(); if (line == null) { break; } if (line.startsWith("cpu")) { StringTokenizer tokenizer = new StringTokenizer(line); List<String> temp = new ArrayList<>(); while (tokenizer.hasMoreElements()) { String value = tokenizer.nextToken(); temp.add(value); } map.put("user", temp.get(1)); map.put("nice", temp.get(2)); map.put("system", temp.get(3)); map.put("idle", temp.get(4)); map.put("iowait", temp.get(5)); map.put("irq", temp.get(6)); map.put("softirq", temp.get(7)); map.put("stealstolen", temp.get(8)); break; } } } catch (Exception e) { logger.error("get cpu usage error", e); } finally { try { buffer.close(); inputs.close(); } catch (Exception e) { logger.error("get cpu usage error", e); } } return map; }
From source file:net.antidot.semantic.rdf.rdb2rdf.r2rml.tools.R2RMLToolkit.java
/** * Every pair of unescaped curly braces in the inverse expression is a * column reference in an inverse expression. The string between the braces * MUST be a valid column name./*from w ww .j ava 2s . co m*/ * * @param value * @return */ public static Set<ColumnIdentifier> extractColumnNamesFromInverseExpression(String inverseExpression) { Set<ColumnIdentifier> result = new HashSet<ColumnIdentifier>(); if (inverseExpression != null) { StringTokenizer st = new StringTokenizer(inverseExpression, "{}"); while (st.hasMoreElements()) { String element = st.nextElement().toString(); int index = inverseExpression.indexOf(element); if (index > 0 && index < inverseExpression.length() && inverseExpression.charAt(index - 1) == '{' && (inverseExpression.charAt(index + element.length()) == '}')) { // result.add(deleteBackSlash(element)); result.add(ColumnIdentifierImpl.buildFromR2RMLConfigFile(element)); } } } return result; }
From source file:org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportParserUtil.java
public static int parseVersion(final String s) { if (StringUtils.isEmpty(s)) { return -1; }/*w w w .ja va 2 s . c o m*/ try { final StringTokenizer strtok = new StringTokenizer(s, "."); int version = 0; while (strtok.hasMoreElements()) { final String token = strtok.nextToken(); final int i = Integer.parseInt(token); version = version * 1000 + i; } return version; } catch (Exception e) { return -1; } }
From source file:org.wso2.carbon.identity.application.authentication.endpoint.util.MutualSSLManager.java
/** * There can be sensitive information like passwords in configuration file. If they are encrypted using secure * vault, this method will resolve them and replace with original values. *//* w w w. j av a 2 s. com*/ private static void resolveSecrets(Properties properties) { String protectedTokens = (String) properties.get(PROTECTED_TOKENS); if (StringUtils.isNotBlank(protectedTokens)) { String secretProvider = (String) properties.get(SECRET_PROVIDER); SecretResolver secretResolver; if (StringUtils.isBlank(secretProvider)) { properties.put(SECRET_PROVIDER, DEFAULT_CALLBACK_HANDLER); } secretResolver = SecretResolverFactory.create(properties, ""); StringTokenizer st = new StringTokenizer(protectedTokens, ","); while (st.hasMoreElements()) { String element = st.nextElement().toString().trim(); if (secretResolver.isTokenProtected(element)) { if (log.isDebugEnabled()) { log.debug("Resolving and replacing secret for " + element); } // Replaces the original encrypted property with resolved property properties.put(element, secretResolver.resolve(element)); } else { if (log.isDebugEnabled()) { log.debug("No encryption done for value with key :" + element); } } } } else { if (log.isDebugEnabled()) { log.debug("Secure vault encryption ignored since no protected tokens available"); } } }
From source file:org.glite.slcs.pki.CertificateExtensionFactory.java
/** * Creates a CertificateExtension. The id can be the OID or the name as * defined below. The values is a comma separated list of value(s) * <p>//from w w w . j a va2 s . c o m * Valid names and values: * <ul> * <li>KeyUsage * <ul> * <li>DigitalSignature * <li>NonRepudiation * <li>KeyEncipherment * <li>DataEncipherment * <li>KeyAgreement * <li>KeyCertSign * <li>CRLSign * <li>EncipherOnly * <li>DecipherOnly * </ul> * <li>ExtendedKeyUsage * <ul> * <li>AnyExtendedKeyUsage * <li>ServerAuth * <li>ClientAuth * <li>CodeSigning * <li>EmailProtection * <li>IPSecEndSystem * <li>IPSecTunnel * <li>IPSecUser * <li>OCSPSigning * <li>Smartcardlogon * </ul> * <li>CertificatePolicies * <ul> * <li>The policy OID(s) * </ul> * <li>SubjectAltName * <ul> * <li>email:EMAIL_ADDRESS * <li>dns:HOSTNAME * </ul> * </ul> * <p> * Example: * <pre> * CertificateExtension keyUsageExtension = * CertificateExtensionFactory.createCertificateExtension("KeyUsage", "DigitalSignature,KeyEncipherment"); * CertificateExtension subjectAltNameExtension = * CertificateExtensionFactory.createCertificateExtension("SubjectAltName", "email:john.doe@example.com,dns:www.exmaple.com"); * </pre> * * @param id * The name or the OID of the extension. * @param values * A comma separated list of extension value(s). * @return The corresponding CertificateExtension or <code>null</code> if * the id (name or oid) is not supported. */ static public CertificateExtension createCertificateExtension(String id, String values) { if (LOG.isDebugEnabled()) { LOG.debug("id:" + id + " value(s):" + values); } if (id.equals(X509Extensions.KeyUsage.getId()) || id.equalsIgnoreCase("KeyUsage")) { // parse the comma separated list of key usage int usage = 0; StringTokenizer st = new StringTokenizer(values, ","); while (st.hasMoreElements()) { String keyUsage = (String) st.nextElement(); keyUsage = keyUsage.trim(); if (keyUsage.equalsIgnoreCase("DigitalSignature")) { usage += KeyUsage.digitalSignature; } else if (keyUsage.equalsIgnoreCase("NonRepudiation")) { usage += KeyUsage.nonRepudiation; } else if (keyUsage.equalsIgnoreCase("KeyEncipherment")) { usage += KeyUsage.keyEncipherment; } else if (keyUsage.equalsIgnoreCase("DataEncipherment")) { usage += KeyUsage.dataEncipherment; } else if (keyUsage.equalsIgnoreCase("KeyAgreement")) { usage += KeyUsage.keyAgreement; } else if (keyUsage.equalsIgnoreCase("KeyCertSign")) { usage += KeyUsage.keyCertSign; } else if (keyUsage.equalsIgnoreCase("CRLSign")) { usage += KeyUsage.cRLSign; } else if (keyUsage.equalsIgnoreCase("EncipherOnly")) { usage += KeyUsage.encipherOnly; } else if (keyUsage.equalsIgnoreCase("DecipherOnly")) { usage += KeyUsage.decipherOnly; } else { LOG.error("Unknown KeyUsage: " + keyUsage); } } return createKeyUsageExtension(usage, values); } else if (id.equals(X509Extensions.ExtendedKeyUsage.getId()) || id.equalsIgnoreCase("ExtendedKeyUsage")) { // value is a comma separated list of keyPurpose Vector keyPurposeIds = new Vector(); StringTokenizer st = new StringTokenizer(values, ","); while (st.hasMoreElements()) { String keyPurpose = (String) st.nextElement(); keyPurpose = keyPurpose.trim(); if (keyPurpose.equalsIgnoreCase("AnyExtendedKeyUsage")) { keyPurposeIds.add(KeyPurposeId.anyExtendedKeyUsage); } else if (keyPurpose.equalsIgnoreCase("ServerAuth")) { keyPurposeIds.add(KeyPurposeId.id_kp_serverAuth); } else if (keyPurpose.equalsIgnoreCase("ClientAuth")) { keyPurposeIds.add(KeyPurposeId.id_kp_clientAuth); } else if (keyPurpose.equalsIgnoreCase("CodeSigning")) { keyPurposeIds.add(KeyPurposeId.id_kp_codeSigning); } else if (keyPurpose.equalsIgnoreCase("EmailProtection")) { keyPurposeIds.add(KeyPurposeId.id_kp_emailProtection); } else if (keyPurpose.equalsIgnoreCase("IPSecEndSystem")) { keyPurposeIds.add(KeyPurposeId.id_kp_ipsecEndSystem); } else if (keyPurpose.equalsIgnoreCase("IPSecTunnel")) { keyPurposeIds.add(KeyPurposeId.id_kp_ipsecTunnel); } else if (keyPurpose.equalsIgnoreCase("IPSecUser")) { keyPurposeIds.add(KeyPurposeId.id_kp_ipsecUser); } else if (keyPurpose.equalsIgnoreCase("TimeStamping")) { keyPurposeIds.add(KeyPurposeId.id_kp_timeStamping); } else if (keyPurpose.equalsIgnoreCase("OCSPSigning")) { keyPurposeIds.add(KeyPurposeId.id_kp_OCSPSigning); } else if (keyPurpose.equalsIgnoreCase("Smartcardlogon")) { keyPurposeIds.add(KeyPurposeId.id_kp_smartcardlogon); } else { LOG.error("Unknown ExtendedKeyUsage: " + keyPurpose); } } return createExtendedKeyUsageExtension(keyPurposeIds, values); } else if (id.equals(X509Extensions.CertificatePolicies.getId()) || id.equalsIgnoreCase("CertificatePolicies")) { // values is a comma separated list of policyOIDs Vector policyOIDs = new Vector(); StringTokenizer st = new StringTokenizer(values, ","); while (st.hasMoreElements()) { String policyOID = (String) st.nextElement(); policyOID = policyOID.trim(); policyOIDs.add(policyOID); } return createCertificatePoliciesExtension(policyOIDs, values); } else if (id.equals(X509Extensions.SubjectAlternativeName.getId()) || id.equalsIgnoreCase("SubjectAltName")) { // values is a comma separated list of altername names prefixed with // the type (email: or dns:) Vector typedSubjectAltNames = new Vector(); StringTokenizer st = new StringTokenizer(values, ","); while (st.hasMoreElements()) { String typedAltName = (String) st.nextElement(); typedAltName = typedAltName.trim(); typedSubjectAltNames.add(typedAltName); } return createSubjectAltNameExtension(typedSubjectAltNames, values); } LOG.error("Unsupported CertificateExtension: " + id); return null; }
From source file:com.liusoft.dlog4j.search.SearchProxy.java
/** * ?//from w w w .j a v a 2 s .com * @param obj * @param field * @return * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException * @throws SecurityException * @throws NoSuchFieldException * @throws IntrospectionException */ private static Class getNestedPropertyType(Object obj, String field) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException, NoSuchFieldException, IntrospectionException { StringTokenizer st = new StringTokenizer(field, "."); Class nodeClass = obj.getClass(); while (st.hasMoreElements()) { String f = st.nextToken(); PropertyDescriptor[] props = Introspector.getBeanInfo(nodeClass).getPropertyDescriptors(); for (int i = 0; i < props.length; i++) { if (props[i].getName().equals(f)) { nodeClass = props[i].getPropertyType(); continue; } } } return nodeClass; }
From source file:ddf.security.sts.claimsHandler.AttributeMapLoader.java
/** * Obtains the user name from the principal. * * @param principal Describing the current user that should be used for retrieving claims. * @return the user name if the principal has one, null if no name is specified or if principal * is null./* ww w .j a va 2 s. c om*/ */ public static String getUser(Principal principal) { String user = null; if (principal instanceof KerberosPrincipal) { KerberosPrincipal kp = (KerberosPrincipal) principal; StringTokenizer st = new StringTokenizer(kp.getName(), "@"); st = new StringTokenizer(st.nextToken(), "/"); user = st.nextToken(); } else if (principal instanceof X500Principal) { X500Principal x500p = (X500Principal) principal; StringTokenizer st = new StringTokenizer(x500p.getName(), ","); while (st.hasMoreElements()) { // token is in the format: // syntaxAndUniqueId // cn // ou // o // loc // state // country String[] strArr = st.nextToken().split("="); if (strArr.length > 1 && strArr[0].equalsIgnoreCase("cn")) { user = strArr[1]; break; } } } else if (principal != null) { user = principal.getName(); } return user; }
From source file:BeanUtil.java
/** * <p>Gets the specified attribute from the specified object. For example, * <code>getObjectAttribute(o, "address.line1")</code> will return * the result of calling <code>o.getAddress().getLine1()</code>.<p> * * <p>The attribute specified may contain as many levels as you like. If at * any time a null reference is acquired by calling one of the successive * getter methods, then the return value from this method is also null.</p> * * <p>When reading from a boolean property the underlying bean introspector * first looks for an is<Property> read method, not finding one it will * still look for a get<Property> read method. Not finding either, the * property is considered write-only.</p> * * @param bean the bean to set the property on * @param propertyNames the name of the propertie(s) to retrieve. If this is * null or the empty string, then <code>bean</code> will be returned. * @return the object value of the bean attribute * * @throws PropertyNotFoundException indicates the the given property * could not be found on the bean * @throws NoSuchMethodException Not thrown * @throws InvocationTargetException if a specified getter method throws an * exception.// w w w . j av a2 s. co m * @throws IllegalAccessException if a getter method is * not public or property is write-only. */ public static Object getObjectAttribute(Object bean, String propertyNames) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Object result = bean; StringTokenizer propertyTokenizer = new StringTokenizer(propertyNames, PROPERTY_SEPARATOR); // Run through the tokens, calling get methods and // replacing result with the new object each time. // If the result equals null, then simply return null. while (propertyTokenizer.hasMoreElements() && result != null) { Class resultClass = result.getClass(); String currentPropertyName = propertyTokenizer.nextToken(); PropertyDescriptor propertyDescriptor = getPropertyDescriptor(currentPropertyName, resultClass); Method readMethod = propertyDescriptor.getReadMethod(); if (readMethod == null) { throw new IllegalAccessException( "User is attempting to " + "read from a property that has no read method. " + " This is likely a write-only bean property. Caused " + "by property [" + currentPropertyName + "] on class [" + resultClass + "]"); } result = readMethod.invoke(result, NO_ARGUMENTS_ARRAY); } return result; }
From source file:net.antidot.semantic.rdf.rdb2rdf.r2rml.tools.R2RMLToolkit.java
/** * Extracts column names referenced by enclosing them in curly braces ({? * and }?) in a string template.//from w ww .ja v a2s.c o m * * @param stringTemplate * @return */ public static Set<String> extractColumnNamesFromStringTemplate(String stringTemplate) { Set<String> result = new HashSet<String>(); // Curly braces that do not enclose column names MUST be // escaped by a backslash character (\?). stringTemplate = stringTemplate.replaceAll("\\\\\\{", ""); stringTemplate = stringTemplate.replaceAll("\\\\\\}", ""); if (stringTemplate != null) { StringTokenizer st = new StringTokenizer(stringTemplate, "{}", true); boolean keepNext = false; String next = null; while (st.hasMoreElements()) { String element = st.nextElement().toString(); if (keepNext) next = element; keepNext = element.equals("{"); if (element.equals("}") && element != null) { log.debug("[R2RMLToolkit:extractColumnNamesFromStringTemplate] Extracted column name " + next + " from string template " + stringTemplate); result.add(next); next = null; } } } return result; }
From source file:com.liusoft.dlog4j.search.SearchProxy.java
/** * ?//w w w .java 2 s . c o m * @param params * @return * @throws Exception */ public static List search(SearchParameter params) throws Exception { if (params == null) return null; SearchEnabled searching = (SearchEnabled) params.getSearchObject().newInstance(); StringBuffer path = new StringBuffer(_baseIndexPath); path.append(searching.name()); File f = new File(path.toString()); if (!f.exists()) return null; IndexSearcher searcher = new IndexSearcher(path.toString()); //? BooleanQuery comboQuery = new BooleanQuery(); int _query_count = 0; StringTokenizer st = new StringTokenizer(params.getSearchKey()); while (st.hasMoreElements()) { String q = st.nextToken(); String[] indexFields = searching.getIndexFields(); for (int i = 0; i < indexFields.length; i++) { QueryParser qp = new QueryParser(indexFields[i], analyzer); try { Query subjectQuery = qp.parse(q); comboQuery.add(subjectQuery, BooleanClause.Occur.SHOULD); _query_count++; } catch (Exception e) { log.error("Add query parameter failed. key=" + q, e); } } } if (_query_count == 0)//? return null; //?? MultiFilter multiFilter = null; HashMap conds = params.getConditions(); if (conds != null) { Iterator keys = conds.keySet().iterator(); while (keys.hasNext()) { if (multiFilter == null) multiFilter = new MultiFilter(0); String key = (String) keys.next(); multiFilter.add(new FieldFilter(key, conds.get(key).toString())); } } /* * Creates a sort, possibly in reverse, * by terms in the given field with the type of term values explicitly given. */ SortField[] s_fields = new SortField[2]; s_fields[0] = SortField.FIELD_SCORE; s_fields[1] = new SortField(searching.getKeywordField(), SortField.INT, true); Sort sort = new Sort(s_fields); Hits hits = searcher.search(comboQuery, multiFilter, sort); int numResults = hits.length(); //System.out.println(numResults + " found............................"); int result_count = Math.min(numResults, MAX_RESULT_COUNT); List results = new ArrayList(result_count); for (int i = 0; i < result_count; i++) { Document doc = (Document) hits.doc(i); //Java Object result = params.getSearchObject().newInstance(); Enumeration fields = doc.fields(); while (fields.hasMoreElements()) { Field field = (Field) fields.nextElement(); //System.out.println(field.name()+" -- "+field.stringValue()); if (CLASSNAME_FIELD.equals(field.name())) continue; //? if (!field.isStored()) continue; //System.out.println("=========== begin to mapping ============"); //String --> anything Class fieldType = getNestedPropertyType(result, field.name()); //System.out.println(field.name()+", class = " + fieldType.getName()); Object fieldValue = null; if (fieldType.equals(Date.class)) fieldValue = new Date(Long.parseLong(field.stringValue())); else fieldValue = ConvertUtils.convert(field.stringValue(), fieldType); //System.out.println(fieldValue+", class = " + fieldValue.getClass().getName()); setNestedProperty(result, field.name(), fieldValue); } results.add(result); } return results; }