public abstract class StringUtils extends Object
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static String[] |
createCommandArray(String s)
Convenience method for creating arrays of strings suitable for use as
command-line parameters when executing an external process.
|
static String[] |
createCommandArray(String s,
char delim)
Deprecated.
Use createCommandArray(String s) instead.
|
static boolean |
isLocalWindowsPath(String path) |
static String |
prettyXml(String xml)
Uses the Xalan javax.transform classes to indent an XML string properly
so that it is easier to read.
|
static String |
truncate(String name,
int length)
truncate
|
public static String[] createCommandArray(String s, char delim)
The default Runtime.exec
method 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.
s
- the string to splitdelim
- a char that does not already exist in s
IllegalArgumentException
- If s
is null or if delim
already exists in s
.public static String[] createCommandArray(String s)
The default Runtime.exec
method 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 preserving all in-quote spaces.
Caveat: This method does not respect escaped quotes! It will simply remove them and leave the stray escape characters.
s
- the string to splitIllegalArgumentException
- If s
is null.public static boolean isLocalWindowsPath(String path)
public static String prettyXml(String xml) throws UnsupportedEncodingException, TransformerException
Copyright © 2017. All rights reserved.