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:edu.duke.cabig.c3pr.utils.StringUtils.java

public static String camelCase(String inputString) {

    String camelCaseStr = "";

    if (inputString == null)
        return camelCaseStr;

    String lowerCase = inputString.toLowerCase();

    StringTokenizer strTokenizer = new StringTokenizer(lowerCase, " ");
    String strToken = "";
    StringBuffer strBuf = null;//from   www.ja va  2s . c o m
    char[] charAry = null;

    while (strTokenizer.hasMoreTokens()) {
        strBuf = new StringBuffer();
        strToken = strTokenizer.nextToken();
        charAry = strToken.toCharArray();
        strBuf.append(Character.toUpperCase(charAry[0]));
        int remaingstrLength = charAry.length - 1;
        strBuf.append(charAry, 1, remaingstrLength);
        camelCaseStr = camelCaseStr + " " + strBuf.toString();
    }
    return camelCaseStr;

}

From source file:com.persistent.cloudninja.controller.AuthFilterUtils.java

/**
 * //from  ww  w  .  j  a v  a  2 s  .co m
 * @param fieldName
 * @param cookieValue
 * @return
 */
public static String getFieldValueFromCookieString(String fieldName, String cookieValue) {
    String retVal = null;
    String fieldNameAndSeparatorString = fieldName + CloudNinjaConstants.COOKIE_FIELD_AND_VALUE_SEPARATOR;
    StringTokenizer tokenizer = new StringTokenizer(cookieValue, CloudNinjaConstants.COOKIE_FIELDS_SEPARATOR);
    while (tokenizer.hasMoreTokens()) {
        String nextToken = tokenizer.nextToken();
        if (nextToken.startsWith(fieldNameAndSeparatorString)) {
            retVal = nextToken.substring(fieldNameAndSeparatorString.length());
        }
    }
    return retVal;
}

From source file:edu.stanford.muse.util.ThunderbirdUtils.java

private static Pair<String, String> parseLine(String line, String keyword) {
    StringTokenizer st = new StringTokenizer(line, ".");
    st.nextToken();
    st.nextToken(); // skip up to the second dot
    String id = st.nextToken(); // stuff between second and third dot is the thunderbird id
    // id = "server2" or "id2"
    id = id.substring(keyword.length());
    // id = "2"//from  w  w w. ja v  a 2 s .c o  m

    String value = line.substring(line.indexOf(' ') + 2); // skip ' ' and "
    // value = xenon.stanford.edu")
    value = value.substring(0, value.indexOf('"'));
    // value = xenon.stanford.edu

    return new Pair<String, String>(id, value);
}

From source file:de.kapsi.net.daap.DaapUtil.java

/**
 * Splits a meta String ("foo,bar,alice,bob") and stores the data
 * in an ArrayList//  w  ww .  j a va2s . c om
 * 
 * @param meta a meta String
 * @return the splitten meta String as ArrayList
 */
public static final ArrayList parseMeta(String meta) {
    StringTokenizer tok = new StringTokenizer(meta, ",");
    ArrayList list = new ArrayList(tok.countTokens());
    boolean flag = false;

    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();

        // Must be te fist! See DAAP documentation 
        // for more info!
        if (!flag && token.equals("dmap.itemkind")) {
            list.add(0, token);
            flag = true;
        } else {
            list.add(token);
        }
    }
    return list;
}

From source file:com.trackplus.ddl.DataWriter.java

private static void insertClobData(Connection con, String line) throws DDLException {
    /*/*from   ww w. jav  a  2 s .  co m*/
    "OBJECTID",//Integer not null
    "EXCHANGEDIRECTION",//Integer not null
    "ENTITYID",//Integer not null
    "ENTITYTYPE",//Integer not null
    "FILENAME",//Varchar(255)
    "CHANGEDBY",//Integer
    "LASTEDIT",//Timestamp
    "TPUUID",//Varchar(36)
    "FILECONTENT"//Blob sub_type 1
     */

    String sql = "INSERT INTO TMSPROJECTEXCHANGE(OBJECTID, EXCHANGEDIRECTION, ENTITYID,ENTITYTYPE,FILENAME,CHANGEDBY,LASTEDIT,TPUUID,FILECONTENT) "
            + "VALUES(?,?,?,?,?,?,?,?,?)";
    StringTokenizer st = new StringTokenizer(line, ",");
    Integer objectID = Integer.valueOf(st.nextToken());
    Integer exchangeDirection = Integer.valueOf(st.nextToken());
    Integer entityID = Integer.valueOf(st.nextToken());
    Integer entityType = Integer.valueOf(st.nextToken());
    String fileName = st.nextToken();
    if ("null".equalsIgnoreCase(fileName)) {
        fileName = null;
    }
    Integer changedBy = null;
    try {
        changedBy = Integer.valueOf(st.nextToken());
    } catch (Exception ex) {
        LOGGER.debug(ex);
    }

    Timestamp lastEdit = null;
    String lastEditStr = st.nextToken();
    if (lastEditStr != null) {
        try {
            lastEdit = Timestamp.valueOf(lastEditStr);
        } catch (Exception ex) {
            LOGGER.debug(ex);
        }
    }
    String tpuid = st.nextToken();
    String base64Str = st.nextToken();
    if (base64Str.length() == 1 && " ".equals(base64Str)) {
        base64Str = "";
    }
    byte[] bytes = Base64.decodeBase64(base64Str);
    String fileContent = new String(bytes);

    try {
        PreparedStatement preparedStatement = con.prepareStatement(sql);

        preparedStatement.setInt(1, objectID);
        preparedStatement.setInt(2, exchangeDirection);
        preparedStatement.setInt(3, entityID);
        preparedStatement.setInt(4, entityType);
        preparedStatement.setString(5, fileName);
        preparedStatement.setInt(6, changedBy);
        preparedStatement.setTimestamp(7, lastEdit);
        preparedStatement.setString(8, tpuid);
        preparedStatement.setString(9, fileContent);

        preparedStatement.executeUpdate();
    } catch (SQLException e) {
        throw new DDLException(e.getMessage(), e);
    }

}

From source file:com.projity.pm.graphic.spreadsheet.common.CommonSpreadSheetModel.java

public static String[] convertActions(String actionList) {
    if (actionList == null)
        return null;
    StringTokenizer st = new StringTokenizer(actionList, ",;:|");
    String[] actions = new String[st.countTokens()];
    for (int i = 0; i < actions.length; i++)
        actions[i] = st.nextToken();
    return actions;
}

From source file:com.sshtools.common.ui.PreferencesStore.java

/**
 *
 *
 * @param name//w ww .  j  a v a2  s .  c om
 * @param def
 *
 * @return
 */
public static Rectangle getRectangle(String name, Rectangle def) {
    String s = get(name);

    if ((s == null) || s.equals("")) {
        return def;
    } else {
        StringTokenizer st = new StringTokenizer(s, ",");
        Rectangle r = new Rectangle();

        try {
            r.x = Integer.parseInt(st.nextToken());
            r.y = Integer.parseInt(st.nextToken());
            r.width = Integer.parseInt(st.nextToken());
            r.height = Integer.parseInt(st.nextToken());
        } catch (NumberFormatException nfe) {
            log.warn("Preference is " + name + " is badly formatted", nfe);
        }

        return r;
    }
}

From source file:de.bayern.gdi.utils.StringUtils.java

/**
 * Split a command line./*w  ww  .  j av a2 s . c  o m*/
 * @param toProcess the command line to process.
 * @return the command line broken into strings.
 * An empty or null toProcess parameter results in a zero sized array.
 * @throws IllegalArgumentException Thrown if quotes are unbalanced.
 */
public static String[] splitCommandLine(String toProcess) throws IllegalArgumentException {

    if (toProcess == null || toProcess.length() == 0) {
        //no command? no string
        return new String[0];
    }
    // parse with a simple finite state machine

    State state = State.NORMAL;
    StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
    ArrayList<String> result = new ArrayList<String>();
    StringBuilder current = new StringBuilder();
    boolean lastTokenHasBeenQuoted = false;

    while (tok.hasMoreTokens()) {
        String nextTok = tok.nextToken();
        switch (state) {
        case IN_QUOTE:
            if ("\'".equals(nextTok)) {
                lastTokenHasBeenQuoted = true;
                state = State.NORMAL;
            } else {
                current.append(nextTok);
            }
            break;
        case IN_DOUBLE_QUOTE:
            if ("\"".equals(nextTok)) {
                lastTokenHasBeenQuoted = true;
                state = State.NORMAL;
            } else {
                current.append(nextTok);
            }
            break;
        default:
            if ("\'".equals(nextTok)) {
                state = State.IN_QUOTE;
            } else if ("\"".equals(nextTok)) {
                state = State.IN_DOUBLE_QUOTE;
            } else if (" ".equals(nextTok)) {
                if (lastTokenHasBeenQuoted || current.length() != 0) {
                    result.add(current.toString());
                    current.setLength(0);
                }
            } else {
                current.append(nextTok);
            }
            lastTokenHasBeenQuoted = false;
            break;
        }
    }
    if (lastTokenHasBeenQuoted || current.length() != 0) {
        result.add(current.toString());
    }
    if (state == State.IN_QUOTE || state == State.IN_DOUBLE_QUOTE) {
        throw new IllegalArgumentException("unbalanced quotes in " + toProcess);
    }
    return result.toArray(new String[result.size()]);
}

From source file:org.apache.lens.regression.util.Util.java

public static HashMap<String, String> stringListToMap(StringList stringList) {
    HashMap<String, String> map = new HashMap<String, String>();
    if (stringList == null) {
        return null;
    }//from www. jav  a  2s. c om
    List<String> list = stringList.getElements();
    for (String element : list) {
        StringTokenizer tk = new StringTokenizer(element, "=");
        map.put(tk.nextToken(), tk.nextToken());
    }
    return map;
}

From source file:com.yamin.kk.vlc.Util.java

public static String[] getStorageDirectories() {
    String[] dirs = null;/*from   w w  w  .j a  va  2 s .co  m*/
    BufferedReader bufReader = null;
    try {
        bufReader = new BufferedReader(new FileReader("/proc/mounts"));
        ArrayList<String> list = new ArrayList<String>();
        list.add(Environment.getExternalStorageDirectory().getPath());
        String line;
        while ((line = bufReader.readLine()) != null) {
            if (line.contains("vfat") || line.contains("exfat") || line.contains("/mnt")
                    || line.contains("/Removable")) {
                StringTokenizer tokens = new StringTokenizer(line, " ");
                String s = tokens.nextToken();
                s = tokens.nextToken(); // Take the second token, i.e. mount point

                if (list.contains(s))
                    continue;

                if (line.contains("/dev/block/vold")) {
                    if (!line.startsWith("tmpfs") && !line.startsWith("/dev/mapper")
                            && !s.startsWith("/mnt/secure") && !s.startsWith("/mnt/shell")
                            && !s.startsWith("/mnt/asec") && !s.startsWith("/mnt/obb")) {
                        list.add(s);
                    }
                }
            }
        }

        dirs = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            dirs[i] = list.get(i);
        }
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    } finally {
        if (bufReader != null) {
            try {
                bufReader.close();
            } catch (IOException e) {
            }
        }
    }
    return dirs;
}