org.opennms.core.utils
Class StringUtils

java.lang.Object
  extended by org.opennms.core.utils.StringUtils

public class StringUtils
extends java.lang.Object


Constructor Summary
StringUtils()
           
 
Method Summary
static java.lang.String[] createCommandArray(java.lang.String s, char delim)
          Convenience method for creating arrays of strings suitable for use as command-line parameters when executing an external process.
static java.lang.String[] tokenizeWithQuotingAndEscapes(java.lang.String line, java.lang.String delims, boolean processQuoted)
           
static java.lang.String truncate(java.lang.String name, int length)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtils

public StringUtils()
Method Detail

createCommandArray

public static java.lang.String[] createCommandArray(java.lang.String s,
                                                    char delim)
Convenience method for creating arrays of strings suitable for use as command-line parameters when executing an external process.

The default Runtime.execmethod will split a single string based on spaces, but it does not respect spaces within quotation marks, and it will leave the quotation marks in the resulting substrings. This method solves those problems by replacing all in-quote spaces with the given delimiter, removes the quotes, and then splits the resulting string by the remaining out-of-quote spaces. It then goes through each substring and replaces the delimiters with spaces.

Caveat: This method does not respect escaped quotes! It will simply remove them and leave the stray escape characters.

Parameters:
s - the string to split
delim - a char that does not already exist in s
Returns:
An array of strings split by spaces outside of quotes.
Throws:
java.lang.IllegalArgumentException - If s is null or if delim already exists in s.

tokenizeWithQuotingAndEscapes

public static java.lang.String[] tokenizeWithQuotingAndEscapes(java.lang.String line,
                                                               java.lang.String delims,
                                                               boolean processQuoted)

truncate

public static java.lang.String truncate(java.lang.String name,
                                        int length)


Copyright © 2007. All Rights Reserved.