Example usage for java.util StringTokenizer hasMoreTokens

List of usage examples for java.util StringTokenizer hasMoreTokens

Introduction

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

Prototype

public boolean hasMoreTokens() 

Source Link

Document

Tests if there are more tokens available from this tokenizer's string.

Usage

From source file:com.free.exception.ExceptionHelper.java

/**
 * <p>/*  ww w  .  j  ava2  s.c  om*/
 * Produces a <code>List</code> of stack frames - the message is not included.
 * </p>
 * <p/>
 * <p>
 * This works in most cases - it will only fail if the exception message
 * contains a line that starts with:
 * <code>&quot;&nbsp;&nbsp;&nbsp;at&quot;.</code>
 * </p>
 * 
 * @param t
 *          is any throwable
 * @return List of stack frames
 */
static List<String> getStackFrameList(Throwable t) {
    String stackTrace = getStackTrace(t);
    String linebreak = LINE_SEPARATOR;
    StringTokenizer frames = new StringTokenizer(stackTrace, linebreak);
    List<String> list = new LinkedList<String>();
    boolean traceStarted = false;
    while (frames.hasMoreTokens()) {
        String token = frames.nextToken();
        // Determine if the line starts with <whitespace>at
        int at = token.indexOf("at");
        if (at != -1 && token.substring(0, at).trim().length() == 0) {
            traceStarted = true;
            list.add(token);
        } else if (traceStarted) {
            break;
        }
    }
    return list;
}

From source file:eionet.cr.util.Util.java

/**
 *
 * @param str/*from   w w w  .j  a v  a2 s.  c  o m*/
 * @param token
 * @param ignoreCase
 * @return
 */
private static boolean containsToken(String str, String token, boolean ignoreCase) {

    if (str == null || str.trim().length() == 0) {
        return false;
    }

    StringTokenizer st = new StringTokenizer(str);
    while (st.hasMoreTokens()) {

        String nextToken = st.nextToken();
        if (ignoreCase ? nextToken.equalsIgnoreCase(token) : nextToken.equals(token)) {
            return true;
        }
    }

    return false;
}

From source file:com.shanke.common.conf.StringHandle.java

/**
 * Returns a collection of strings./*ww  w  . j  a  v  a  2s  .co m*/
 * 
 * @param str
 *            comma seperated string values
 * @return an <code>ArrayList</code> of string values
 */
public static Collection<String> getStringCollection(String str) {
    List<String> values = new ArrayList<String>();
    if (str == null)
        return values;
    StringTokenizer tokenizer = new StringTokenizer(str, ",");
    values = new ArrayList<String>();
    while (tokenizer.hasMoreTokens()) {
        values.add(tokenizer.nextToken());
    }
    return values;
}

From source file:isl.FIMS.utils.Utils.java

private static long getFreeSpaceOnLinux(String path) throws Exception {
    long bytesFree = -1;

    Process p = Runtime.getRuntime().exec("df " + "/" + path); //$NON-NLS-1$ //$NON-NLS-2$
    InputStream reader = new BufferedInputStream(p.getInputStream());
    StringBuffer buffer = new StringBuffer();
    for (;;) {/*from w w w. j a va 2  s . c  o  m*/
        int c = reader.read();
        if (c == -1) {
            break;
        }
        buffer.append((char) c);
    }
    String outputText = buffer.toString();
    reader.close();

    // parse the output text for the bytes free info
    StringTokenizer tokenizer = new StringTokenizer(outputText, "\n"); //$NON-NLS-1$
    tokenizer.nextToken();
    if (tokenizer.hasMoreTokens()) {
        String line2 = tokenizer.nextToken();
        StringTokenizer tokenizer2 = new StringTokenizer(line2, " "); //$NON-NLS-1$
        if (tokenizer2.countTokens() >= 4) {
            tokenizer2.nextToken();
            tokenizer2.nextToken();
            tokenizer2.nextToken();
            bytesFree = Long.parseLong(tokenizer2.nextToken());
            return bytesFree * 1024;
        }

        return bytesFree * 1024;
    }

    throw new Exception("Can not read the free space of " + path + " path"); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:isl.FIMS.utils.Utils.java

private static long getFreeSpaceOnWindows(String path) throws Exception {
    long bytesFree = -1;

    File script = new File(System.getProperty("java.io.tmpdir"), //$NON-NLS-1$
            "script.bat"); //$NON-NLS-1$
    PrintWriter writer = new PrintWriter(new FileWriter(script, false));
    writer.println("dir \"" + path + "\""); //$NON-NLS-1$ //$NON-NLS-2$
    writer.close();/*from   w w w  .ja  va2s .  c  o  m*/

    // get the output from running the .bat file
    Process p = Runtime.getRuntime().exec(script.getAbsolutePath());
    InputStream reader = new BufferedInputStream(p.getInputStream());
    StringBuffer buffer = new StringBuffer();
    for (;;) {
        int c = reader.read();
        if (c == -1) {
            break;
        }
        buffer.append((char) c);
    }
    String outputText = buffer.toString();
    reader.close();

    StringTokenizer tokenizer = new StringTokenizer(outputText, "\n"); //$NON-NLS-1$
    String line = null;
    while (tokenizer.hasMoreTokens()) {
        line = tokenizer.nextToken().trim();
        // see if line contains the bytes free information

    }
    tokenizer = new StringTokenizer(line, " "); //$NON-NLS-1$
    tokenizer.nextToken();
    tokenizer.nextToken();
    bytesFree = Long.parseLong(tokenizer.nextToken().replace('.', ',').replaceAll(",", "")); //$NON-NLS-1$//$NON-NLS-2$
    return bytesFree;
}

From source file:com.ephesoft.dcma.da.common.UpgradePatchPreparation.java

/**
 * This method creates patch for plugin.
 * //from  w  w w .  j  av  a  2  s  . c o m
 * @param service {@link BatchClassService}
 * @param pluginInfo {@link String}
 */
private static void createPatchForPlugin(final BatchClassService service, final String pluginInfo) {
    final StringTokenizer pluginTokens = new StringTokenizer(pluginInfo, DataAccessConstant.SEMI_COLON);
    while (pluginTokens.hasMoreTokens()) {
        String pluginToken = pluginTokens.nextToken();
        StringTokenizer pluginConfigTokens = new StringTokenizer(pluginToken, DataAccessConstant.COMMA);
        String batchClassIdentifier = null;
        String moduleId = null;
        String pluginId = null;
        try {
            batchClassIdentifier = pluginConfigTokens.nextToken();
            moduleId = pluginConfigTokens.nextToken();
            pluginId = pluginConfigTokens.nextToken();
            BatchClassPlugin createdPlugin = createPatch(batchClassIdentifier, moduleId, pluginId, service);
            if (createdPlugin != null) {
                BatchClass batchClass = service.getBatchClassByIdentifier(batchClassIdentifier);
                Module module = moduleService.getModulePropertiesForModuleId(Long.valueOf(moduleId));
                String key = batchClass.getName() + DataAccessConstant.COMMA + module.getName();
                ArrayList<BatchClassPlugin> pluginsList = batchClassNameVsPluginsMap.get(key);
                if (pluginsList == null) {
                    pluginsList = new ArrayList<BatchClassPlugin>();
                    batchClassNameVsPluginsMap.put(key, pluginsList);
                }
                pluginsList.add(createdPlugin);
            }

        } catch (NoSuchElementException e) {
            LOG.info("Incomplete data specifiedin properties file.", e);
        }
    }

    try {
        File serializedExportFile = new File(
                upgradePatchFolderPath + File.separator + "PluginUpdate" + SERIALIZATION_EXT);
        SerializationUtils.serialize(batchClassNameVsPluginsMap, new FileOutputStream(serializedExportFile));
    } catch (FileNotFoundException e) {
        // Unable to read serializable file
        LOG.error(ERROR_OCCURRED_WHILE_CREATING_THE_SERIALIZABLE_FILE + e.getMessage(), e);
    }
}

From source file:com.kadwa.hadoop.DistExec.java

/**
 * Make a path relative with respect to a root path.
 * absPath is always assumed to descend from root.
 * Otherwise returned path is null.//w  w  w .j a va  2s  .co m
 */
static String makeRelative(Path root, Path absPath) {
    if (!absPath.isAbsolute()) {
        throw new IllegalArgumentException("!absPath.isAbsolute(), absPath=" + absPath);
    }
    String p = absPath.toUri().getPath();

    StringTokenizer pathTokens = new StringTokenizer(p, "/");
    for (StringTokenizer rootTokens = new StringTokenizer(root.toUri().getPath(), "/"); rootTokens
            .hasMoreTokens();) {
        if (!rootTokens.nextToken().equals(pathTokens.nextToken())) {
            return null;
        }
    }
    StringBuilder sb = new StringBuilder();
    for (; pathTokens.hasMoreTokens();) {
        sb.append(pathTokens.nextToken());
        if (pathTokens.hasMoreTokens()) {
            sb.append(Path.SEPARATOR);
        }
    }
    return sb.length() == 0 ? "." : sb.toString();
}

From source file:com.easyjf.util.StringUtils.java

/**
 * Tokenize the given String into a String array via a StringTokenizer.
 * <p>//  www  .j  a v  a2s .com
 * The given delimiters string is supposed to consist of any number of
 * delimiter characters. Each of those characters can be used to separate
 * tokens. A delimiter is always a single character; for multi-character
 * delimiters, consider using <code>delimitedListToStringArray</code>
 * 
 * @param str
 *            the String to tokenize
 * @param delimiters
 *            the delimiter characters, assembled as String (each of those
 *            characters is individually considered as delimiter)
 * @param trimTokens
 *            trim the tokens via String's <code>trim</code>
 * @param ignoreEmptyTokens
 *            omit empty tokens from the result array (only applies to
 *            tokens that are empty after trimming; StringTokenizer will not
 *            consider subsequent delimiters as token in the first place).
 * @return an array of the tokens
 * @see java.util.StringTokenizer
 * @see java.lang.String#trim
 * @see #delimitedListToStringArray
 */
public static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens,
        boolean ignoreEmptyTokens) {
    if (str == null)
        return new String[] {};
    StringTokenizer st = new StringTokenizer(str, delimiters);
    List tokens = new ArrayList();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (trimTokens)
            token = token.trim();
        if (!ignoreEmptyTokens || token.length() > 0)
            tokens.add(token);
    }
    return toStringArray(tokens);
}

From source file:com.ckfinder.connector.utils.FileUtils.java

/**
 * rename file with double extension.//  ww  w  .  j ava  2 s . co  m
 * @param fileName file name
 * @return new file name with . replaced with _ (but not last)
 */
public static String renameFileWithBadExt(final ResourceType type, final String fileName) {
    if (type == null || fileName == null) {
        return null;
    }

    if (fileName.indexOf('.') == -1) {
        return fileName;
    }

    StringTokenizer tokens = new StringTokenizer(fileName, ".");
    String cfileName = tokens.nextToken();
    String currToken = "";
    while (tokens.hasMoreTokens()) {
        currToken = tokens.nextToken();
        if (tokens.hasMoreElements()) {
            cfileName = cfileName.concat(checkSingleExtension(currToken, type) ? "." : "_");
            cfileName = cfileName.concat(currToken);
        } else {
            cfileName = cfileName.concat(".".concat(currToken));
        }
    }
    return cfileName;
}