public class StringUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
StringUtils.TraditionalBinaryPrefix
The traditional binary prefixes, kilo, mega, ..., exa,
which can be represented by a 64-bit integer.
|
Modifier and Type | Field and Description |
---|---|
static char |
COMMA |
static java.lang.String[] |
emptyStringArray |
static char |
ESCAPE_CHAR |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
arrayToString(java.lang.String[] strs)
Given an array of strings, return a comma-separated list of its elements.
|
static java.lang.String |
byteDesc(long len)
Return an abbreviated English-language desc of the byte length
|
static java.lang.String |
byteToHexString(byte[] bytes)
Same as byteToHexString(bytes, 0, bytes.length).
|
static java.lang.String |
byteToHexString(byte[] bytes,
int start,
int end)
Given an array of bytes it will convert the bytes to a hex string
representation of the bytes
|
static java.lang.String |
escapeHTML(java.lang.String string)
Escapes HTML Special characters present in the string.
|
static java.lang.String |
escapeString(java.lang.String str)
Escape commas in the string using the default escape char
|
static java.lang.String |
escapeString(java.lang.String str,
char escapeChar,
char charToEscape)
Escape
charToEscape in the string
with the escape char escapeChar |
static java.lang.String |
escapeString(java.lang.String str,
char escapeChar,
char[] charsToEscape) |
static int |
findNext(java.lang.String str,
char separator,
char escapeChar,
int start,
java.lang.StringBuilder split)
Finds the first occurrence of the separator character ignoring the escaped
separators starting from the index.
|
static java.lang.String |
formatPercent(double done,
int digits)
Format a percentage for presentation to the user.
|
static java.lang.String |
formatTime(long timeDiff)
Given the time in long milliseconds, returns a
String in the format Xhrs, Ymins, Z sec.
|
static java.lang.String |
formatTimeDiff(long finishTime,
long startTime)
Given a finish and start time in long milliseconds, returns a
String in the format Xhrs, Ymins, Z sec, for the time difference between two times.
|
static java.lang.String |
getFormattedTimeWithDiff(java.text.DateFormat dateFormat,
long finishTime,
long startTime)
Formats time in ms and appends difference (finishTime - startTime)
as returned by formatTimeDiff().
|
static java.lang.String |
getHostname()
Return hostname without throwing exception.
|
static java.util.Collection<java.lang.String> |
getStringCollection(java.lang.String str)
Returns a collection of strings.
|
static java.lang.String[] |
getStrings(java.lang.String str)
Returns an arraylist of strings.
|
static java.util.Collection<java.lang.String> |
getTrimmedStringCollection(java.lang.String str)
Splits a comma separated value
String , trimming leading and trailing whitespace on each value. |
static java.lang.String[] |
getTrimmedStrings(java.lang.String str)
Splits a comma separated value
String , trimming leading and trailing whitespace on each value. |
static byte[] |
hexStringToByte(java.lang.String hex)
Given a hexstring this will return the byte array corresponding to the
string
|
static java.lang.String |
humanReadableInt(long number)
Given an integer, return a string that is in an approximate, but human
readable format.
|
static java.lang.String |
join(java.lang.CharSequence separator,
java.lang.Iterable<java.lang.String> strings)
Concatenates strings, using a separator.
|
static java.lang.String |
joinObjects(java.lang.CharSequence separator,
java.lang.Iterable<? extends java.lang.Object> objects)
Concatenates stringified objects, using a separator.
|
static java.lang.String |
limitDecimalTo2(double d) |
static java.lang.String |
simpleHostname(java.lang.String fullHostname)
Given a full hostname, return the word upto the first dot.
|
static java.lang.String[] |
split(java.lang.String str)
Split a string using the default separator
|
static java.lang.String[] |
split(java.lang.String str,
char escapeChar,
char separator)
Split a string using the given separator
|
static java.lang.String |
stringifyException(java.lang.Throwable e)
Make a string representation of the exception.
|
static java.net.URI[] |
stringToURI(java.lang.String[] str) |
static java.lang.String |
unEscapeString(java.lang.String str)
Unescape commas in the string using the default escape char
|
static java.lang.String |
unEscapeString(java.lang.String str,
char escapeChar,
char charToEscape)
Unescape
charToEscape in the string
with the escape char escapeChar |
static java.lang.String |
unEscapeString(java.lang.String str,
char escapeChar,
char[] charsToEscape) |
static java.lang.String |
uriToString(java.net.URI[] uris) |
public static final java.lang.String[] emptyStringArray
public static final char COMMA
public static final char ESCAPE_CHAR
public static java.lang.String stringifyException(java.lang.Throwable e)
e
- The exception to stringifypublic static java.lang.String simpleHostname(java.lang.String fullHostname)
fullHostname
- the full hostnamepublic static java.lang.String humanReadableInt(long number)
number
- the number to formatpublic static java.lang.String formatPercent(double done, int digits)
done
- the percentage to format (0.0 to 1.0)digits
- the number of digits past the decimal pointpublic static java.lang.String arrayToString(java.lang.String[] strs)
strs
- Array of stringspublic static java.lang.String byteToHexString(byte[] bytes, int start, int end)
bytes
- start
- start index, inclusivelyend
- end index, exclusivelypublic static java.lang.String byteToHexString(byte[] bytes)
public static byte[] hexStringToByte(java.lang.String hex)
hex
- the hex String arraypublic static java.lang.String uriToString(java.net.URI[] uris)
uris
- public static java.net.URI[] stringToURI(java.lang.String[] str)
str
- public static java.lang.String formatTimeDiff(long finishTime, long startTime)
finishTime
- finish timestartTime
- start timepublic static java.lang.String formatTime(long timeDiff)
timeDiff
- The time difference to formatpublic static java.lang.String getFormattedTimeWithDiff(java.text.DateFormat dateFormat, long finishTime, long startTime)
dateFormat
- date format to usefinishTime
- fnish timestartTime
- start timepublic static java.lang.String[] getStrings(java.lang.String str)
str
- the comma separated string valuespublic static java.util.Collection<java.lang.String> getStringCollection(java.lang.String str)
str
- comma separated string valuesArrayList
of string valuespublic static java.util.Collection<java.lang.String> getTrimmedStringCollection(java.lang.String str)
String
, trimming leading and trailing whitespace on each value.str
- a comma separated Collection
of String
valuespublic static java.lang.String[] getTrimmedStrings(java.lang.String str)
String
, trimming leading and trailing whitespace on each value.str
- a comma separated String
valuespublic static java.lang.String[] split(java.lang.String str)
str
- a string that may have escaped separatorpublic static java.lang.String[] split(java.lang.String str, char escapeChar, char separator)
str
- a string that may have escaped separatorescapeChar
- a char that be used to escape the separatorseparator
- a separator charpublic static int findNext(java.lang.String str, char separator, char escapeChar, int start, java.lang.StringBuilder split)
str
- the source stringseparator
- the character to findescapeChar
- character used to escapestart
- from where to searchsplit
- used to pass back the extracted stringpublic static java.lang.String escapeString(java.lang.String str)
str
- a stringpublic static java.lang.String escapeString(java.lang.String str, char escapeChar, char charToEscape)
charToEscape
in the string
with the escape char escapeChar
str
- stringescapeChar
- escape charcharToEscape
- the char to be escapedpublic static java.lang.String escapeString(java.lang.String str, char escapeChar, char[] charsToEscape)
charsToEscape
- array of characters to be escapedpublic static java.lang.String unEscapeString(java.lang.String str)
str
- a stringpublic static java.lang.String unEscapeString(java.lang.String str, char escapeChar, char charToEscape)
charToEscape
in the string
with the escape char escapeChar
str
- stringescapeChar
- escape charcharToEscape
- the escaped charpublic static java.lang.String unEscapeString(java.lang.String str, char escapeChar, char[] charsToEscape)
charsToEscape
- array of characters to unescapepublic static java.lang.String getHostname()
public static java.lang.String escapeHTML(java.lang.String string)
string
- public static java.lang.String byteDesc(long len)
public static java.lang.String limitDecimalTo2(double d)
public static java.lang.String join(java.lang.CharSequence separator, java.lang.Iterable<java.lang.String> strings)
separator
- Separator to join with.strings
- Strings to join.public static java.lang.String joinObjects(java.lang.CharSequence separator, java.lang.Iterable<? extends java.lang.Object> objects)
separator
- Separator to join with.objects
- Objects to join.