public final class StringUtils extends Object
Utility class providing helper constants and static methods around strings.
Modifier and Type | Field and Description |
---|---|
static char[] |
HEX_ARRAY
Hexadecimal possibles characters.
|
Modifier and Type | Method and Description |
---|---|
static String |
merge(String[] merge,
String separator)
Merges all the given
String into one String separated with the separator. |
static String |
removeTrailing(String str,
String trailing)
Removes all trailing
String at the beginning and at the end of the specified String . |
static String |
simplifyPathWithDoubleDot(String toSimplify)
Simplifies the given string representation of a path by removing substring like '/foo/bar/..
|
static String |
simplifyPathWithDoubleDot(String toSimplify,
String separator)
Simplifies the given string representation of a path by removing substring like '/foo/bar/..
|
static String |
toHexString(byte[] bytes)
Converts bytes to hexadecimal
String . |
public static String toHexString(byte[] bytes)
Converts bytes to hexadecimal String
.
See: http://stackoverflow.com/questions/9655181/convert-from-byte-array-to-hex-string-in-java
bytes
- bytespublic static String simplifyPathWithDoubleDot(String toSimplify)
Simplifies the given string representation of a path by removing substring like '/foo/bar/../dir' by '/foo/dir',
considering the '..' substring as a reference to the parent path and the IOUtils.STD_SEPARATOR
as separator.
toSimplify
- the path to simplifynull
if it is not possible to simplifysimplifyPathWithDoubleDot(String, String)
public static String simplifyPathWithDoubleDot(String toSimplify, String separator)
Simplifies the given string representation of a path by removing substring like '/foo/bar/../dir' by '/foo/dir', considering the '..' substring as a reference to the parent path. In this case, the path separator must be '/'. Not that the separator must not contain regex keywords.
If a parent path is not found in the string, then null
is returned. For instance, '../bar' can't be
simplified.
toSimplify
- the path to simplifyseparator
- the path separatornull
if it is not possible to simplifypublic static String removeTrailing(String str, String trailing)
Removes all trailing String
at the beginning and at the end of the specified String
.
str
- the string to be treatedtrailing
- the trailing string to removepublic static String merge(String[] merge, String separator)
Merges all the given String
into one String
separated with the separator.
For example, merge(new String[] { "foo", "oof", }, ":") results in "foo:oof".
If the separator is null
, then no separator is inserted. If only one is
specified, then this is directly returned. If no element is given, an empty String
will be returned.
Finally, the method ensure that the separator has only one occurrence between words. For example : merge(new String[] { "foo:", ":oof", }, ":") results in "foo:oof".
merge
- to mergeseparator
- the separatorCopyright © 2012-2015. All Rights Reserved.