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:com.aimluck.eip.util.ALCellularUtils.java

/**
 * ?? ID ????/*from  ww  w  .j ava2 s . c  o  m*/
 * 
 * @param rundata
 * @return
 */
public static String getCellularUid(RunData rundata) {
    String password = "";
    JetspeedRunData data = (JetspeedRunData) rundata;
    String useragent = data.getRequest().getHeader("User-Agent");
    if (useragent != null && useragent.length() > 0) {
        useragent = useragent.trim();
        CapabilityMap cm = CapabilityMapFactory.getCapabilityMap(useragent);
        MimeType mime = cm.getPreferredType();
        if (mime != null) {
            MediaTypeEntry media = (MediaTypeEntry) Registry.getEntry(Registry.MEDIA_TYPE,
                    cm.getPreferredMediaType());
            if ("docomo_imode".equals(media.getName())) {
                int lastindex = useragent.lastIndexOf("ser");
                if (lastindex >= 0) {
                    password = useragent.substring(lastindex, useragent.length());
                }
            } else if ("docomo_foma".equals(media.getName())) {
                StringTokenizer st = new StringTokenizer(useragent, ";");
                String token = null;
                while (st.hasMoreTokens()) {
                    if ((token = st.nextToken()).startsWith("ser")) {
                        password = token.trim();
                        break;
                    }
                }
            } else if ("au".equals(media.getName())) {
                String header = data.getRequest().getHeader("x-up-subno");
                if (header != null && header.length() > 0) {
                    int index = header.indexOf("_");
                    if (index >= 0) {
                        password = header.substring(0, index);
                    }
                }
            } else if ("vodafone".equals(media.getName())) {
                int index = useragent.indexOf("SN");
                if (index >= 0) {
                    int delta = -1;
                    if (useragent.startsWith("J-PHONE/4")) {
                        delta = 10;
                    } else if (useragent.startsWith("J-PHONE/5")) {
                        delta = 15;
                    } else if (useragent.startsWith("Vodafone")) {
                        delta = 15;
                    } else if (useragent.startsWith("SoftBank")) {
                        delta = 15;
                    }
                    if (index >= 0 && delta > 0) {
                        password = useragent.substring(index, index + 2 + delta);
                    }
                } else {
                    String jphoneUid = data.getRequest().getHeader("x-jphone-uid");
                    if (jphoneUid != null) {
                        password = jphoneUid;
                    }
                }
            }
        }
    }
    return password;
}

From source file:keel.Algorithms.Neural_Networks.NNEP_Clas.KEELWrapperClas.java

/**
 * <p>/*from ww  w.ja v a 2  s.  c  o m*/
 * Reads schema from the KEEL file
 * 
 * @param jobFilename Name of the KEEL dataset file
 * </p>
 */

private static byte[] readSchema(String fileName) throws IOException, DatasetException {

    KeelDataSet dataset = new KeelDataSet(fileName);
    dataset.open();

    File file = new File(fileName);

    List<String> inputIds = new ArrayList<String>();
    List<String> outputIds = new ArrayList<String>();

    Reader reader = new BufferedReader(new FileReader(file));
    String line = ((BufferedReader) reader).readLine();
    line = line.replace("real[", "real [");
    line = line.replace("integer[", "integer [");
    line = line.replace("{", " {");
    StringTokenizer elementLine = new StringTokenizer(line);
    String element = elementLine.nextToken();

    while (!element.equalsIgnoreCase("@data")) {

        if (element.equalsIgnoreCase("@inputs")) {
            while (elementLine.hasMoreTokens()) {
                StringTokenizer commaTokenizer = new StringTokenizer(elementLine.nextToken(), ",");
                while (commaTokenizer.hasMoreTokens())
                    inputIds.add(commaTokenizer.nextToken());
            }
        } else if (element.equalsIgnoreCase("@outputs")) {
            while (elementLine.hasMoreTokens()) {
                StringTokenizer commaTokenizer = new StringTokenizer(elementLine.nextToken(), ",");
                while (commaTokenizer.hasMoreTokens())
                    outputIds.add(commaTokenizer.nextToken());
            }
        }

        // Next line of the file
        line = ((BufferedReader) reader).readLine();
        while (line.startsWith("%") || line.equalsIgnoreCase(""))
            line = ((BufferedReader) reader).readLine();

        line = line.replace("real[", "real [");
        line = line.replace("integer[", "integer [");
        line = line.replace("{", " {");
        elementLine = new StringTokenizer(line);
        element = elementLine.nextToken();
    }

    IMetadata metadata = dataset.getMetadata();
    byte[] schema = new byte[metadata.numberOfAttributes()];

    if (inputIds.isEmpty() || outputIds.isEmpty()) {
        for (int i = 0; i < schema.length; i++) {
            if (i != (schema.length - 1))
                schema[i] = 1;
            else {
                IAttribute outputAttribute = metadata.getAttribute(i);
                schema[i] = 2;
                consoleReporter.setOutputAttribute(outputAttribute);
            }
        }
    } else {
        for (int i = 0; i < schema.length; i++) {
            if (inputIds.contains(metadata.getAttribute(i).getName()))
                schema[i] = 1;
            else if (outputIds.contains(metadata.getAttribute(i).getName())) {
                IAttribute outputAttribute = metadata.getAttribute(i);
                schema[i] = 2;
                consoleReporter.setOutputAttribute(outputAttribute);
            } else
                schema[i] = -1;
        }
    }

    StringBuffer header = new StringBuffer();
    header.append("@relation " + dataset.getName() + "\n");
    for (int i = 0; i < metadata.numberOfAttributes(); i++) {
        IAttribute attribute = metadata.getAttribute(i);
        header.append("@attribute " + attribute.getName() + " ");
        if (attribute.getType() == AttributeType.Categorical) {
            CategoricalAttribute catAtt = (CategoricalAttribute) attribute;

            Interval interval = catAtt.intervalValues();

            header.append("{");
            for (int j = (int) interval.getLeft(); j <= interval.size() + 1; j++) {
                header.append(catAtt.show(j) + (j != interval.size() + 1 ? "," : "}\n"));
            }
        } else if (attribute.getType() == AttributeType.IntegerNumerical) {
            IntegerNumericalAttribute intAtt = (IntegerNumericalAttribute) attribute;
            header.append("integer[" + (int) intAtt.intervalValues().getLeft() + ","
                    + (int) intAtt.intervalValues().getRight() + "]\n");
        } else if (attribute.getType() == AttributeType.DoubleNumerical) {
            RealNumericalAttribute doubleAtt = (RealNumericalAttribute) attribute;
            header.append("real[" + doubleAtt.intervalValues().getLeft() + ","
                    + doubleAtt.intervalValues().getRight() + "]\n");
        }
    }
    header.append("@data\n");
    consoleReporter.setHeader(header.toString());

    dataset.close();
    return schema;
}

From source file:com.adaptris.core.http.jetty.HttpsConnection.java

private static String[] asArray(String s) {
    if (s == null) {
        return new String[0];
    }//  w  w w .  j  ava2  s  .c  o m
    StringTokenizer st = new StringTokenizer(s, ",");
    List<String> l = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        String tok = st.nextToken().trim();
        if (!isEmpty(tok))
            l.add(tok);
    }
    return l.toArray(new String[0]);
}

From source file:com.concursive.connect.web.webdav.WebdavManager.java

protected static HashMap getAuthenticationParams(String argHeader) {
    HashMap params = new HashMap();
    StringTokenizer st = new StringTokenizer(argHeader, ",");
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (token.startsWith("Digest")) {
            token = token.substring("Digest".length());
        }// w  w w.j a  v a  2 s .c o m
        if (token.contains("=") && token.contains("\"")) {
            String param = token.substring(0, token.indexOf("=")).trim();
            String value = token.substring(token.indexOf("\"") + 1, token.lastIndexOf("\""));
            params.put(param, value);
        }
    }
    return params;
}

From source file:com.teamsun.framework.util.ConvertUtil.java

/**
 * lf add ??/*from w w  w . j  a  v  a  2 s. c  o m*/
 */
public static String dealField(String field) {

    String result = "";
    if (StringUtils.isEmpty(field))
        return result;
    if (field.indexOf("_") > -1) {
        StringBuffer sb = new StringBuffer();
        StringTokenizer st = new StringTokenizer(field, "_");
        int i = 0;
        while (st.hasMoreTokens()) {
            if (i == 0)
                sb.append(st.nextToken().toLowerCase());
            else {
                String sec = st.nextToken();
                String one = sec.substring(0, 1);
                String two = sec.substring(1);
                sec = one.toLowerCase() + two.toLowerCase();
                sb.append(sec);
            }
            i++;
        }
        result = sb.toString();
    } else {
        // _???????
        result = field.toLowerCase();
    }
    return result;
}

From source file:keel.Algorithms.Neural_Networks.NNEP_Regr.KEELWrapperRegr.java

/**
 * <p>//from w ww . j a  v a2  s  . c o m
 * Reads schema from the KEEL file
 * </p>
 * @param jobFilename Name of the KEEL dataset file
 */

private static byte[] readSchema(String fileName) throws IOException, DatasetException {

    KeelDataSet dataset = new KeelDataSet(fileName);
    dataset.open();

    File file = new File(fileName);

    List<String> inputIds = new ArrayList<String>();
    List<String> outputIds = new ArrayList<String>();

    Reader reader = new BufferedReader(new FileReader(file));
    String line = ((BufferedReader) reader).readLine();
    line = line.replace("real[", "real [");
    line = line.replace("integer[", "integer [");
    line = line.replace("{", " {");
    StringTokenizer elementLine = new StringTokenizer(line);
    String element = elementLine.nextToken();

    while (!element.equalsIgnoreCase("@data")) {

        if (element.equalsIgnoreCase("@inputs")) {
            while (elementLine.hasMoreTokens()) {
                StringTokenizer commaTokenizer = new StringTokenizer(elementLine.nextToken(), ",");
                while (commaTokenizer.hasMoreTokens())
                    inputIds.add(commaTokenizer.nextToken());
            }
        } else if (element.equalsIgnoreCase("@outputs")) {
            while (elementLine.hasMoreTokens()) {
                StringTokenizer commaTokenizer = new StringTokenizer(elementLine.nextToken(), ",");
                while (commaTokenizer.hasMoreTokens())
                    outputIds.add(commaTokenizer.nextToken());
            }
        }

        // Next line of the file
        line = ((BufferedReader) reader).readLine();
        while (line.startsWith("%") || line.equalsIgnoreCase(""))
            line = ((BufferedReader) reader).readLine();

        line = line.replace("real[", "real [");
        line = line.replace("integer[", "integer [");
        line = line.replace("{", " {");

        elementLine = new StringTokenizer(line);
        element = elementLine.nextToken();
    }

    IMetadata metadata = dataset.getMetadata();
    byte[] schema = new byte[metadata.numberOfAttributes()];

    if (inputIds.isEmpty() || outputIds.isEmpty()) {
        for (int i = 0; i < schema.length; i++) {
            if (i != (schema.length - 1))
                schema[i] = 1;
            else {
                IAttribute outputAttribute = metadata.getAttribute(i);
                schema[i] = 2;
                consoleReporter.setOutputAttribute(outputAttribute);
            }
        }
    } else {
        for (int i = 0; i < schema.length; i++) {
            if (inputIds.contains(metadata.getAttribute(i).getName()))
                schema[i] = 1;
            else if (outputIds.contains(metadata.getAttribute(i).getName())) {
                IAttribute outputAttribute = metadata.getAttribute(i);
                schema[i] = 2;
                consoleReporter.setOutputAttribute(outputAttribute);
            } else
                schema[i] = -1;
        }
    }

    StringBuffer header = new StringBuffer();
    header.append("@relation " + dataset.getName() + "\n");
    for (int i = 0; i < metadata.numberOfAttributes(); i++) {
        IAttribute attribute = metadata.getAttribute(i);
        header.append("@attribute " + attribute.getName() + " ");
        if (attribute.getType() == AttributeType.Categorical) {
            CategoricalAttribute catAtt = (CategoricalAttribute) attribute;

            Interval interval = catAtt.intervalValues();

            header.append("{");
            for (int j = (int) interval.getLeft(); j <= interval.size() + 1; j++) {
                header.append(catAtt.show(j) + (j != interval.size() + 1 ? "," : "}\n"));
            }
        } else if (attribute.getType() == AttributeType.IntegerNumerical) {
            IntegerNumericalAttribute intAtt = (IntegerNumericalAttribute) attribute;
            header.append("integer[" + (int) intAtt.intervalValues().getLeft() + ","
                    + (int) intAtt.intervalValues().getRight() + "]\n");
        } else if (attribute.getType() == AttributeType.DoubleNumerical) {
            RealNumericalAttribute doubleAtt = (RealNumericalAttribute) attribute;
            header.append("real[" + doubleAtt.intervalValues().getLeft() + ","
                    + doubleAtt.intervalValues().getRight() + "]\n");
        }
    }
    header.append("@data\n");
    consoleReporter.setHeader(header.toString());

    dataset.close();
    return schema;
}

From source file:hudson.plugins.testlink.util.TestLinkHelper.java

/**
 * Maybe adds a system property if it is in format <key>=<value>.
 * /* www  . j a va  2 s  .  c  o m*/
 * @param systemProperty System property entry in format <key>=<value>.
 * @param listener Jenkins Build listener
 */
public static void maybeAddSystemProperty(String systemProperty, BuildListener listener) {
    final StringTokenizer tokenizer = new StringTokenizer(systemProperty, "=:");
    if (tokenizer.countTokens() == 2) {
        final String key = tokenizer.nextToken();
        final String value = tokenizer.nextToken();

        if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(value)) {
            if (key.contains(BASIC_HTTP_PASSWORD)) {
                listener.getLogger().println(Messages.TestLinkBuilder_SettingSystemProperty(key, "********"));
            } else {
                listener.getLogger().println(Messages.TestLinkBuilder_SettingSystemProperty(key, value));
            }
            try {
                System.setProperty(key, value);
            } catch (SecurityException se) {
                se.printStackTrace(listener.getLogger());
            }

        }
    }
}

From source file:Main.java

/**
 * Given an {@link NNTPClient} instance, and an integer range of messages, return 
 * an array of {@link Article} instances.
 * @param client //from  www  . j a  va2  s.  c  o  m
 * @param lowArticleNumber
 * @param highArticleNumber
 * @return Article[] An array of Article
 * @throws IOException
 */
public static Article[] getArticleInfo(NNTPClient client, int lowArticleNumber, int highArticleNumber)
        throws IOException {
    Reader reader = null;
    Article[] articles = null;
    reader = (DotTerminatedMessageReader) client.retrieveArticleInfo(lowArticleNumber, highArticleNumber);

    if (reader != null) {
        String theInfo = readerToString(reader);
        StringTokenizer st = new StringTokenizer(theInfo, "\n");

        // Extract the article information
        // Mandatory format (from NNTP RFC 2980) is :
        // Subject\tAuthor\tDate\tID\tReference(s)\tByte Count\tLine Count

        int count = st.countTokens();
        articles = new Article[count];
        int index = 0;

        while (st.hasMoreTokens()) {
            StringTokenizer stt = new StringTokenizer(st.nextToken(), "\t");
            Article article = new Article();
            article.setArticleNumber(Integer.parseInt(stt.nextToken()));
            article.setSubject(stt.nextToken());
            article.setFrom(stt.nextToken());
            article.setDate(stt.nextToken());
            article.setArticleId(stt.nextToken());
            article.addHeaderField("References", stt.nextToken());
            articles[index++] = article;
        }
    } else {
        return null;
    }

    return articles;
}

From source file:com.liusoft.dlog4j.search.SearchProxy.java

/**
 * ?/*from w w w.  j av a 2s .c o  m*/
 * @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:com.emc.plants.utils.Util.java

/**
 * Method readTokens.//from w  w  w  .  j  ava2s. c  om
 * @param text
 * @param token
 * @return list
 */
public static String[] readTokens(String text, String token) {
    StringTokenizer parser = new StringTokenizer(text, token);
    int numTokens = parser.countTokens();
    String[] list = new String[numTokens];
    for (int i = 0; i < numTokens; i++) {
        list[i] = parser.nextToken();
    }
    return list;
}