Example usage for java.util StringTokenizer nextToken

List of usage examples for java.util StringTokenizer nextToken

Introduction

In this page you can find the example usage for java.util StringTokenizer nextToken.

Prototype

public String nextToken() 

Source Link

Document

Returns the next token from this string tokenizer.

Usage

From source file:apim.restful.importexport.utils.AuthenticatorUtil.java

/**
 * Checks whether user has provided non blank username and password for authentication
 *
 * @param headers Http Headers of the request
 * @return boolean Whether a user name and password has been provided for authentication
 * @throws APIExportException If an error occurs while extracting username and password from
 *                            the header
 *//*w  ww. java 2 s.c  om*/
private static boolean isValidCredentials(HttpHeaders headers) throws APIExportException {

    //Fetch authorization header
    final List<String> authorization = headers.getRequestHeader(AUTHORIZATION_PROPERTY);

    //If no authorization information present; block access
    if (authorization == null || authorization.isEmpty()) {
        return false;
    }

    //Get encoded username and password
    final String encodedUserPassword = authorization.get(0).replaceFirst(AUTHENTICATION_SCHEME + " ", "");

    //Decode username and password
    String usernameAndPassword;
    usernameAndPassword = StringUtils.newStringUtf8(Base64.decodeBase64(encodedUserPassword.getBytes()));

    if (usernameAndPassword != null) {
        //Split username and password tokens
        final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");

        if (tokenizer.hasMoreTokens()) {
            username = tokenizer.nextToken();
        }

        if (tokenizer.hasMoreTokens()) {
            password = tokenizer.nextToken();
        }

        if (username != null && password != null) {
            return true;
        }
    }

    return false;
}

From source file:com.ai.smart.common.helper.util.RequestUtils.java

public static Map<String, String[]> parseQueryString(String s) {
    String valArray[] = null;//  www .j a va2  s  .co  m
    if (s == null) {
        throw new IllegalArgumentException();
    }
    Map<String, String[]> ht = new HashMap<String, String[]>();
    StringTokenizer st = new StringTokenizer(s, "&");
    while (st.hasMoreTokens()) {
        String pair = (String) st.nextToken();
        int pos = pair.indexOf('=');
        if (pos == -1) {
            continue;
        }
        String key = pair.substring(0, pos);
        String val = pair.substring(pos + 1, pair.length());
        if (ht.containsKey(key)) {
            String oldVals[] = (String[]) ht.get(key);
            valArray = new String[oldVals.length + 1];
            for (int i = 0; i < oldVals.length; i++) {
                valArray[i] = oldVals[i];
            }
            valArray[oldVals.length] = val;
        } else {
            valArray = new String[1];
            valArray[0] = val;
        }
        ht.put(key, valArray);
    }
    return ht;
}

From source file:Main.java

/**
 * /* w ww.  ja  v a2s .  c  o  m*/
 * @param value
 * @return Object[]
 */
public static Object[] toArray(final String value) {
    if (value == null) {
        return new Object[] {};
    }

    final int BRACKET_LENGTH = 1;
    final String strippedValue = value.substring(BRACKET_LENGTH, value.length() - BRACKET_LENGTH);
    final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ELEMENT_SEPARATOR);
    final Collection<Object> collection = new ArrayList<>();

    while (tokenizer.hasMoreTokens()) {
        collection.add(tokenizer.nextToken().trim());
    }

    return collection.toArray();
}

From source file:org.apache.geode.geospatial.utils.ToolBox.java

public static void configureDefaultClientPool(ClientCacheFactory clientCacheFactory, String locators) {
    StringTokenizer stringTokenizer = new StringTokenizer(locators, ",");
    clientCacheFactory.setPoolMaxConnections(-1);
    clientCacheFactory.setPoolPRSingleHopEnabled(true);

    while (stringTokenizer.hasMoreTokens()) {
        String curr = stringTokenizer.nextToken();
        DistributionLocatorId locatorId = new DistributionLocatorId(curr);
        String addr = locatorId.getBindAddress();
        if (addr != null && addr.trim().length() > 0) {
            clientCacheFactory.addPoolLocator(addr, locatorId.getPort());
        } else {/*from   w w  w  .  j  a v  a 2 s.c  o  m*/
            clientCacheFactory.addPoolLocator(locatorId.getHost().getHostName(), locatorId.getPort());
        }
    }
    clientCacheFactory.create();
}

From source file:net.ripe.rpki.commons.util.VersionedId.java

public static VersionedId parse(String s) {
    Validate.notNull(s, "string required");
    StringTokenizer tokenizer = new StringTokenizer(s, ":");
    int count = tokenizer.countTokens();
    Validate.isTrue(count == 1 || count == 2, "invalid number of tokens in versioned id");
    long id = Long.parseLong(tokenizer.nextToken());
    long version;
    if (tokenizer.hasMoreTokens()) {
        version = Long.parseLong(tokenizer.nextToken());
    } else {// ww w. ja  v a 2 s . co  m
        version = 0;
    }
    return new VersionedId(id, version);
}

From source file:com.sds.acube.ndisc.xnapi.XNApiUtils.java

/**
 *    ?/*from   w ww  .  ja va 2 s . co m*/
 * 
 * @param rcvmsg
 *              ?
 * @return  
 */
public static String getReplyMessage(String rcvmsg) {
    try {
        StringTokenizer sTK = new StringTokenizer(rcvmsg, XNApiConfig.DELIM_STR);
        rcvmsg = sTK.nextToken().trim();
        if (XNApiConfig.ERROR.equals(rcvmsg)) {
            throw new NDiscException(sTK.nextToken().trim());
        }
    } catch (Exception e) {
    }
    return rcvmsg;
}

From source file:com.twitter.hbc.example.FilterStreamExample.java

public static String classifyText(String msg) {

    //Delimeters need to be further extended.
    StringTokenizer st = new StringTokenizer(msg, "[,. #]+");
    int positive = 0, negative = 0, neutral = 0;
    while (st.hasMoreTokens()) {
        String next = st.nextToken().toLowerCase();
        //System.out.println(next);
        positive += (positiveList.contains(next) ? 1 : 0);
        negative += (negativeList.contains(next) ? 1 : 0);

        //See whether neutral adds any value, TODO -
        if (!positiveList.contains(next) && !negativeList.contains(next))
            neutral += (positiveList.contains(next) ? 1 : 0);
    }/*from w  w  w . ja  v a  2  s  .com*/
    return (positive == negative) ? "Neutral" : ((positive > negative) ? "Positive" : "Negative");
}

From source file:de.micromata.genome.gwiki.page.impl.actionbean.GWikiErrorsTag.java

/**
 * Verwendet einen StringTokenizer und liefert das Ergebnis als Liste
 *//*  w w  w.j  a  va 2 s  .c  om*/
public static List<String> parseStringTokens(String text, String delimiter, boolean returnDelimiter) {
    List<String> result = new ArrayList<String>();
    StringTokenizer st = new StringTokenizer(text, delimiter, returnDelimiter);
    while (st.hasMoreTokens() == true) {
        result.add(st.nextToken());
    }
    return result;
}

From source file:com.canoo.webtest.plugins.emailtest.AbstractSelectStep.java

static boolean doMatchMultiple(final String expected, final Address[] actuals) {
    // semantics are: if no expectation then match
    if (StringUtils.isEmpty(expected)) {
        return true;
    } else if (actuals == null) {
        return false;
    }// ww w. j a  v a 2 s. c  o m

    final StringTokenizer expectedTokens = new StringTokenizer(expected, ",");
    while (expectedTokens.hasMoreTokens()) {
        final String expectedToken = expectedTokens.nextToken().trim();
        boolean hasMatched = false;
        for (int i = 0; i < actuals.length; i++) {
            final Address actual = actuals[i];
            hasMatched = doMatch(expectedToken, actual.toString());
            if (hasMatched) {
                break;
            }
        }
        if (!hasMatched) {
            return false;
        }
    }
    return true;
}

From source file:IPAddress.java

/**
 * Check if the specified address is a valid numeric TCP/IP address
 * //from  w  ww.j a v a 2  s .  co m
 * @param ipaddr String
 * @return boolean
 */
public final static boolean isNumericAddress(String ipaddr) {

    //   Check if the string is valid

    if (ipaddr == null || ipaddr.length() < 7 || ipaddr.length() > 15)
        return false;

    //   Check the address string, should be n.n.n.n format

    StringTokenizer token = new StringTokenizer(ipaddr, ".");
    if (token.countTokens() != 4)
        return false;

    while (token.hasMoreTokens()) {

        //   Get the current token and convert to an integer value

        String ipNum = token.nextToken();

        try {
            int ipVal = Integer.valueOf(ipNum).intValue();
            if (ipVal < 0 || ipVal > 255)
                return false;
        } catch (NumberFormatException ex) {
            return false;
        }
    }

    //   Looks like a valid IP address

    return true;
}