Java Code Examples for java.util.StringTokenizer#nextElement()

The following examples show how to use java.util.StringTokenizer#nextElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SftpClient.java    From j2ssh-maverick with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * <p>
 * Create a directory or set of directories. This method will not fail even
 * if the directories exist. It is advisable to test whether the directory
 * exists before attempting an operation by using <a
 * href="#stat(java.lang.String)">stat</a> to return the directories
 * attributes.
 * </p>
 * 
 * @param dir
 *            the path of directories to create.
 */
public void mkdirs(String dir) throws SftpStatusException, SshException {
	StringTokenizer tokens = new StringTokenizer(dir, "/");
	String path = dir.startsWith("/") ? "/" : "";

	while (tokens.hasMoreElements()) {
		path += (String) tokens.nextElement();

		try {
			stat(path);
		} catch (SftpStatusException ex) {
			try {
				mkdir(path);
			} catch (SftpStatusException ex2) {
				if (ex2.getStatus() == SftpStatusException.SSH_FX_PERMISSION_DENIED)
					throw ex2;
			}
		}

		path += "/";
	}
}
 
Example 2
Source File: MimeEntry.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void setExtensions(String extensionString) {
    StringTokenizer extTokens = new StringTokenizer(extensionString, ",");
    int numExts = extTokens.countTokens();
    String extensionStrings[] = new String[numExts];

    for (int i = 0; i < numExts; i++) {
        String ext = (String)extTokens.nextElement();
        extensionStrings[i] = ext.trim();
    }

    fileExtensions = extensionStrings;
}
 
Example 3
Source File: IEngineImpl.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
private boolean canUpdateElement(String path) {
    StringTokenizer st = new StringTokenizer(path, "/");
    st.nextElement();
    long elementId = Long.parseLong(st.nextToken());
    long attributeId = Long.parseLong(st.nextToken());
    return accessor.canUpdateElement(elementId, attributeId);
}
 
Example 4
Source File: TestCacheAccess.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
/**
 * @param message
 * @throws CacheException
 */
private void processPutGroup( String message )
    throws CacheException
{
    String group = null;
    String key = null;
    StringTokenizer toke = new StringTokenizer( message );
    int tcnt = 0;
    while ( toke.hasMoreElements() )
    {
        tcnt++;
        String t = (String) toke.nextElement();
        if ( tcnt == 2 )
        {
            key = t.trim();
        }
        else if ( tcnt == 3 )
        {
            group = t.trim();
        }
    }

    if ( tcnt < 3 )
    {
        p( "usage: putg key group" );
    }
    else
    {
        long n_start = System.currentTimeMillis();
        group_cache_control.putInGroup( key, group, "data from putg ----asdfasfas-asfasfas-asfas in group " + group );
        long n_end = System.currentTimeMillis();
        p( "---put " + key + " in group " + group + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
    }
}
 
Example 5
Source File: ElastistorPrimaryDataStoreLifeCycle.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
private String getAccessPath(String url) {
    StringTokenizer st = new StringTokenizer(url, "/");
    int count = 0;
    while (st.hasMoreElements()) {
        if (count == 2) {
            String s = "/";
            return s.concat(st.nextElement().toString());
        }
        st.nextElement();
        count++;
    }
    return null;
}
 
Example 6
Source File: MimeEntry.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void setExtensions(String extensionString) {
    StringTokenizer extTokens = new StringTokenizer(extensionString, ",");
    int numExts = extTokens.countTokens();
    String extensionStrings[] = new String[numExts];

    for (int i = 0; i < numExts; i++) {
        String ext = (String)extTokens.nextElement();
        extensionStrings[i] = ext.trim();
    }

    fileExtensions = extensionStrings;
}
 
Example 7
Source File: MimeEntry.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void setExtensions(String extensionString) {
    StringTokenizer extTokens = new StringTokenizer(extensionString, ",");
    int numExts = extTokens.countTokens();
    String extensionStrings[] = new String[numExts];

    for (int i = 0; i < numExts; i++) {
        String ext = (String)extTokens.nextElement();
        extensionStrings[i] = ext.trim();
    }

    fileExtensions = extensionStrings;
}
 
Example 8
Source File: MimeEntry.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void setExtensions(String extensionString) {
    StringTokenizer extTokens = new StringTokenizer(extensionString, ",");
    int numExts = extTokens.countTokens();
    String extensionStrings[] = new String[numExts];

    for (int i = 0; i < numExts; i++) {
        String ext = (String)extTokens.nextElement();
        extensionStrings[i] = ext.trim();
    }

    fileExtensions = extensionStrings;
}
 
Example 9
Source File: KeyIndex.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Given a context node and the argument to the XPath <code>id</code>
 * function, checks whether the context node is in the set of nodes that
 * results from that reference to the <code>id</code> function.  This is
 * used in the implementation of <code>id</code> patterns.
 *
 * @param node The context node
 * @param value The argument to the <code>id</code> function
 * @return <code>1</code> if the context node is in the set of nodes
 *         returned by the reference to the <code>id</code> function;
 *         <code>0</code>, otherwise
 */
public int containsID(int node, Object value) {
    final String string = (String)value;
    int rootHandle = _dom.getAxisIterator(Axis.ROOT)
                             .setStartNode(node).next();

    // Get the mapping table for the document containing the context node
    Map<String, IntegerArray> index =
        _rootToIndexMap.get(rootHandle);

    // Split argument to id function into XML whitespace separated tokens
    final StringTokenizer values = new StringTokenizer(string, " \n\t");

    while (values.hasMoreElements()) {
        final String token = (String) values.nextElement();
        IntegerArray nodes = null;

        if (index != null) {
            nodes = index.get(token);
        }

        // If input was from W3C DOM, use DOM's getElementById to do
        // the look-up.
        if (nodes == null && _enhancedDOM != null
            && _enhancedDOM.hasDOMSource()) {
            nodes = getDOMNodeById(token);
        }

        // Did we find the context node in the set of nodes?
        if (nodes != null && nodes.indexOf(node) >= 0) {
            return 1;
        }
    }

    // Didn't find the context node in the set of nodes returned by id
    return 0;
}
 
Example 10
Source File: TestCacheAccess.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
/**
 * @param message
 * @throws CacheException
 */
private void processPutAutoGroup( String message )
    throws CacheException
{
    String group = null;
    int num = 0;
    StringTokenizer toke = new StringTokenizer( message );
    int tcnt = 0;
    while ( toke.hasMoreElements() )
    {
        tcnt++;
        String t = (String) toke.nextElement();
        if ( tcnt == 2 )
        {
            num = Integer.parseInt( t.trim() );
        }
        else if ( tcnt == 3 )
        {
            group = t.trim();
        }
    }

    if ( tcnt < 3 )
    {
        p( "usage: putag num group" );
    }
    else
    {
        long n_start = System.currentTimeMillis();
        for ( int a = 0; a < num; a++ )
        {
            group_cache_control.putInGroup( "keygr" + a, group, "data " + a
                + " from putag ----asdfasfas-asfasfas-asfas in group " + group );
        }
        long n_end = System.currentTimeMillis();
        p( "---put " + num + " in group " + group + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
    }
}
 
Example 11
Source File: KeyIndex.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given a context node and the argument to the XPath <code>id</code>
 * function, checks whether the context node is in the set of nodes that
 * results from that reference to the <code>id</code> function.  This is
 * used in the implementation of <code>id</code> patterns.
 *
 * @param node The context node
 * @param value The argument to the <code>id</code> function
 * @return <code>1</code> if the context node is in the set of nodes
 *         returned by the reference to the <code>id</code> function;
 *         <code>0</code>, otherwise
 */
public int containsID(int node, Object value) {
    final String string = (String)value;
    int rootHandle = _dom.getAxisIterator(Axis.ROOT)
                             .setStartNode(node).next();

    // Get the mapping table for the document containing the context node
    Map<String, IntegerArray> index =
        _rootToIndexMap.get(new Integer(rootHandle));

    // Split argument to id function into XML whitespace separated tokens
    final StringTokenizer values = new StringTokenizer(string, " \n\t");

    while (values.hasMoreElements()) {
        final String token = (String) values.nextElement();
        IntegerArray nodes = null;

        if (index != null) {
            nodes = index.get(token);
        }

        // If input was from W3C DOM, use DOM's getElementById to do
        // the look-up.
        if (nodes == null && _enhancedDOM != null
            && _enhancedDOM.hasDOMSource()) {
            nodes = getDOMNodeById(token);
        }

        // Did we find the context node in the set of nodes?
        if (nodes != null && nodes.indexOf(node) >= 0) {
            return 1;
        }
    }

    // Didn't find the context node in the set of nodes returned by id
    return 0;
}
 
Example 12
Source File: MimeLauncher.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private boolean findExecutablePath(String str) {
    if (str == null || str.length() == 0) {
        return false;
    }

    String command;
    int index = str.indexOf(' ');
    if (index != -1) {
        command = str.substring(0, index);
    }
    else {
        command = str;
    }

    File f = new File(command);
    if (f.isFile()) {
        // Already executable as it is
        execPath = str;
        return true;
    }

    String execPathList;
    execPathList = java.security.AccessController.doPrivileged(
            new sun.security.action.GetPropertyAction("exec.path"));
    if (execPathList == null) {
        // exec.path property not set
        return false;
    }

    StringTokenizer iter = new StringTokenizer(execPathList, "|");
    while (iter.hasMoreElements()) {
        String prefix = (String)iter.nextElement();
        String fullCmd = prefix + File.separator + command;
        f = new File(fullCmd);
        if (f.isFile()) {
            execPath = prefix + File.separator + str;
            return true;
        }
    }

    return false; // application not found in exec.path
}
 
Example 13
Source File: TestCacheAccess.java    From commons-jcs with Apache License 2.0 4 votes vote down vote up
/**
 * @param message
 */
private void processGet( String message )
{
    // plain old get

    String key = null;
    boolean show = true;

    StringTokenizer toke = new StringTokenizer( message );
    int tcnt = 0;
    while ( toke.hasMoreElements() )
    {
        tcnt++;
        String t = (String) toke.nextElement();
        if ( tcnt == 2 )
        {
            key = t.trim();
        }
        else if ( tcnt == 3 )
        {
            show = Boolean.valueOf( t ).booleanValue();
        }
    }

    if ( tcnt < 2 )
    {
        p( "usage: get key show values[true|false]" );
    }
    else
    {
        long n_start = System.currentTimeMillis();
        try
        {
            Object obj = cache_control.get( key );
            if ( show && obj != null )
            {
                p( obj.toString() );
            }
        }
        catch ( Exception e )
        {
            log.error( e );
        }
        long n_end = System.currentTimeMillis();
        p( "---got " + key + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
    }
}
 
Example 14
Source File: ImgPostscript.java    From MesquiteCore with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * This method checks if the image is a valid Postscript and processes some parameters.
 * @throws BadElementException
 * @throws IOException
 */

private void processParameters() throws BadElementException, IOException {
    type = IMGTEMPLATE;
    originalType = ORIGINAL_PS;
    InputStream is = null;
    try {
        String errorID;
        if (rawData == null) {
            is = url.openStream();
            errorID = url.toString();
        }
        else {
            is = new java.io.ByteArrayInputStream(rawData);
            errorID = "Byte array";
        }
        String boundingbox=null;
        Reader r = new BufferedReader(new InputStreamReader(is));
        //  StreamTokenizer st = new StreamTokenizer(r);
        while (r.ready()) {
            char c;
            StringBuffer sb = new StringBuffer();
            while ( (c = ( (char) r.read())) != '\n') {
                sb.append(c);
            }
            //System.out.println("<<" + sb.toString() + ">>");
            if (sb.toString().startsWith("%%BoundingBox:")) {
                boundingbox = sb.toString();
                
            }
            if (sb.toString().startsWith("%%TemplateBox:")) {
                boundingbox = sb.toString();
            }
            if (sb.toString().startsWith("%%EndComments")) {
                break;
            }
            
        }
        if(boundingbox==null)return;
        StringTokenizer st=new StringTokenizer(boundingbox,": \r\n");
        st.nextElement();
        String xx1=st.nextToken();
        String yy1=st.nextToken();
        String xx2=st.nextToken();
        String yy2=st.nextToken();
        
        int left = Integer.parseInt(xx1);
        int top = Integer.parseInt(yy1);
        int right = Integer.parseInt(xx2);
        int bottom = Integer.parseInt(yy2);
        int inch = 1;
        dpiX = 72;
        dpiY = 72;
        scaledHeight = (float) (bottom - top) / inch *1f;
        scaledHeight=800;
        setTop(scaledHeight);
        scaledWidth = (float) (right - left) / inch * 1f;
        scaledWidth=800;
        setRight(scaledWidth);
    }
    finally {
        if (is != null) {
            is.close();
        }
        plainWidth = width();
        plainHeight = height();
    }
}
 
Example 15
Source File: SESConnector.java    From SensorWebClient with GNU General Public License v2.0 4 votes vote down vote up
private String[] getSingleObservations(ObservationPropertyType observations) {

        String obsPropType = observations.xmlText();
        
        // Determining how many observations are contained in the observation collection
        Pattern countPattern = Pattern.compile("<swe:value>(.*?)</swe:value>");
        Matcher countMatcher = countPattern.matcher(obsPropType);
        String countString = null;
        if (countMatcher.find()) {
            countString = countMatcher.group(1).trim();
        }
        int observationCount = Integer.parseInt(countString);

        // This array will contain one observation string for each observation of the observation
        // collection
        String[] outputStrings;

        // If the observation collection contains only one value it can be directly returned
        if (observationCount == 1) {
            outputStrings = new String[] {obsPropType};
        }

        // If the observation collection contains more than one value it must be split
        else {

            // Extracting the values that are contained in the observation collection and creating a
            // StringTokenizer that allows to access the values
            Pattern valuesPattern = Pattern.compile("<swe:values>(.*?)</swe:values>");
            Matcher valuesMatcher = valuesPattern.matcher(obsPropType);
            String valuesString = null;
            if (valuesMatcher.find()) {
                valuesString = valuesMatcher.group(1).trim();
            }

            StringTokenizer valuesTokenizer = new StringTokenizer(valuesString, ";");
            // If only the latest observation is wished, find youngest
            // observation.
            if (FeederConfig.getFeederConfig().isOnlyYoungestName()) {
                DateTime youngest = new DateTime(0);
                String youngestValues = "";
                DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
                while (valuesTokenizer.hasMoreElements()) {
                    String valueString = (String) valuesTokenizer.nextElement();
                    DateTime time = fmt.parseDateTime(valueString.split(",")[0]);
                    if (time.isAfter(youngest.getMillis())) {
                        youngest = time;
                        youngestValues = valueString;
                    }
                }
                outputStrings = new String[] {createSingleObservationString(obsPropType, youngestValues)};
            }
            else {
                outputStrings = new String[observationCount];

                for (int i = 0; i < observationCount; i++) {

                    // Add the extracted observation to an array containing
                    // all extracted observations
                    outputStrings[i] = createSingleObservationString(obsPropType, valuesTokenizer.nextToken());
                }
            }

        }
        // Returning the extracted observations
        return outputStrings;
    }
 
Example 16
Source File: MimeLauncher.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean findExecutablePath(String str) {
    if (str == null || str.length() == 0) {
        return false;
    }

    String command;
    int index = str.indexOf(' ');
    if (index != -1) {
        command = str.substring(0, index);
    }
    else {
        command = str;
    }

    File f = new File(command);
    if (f.isFile()) {
        // Already executable as it is
        execPath = str;
        return true;
    }

    String execPathList;
    execPathList = java.security.AccessController.doPrivileged(
            new sun.security.action.GetPropertyAction("exec.path"));
    if (execPathList == null) {
        // exec.path property not set
        return false;
    }

    StringTokenizer iter = new StringTokenizer(execPathList, "|");
    while (iter.hasMoreElements()) {
        String prefix = (String)iter.nextElement();
        String fullCmd = prefix + File.separator + command;
        f = new File(fullCmd);
        if (f.isFile()) {
            execPath = prefix + File.separator + str;
            return true;
        }
    }

    return false; // application not found in exec.path
}
 
Example 17
Source File: MimeLauncher.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean findExecutablePath(String str) {
    if (str == null || str.length() == 0) {
        return false;
    }

    String command;
    int index = str.indexOf(' ');
    if (index != -1) {
        command = str.substring(0, index);
    }
    else {
        command = str;
    }

    File f = new File(command);
    if (f.isFile()) {
        // Already executable as it is
        execPath = str;
        return true;
    }

    String execPathList;
    execPathList = java.security.AccessController.doPrivileged(
            new sun.security.action.GetPropertyAction("exec.path"));
    if (execPathList == null) {
        // exec.path property not set
        return false;
    }

    StringTokenizer iter = new StringTokenizer(execPathList, "|");
    while (iter.hasMoreElements()) {
        String prefix = (String)iter.nextElement();
        String fullCmd = prefix + File.separator + command;
        f = new File(fullCmd);
        if (f.isFile()) {
            execPath = prefix + File.separator + str;
            return true;
        }
    }

    return false; // application not found in exec.path
}
 
Example 18
Source File: PersistentClass.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private Property getRecursiveProperty(String propertyPath, Iterator iter) throws MappingException {
	Property property = null;
	StringTokenizer st = new StringTokenizer( propertyPath, ".", false );
	try {
		while ( st.hasMoreElements() ) {
			final String element = (String) st.nextElement();
			if ( property == null ) {
				Property identifierProperty = getIdentifierProperty();
				if ( identifierProperty != null && identifierProperty.getName().equals( element ) ) {
					// we have a mapped identifier property and the root of
					// the incoming property path matched that identifier
					// property
					property = identifierProperty;
				}
				else if ( identifierProperty == null && getIdentifierMapper() != null ) {
					// we have an embedded composite identifier
					try {
						identifierProperty = getProperty( element, getIdentifierMapper().getPropertyIterator() );
						if ( identifierProperty != null ) {
							// the root of the incoming property path matched one
							// of the embedded composite identifier properties
							property = identifierProperty;
						}
					}
					catch (MappingException ignore) {
						// ignore it...
					}
				}

				if ( property == null ) {
					property = getProperty( element, iter );
				}
			}
			else {
				//flat recursive algorithm
				property = ( (Component) property.getValue() ).getProperty( element );
			}
		}
	}
	catch (MappingException e) {
		throw new MappingException( "property [" + propertyPath + "] not found on entity [" + getEntityName() + "]" );
	}

	return property;
}
 
Example 19
Source File: SamlTokenUtil.java    From vsphere-automation-sdk-java with MIT License 4 votes vote down vote up
/**
 * Method to to get SAML Bearer token from the vCenter Server by using the access token
 * retrieved from CSP. 
 * 
 * @param accessToken Access Token
 * @param idToken ID Token
 * @param vCenterServer vCenter host name or IP address
 * @return
 */
public static Element getSamlTokenByApiAccessToken(String vCenterServer, String accessToken, String idToken)
		throws Exception {
	// Create the REST URL
	String vcHostnameUri = "https://" + vCenterServer + VCENTER_TOKENEXCHANGE_ENDPOINT;
	URL url = new URL(vcHostnameUri);

	// Create the REST Header
	Map<String, String> headers = new HashMap<String, String>();
	headers.put("Content-Type", "application/json");
	headers.put("Accept", "application/json");

	headers.put("Authorization", "Bearer " + accessToken);

	// POST the REST CALL and get the API Response
	String payload = "{ \"spec\": { \"subject_token\":\"" + accessToken + "\","
			+ "\"subject_token_type\":\"urn:ietf:params:oauth:token-type:access_token\", \""
			+ "requested_token_type\": \"urn:ietf:params:oauth:token-type:saml2\","
			+ "\"grant_type\": \"urn:ietf:params:oauth:grant-type:token-exchange\","
			+ "\"actor_token_type\":\"urn:ietf:params:oauth:token-type:id_token\","
			+ "\"actor_token\":\"" + idToken + "\"} }";

	URLEncoder.encode(payload, "UTF-8");

	Map<Integer, String> apiResponse = RestHandler.httpPost(url, headers, payload);
	Iterator<Integer> itr = apiResponse.keySet().iterator();
	Integer key = itr.next();
	String local_response = apiResponse.get(key).replaceFirst("\\{", "").replace("\\}", "");
	StringTokenizer tokenizer = new StringTokenizer(local_response, ",");
	while (tokenizer.hasMoreElements()) {
		String element = (String) tokenizer.nextElement();
		String[] res = element.split(":");
		String accessTokenElements = res[1].replaceFirst("\\{", "").replace("\\}", "");
		String replacedAcessToken = accessTokenElements.toString().replaceAll("\"", "");
		if ("access_token".equalsIgnoreCase(replacedAcessToken)) {
			String samlToken = res[2];
			String replacedSamlToken = samlToken.replaceAll("\"", "");
			byte[] decodedBytes = DatatypeConverter.parseBase64Binary(replacedSamlToken);
			String decodedSamlToken = new String(decodedBytes, "UTF-8");
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			factory.setNamespaceAware(true);
			DocumentBuilder builder;
			builder = factory.newDocumentBuilder();
			Document doc = builder.parse(new InputSource(new StringReader(decodedSamlToken)));
			return doc.getDocumentElement();
		}
	}
	
	throw new Exception("Error encountered while retrieving saml bearer token using access token");
}
 
Example 20
Source File: MimeLauncher.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private boolean findExecutablePath(String str) {
    if (str == null || str.length() == 0) {
        return false;
    }

    String command;
    int index = str.indexOf(' ');
    if (index != -1) {
        command = str.substring(0, index);
    }
    else {
        command = str;
    }

    File f = new File(command);
    if (f.isFile()) {
        // Already executable as it is
        execPath = str;
        return true;
    }

    String execPathList;
    execPathList = java.security.AccessController.doPrivileged(
            new sun.security.action.GetPropertyAction("exec.path"));
    if (execPathList == null) {
        // exec.path property not set
        return false;
    }

    StringTokenizer iter = new StringTokenizer(execPathList, "|");
    while (iter.hasMoreElements()) {
        String prefix = (String)iter.nextElement();
        String fullCmd = prefix + File.separator + command;
        f = new File(fullCmd);
        if (f.isFile()) {
            execPath = prefix + File.separator + str;
            return true;
        }
    }

    return false; // application not found in exec.path
}