public class ConfigPropertiesCascadeCommonUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUFFER_SIZE
The name says it all.
|
static String[] |
EMPTY_STRING_ARRAY
An empty immutable
String array. |
| Constructor and Description |
|---|
ConfigPropertiesCascadeCommonUtils() |
| Modifier and Type | Method and Description |
|---|---|
static ClassLoader |
classLoader()
fast class loader
|
static String |
className(Object object)
null safe classname method, gets the unenhanced name
|
static void |
closeQuietly(InputStream input)
Unconditionally close an
InputStream. |
static URL |
computeUrl(String resourceName,
boolean canBeNull)
compute a url of a resource
|
static void |
copy(InputStream input,
Writer output,
String encoding)
Copy and convert bytes from an
InputStream to chars on a
Writer, using the specified encoding. |
static int |
copy(Reader input,
Writer output)
Copy chars from a
Reader to a Writer. |
static String |
defaultString(String str)
Returns either the passed in String,
or if the String is
null, an empty String (""). |
static <E extends Enum<?>> |
enumValueOfIgnoreCase(Class<E> theEnumClass,
String string,
boolean exceptionOnNotFound)
do a case-insensitive matching
|
static boolean |
equals(String first,
String second)
null safe string compare
|
static boolean |
equalsIgnoreCase(String str1,
String str2)
null-safe equalsignorecase
|
static String |
fileCanonicalPath(File file)
get canonical path of file
|
static int |
intValue(Object input)
convert an object to a int
|
static boolean |
isBlank(String str)
Checks if a String is whitespace, empty ("") or null.
|
static File |
jarFile(Class sampleClass)
get a jar file from a sample class
|
static String |
mapToString(Map map)
convert a set to a string (comma separate)
|
static String |
MapToString(Map map)
Deprecated.
use mapToString(map)
|
static <T> T |
newInstance(Class<T> theClass)
Construct a class
|
static <T> T |
newInstance(Class<T> theClass,
boolean allowPrivateConstructor)
Construct a class
|
static String |
prefixOrSuffix(String startString,
String separator,
boolean isPrefix)
get the prefix or suffix of a string based on a separator
|
static String[] |
split(String str,
String separatorChars)
Splits the provided text into an array, separators specified.
|
static String[] |
splitPreserveAllTokens(String str,
String separatorChars)
Splits the provided text into an array, separators specified,
preserving all tokens, including empty tokens created by adjacent
separators.
|
static String[] |
splitTrim(String input,
String separator)
split a string based on a separator into an array, and trim each entry (see
the Commons Util trim() for more details)
|
static String[] |
splitTrim(String input,
String separator,
boolean treatAdjacentSeparatorsAsOne)
split a string based on a separator into an array, and trim each entry (see
the Commons Util trim() for more details)
|
static List<String> |
splitTrimToList(String input,
String separator)
split a string based on a separator into an array, and trim each entry (see
the Commons Util trim() for more details)
|
static String |
stripLastSlashIfExists(String input)
strip the last slash (/ or \) from a string if it exists
|
static <T> List<T> |
toList(T... objects)
return a list of objects from varargs.
|
static String |
toString(InputStream input,
String encoding)
Get the contents of an
InputStream as a String. |
static String |
trim(String str)
trim whitespace from string
|
public static final int DEFAULT_BUFFER_SIZE
public static final String[] EMPTY_STRING_ARRAY
String array.public static String fileCanonicalPath(File file)
file - The file from which the canonical path will be extractedFile.getCanonicalPath()public static URL computeUrl(String resourceName, boolean canBeNull)
resourceName - The resource name for which a URL will be builtcanBeNull - if can't be null, throw runtimeClassLoader.getResource(String)public static ClassLoader classLoader()
public static String prefixOrSuffix(String startString, String separator, boolean isPrefix)
startString - is the string to start withseparator - is the separator to split onisPrefix - if thre prefix or suffix should be returnedpublic static <T> T newInstance(Class<T> theClass)
T - template typetheClass - the classpublic static <T> T newInstance(Class<T> theClass, boolean allowPrivateConstructor)
T - template typetheClass - the classallowPrivateConstructor - true if should allow private constructors@Deprecated public static String MapToString(Map map)
map - the map to convert into a human-readable stringpublic static String mapToString(Map map)
map - the map to convert into a human-readable stringpublic static String[] splitTrim(String input, String separator)
input - is the delimited input to split and trimseparator - is what to split onpublic static List<String> splitTrimToList(String input, String separator)
input - is the delimited input to split and trimseparator - is what to split onpublic static String[] splitTrim(String input, String separator, boolean treatAdjacentSeparatorsAsOne)
input - is the delimited input to split and trimseparator - is what to split ontreatAdjacentSeparatorsAsOne - when true, adjacent separators are treaded as onepublic static <T> List<T> toList(T... objects)
T - template type of the objectsobjects - The arguments to be returned as a Listpublic static String className(Object object)
object - The object whose class name is desiredpublic static int intValue(Object input)
input - the object (String or Number) to parse or convert to an intpublic static void closeQuietly(InputStream input)
InputStream.
Equivalent to InputStream.close(), except any exceptions will be ignored.input - A (possibly null) InputStreampublic static String toString(InputStream input, String encoding) throws IOException
InputStream as a String.input - the InputStream to read fromencoding - The name of a supported character encoding. See the
IANA
Charset Registry for a list of valid encoding types.StringIOException - In case of an I/O problempublic static void copy(InputStream input, Writer output, String encoding) throws IOException
InputStream to chars on a
Writer, using the specified encoding.input - the InputStream to read fromoutput - the Writer to write toencoding - The name of a supported character encoding. See the
IANA
Charset Registry for a list of valid encoding types.IOException - In case of an I/O problempublic static int copy(Reader input, Writer output) throws IOException
Reader to a Writer.input - the Reader to read fromoutput - the Writer to write toIOException - In case of an I/O problempublic static <E extends Enum<?>> E enumValueOfIgnoreCase(Class<E> theEnumClass, String string, boolean exceptionOnNotFound) throws RuntimeException
E - generic typetheEnumClass - class of the enumstring - The name of an enum constantexceptionOnNotFound - true if exception should be thrown on not foundRuntimeException - if there is a problempublic static boolean equals(String first, String second)
first - first string, or nullsecond - second string, or nullpublic static boolean isBlank(String str)
Checks if a String is whitespace, empty ("") or null.
isBlank(null) = true
isBlank("") = true
isBlank(" ") = true
isBlank("bob") = false
isBlank(" bob ") = false
str - the String to check, may be nulltrue if the String is null, empty or whitespacepublic static String trim(String str)
str - string to trimpublic static boolean equalsIgnoreCase(String str1, String str2)
str1 - first stringstr2 - second stringpublic static String[] split(String str, String separatorChars)
Splits the provided text into an array, separators specified. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as one separator. For more control over the split use the StrTokenizer class.
A null input String returns null.
A null separatorChars splits on whitespace.
StringUtils.split(null, *) = null
StringUtils.split("", *) = []
StringUtils.split("abc def", null) = ["abc", "def"]
StringUtils.split("abc def", " ") = ["abc", "def"]
StringUtils.split("abc def", " ") = ["abc", "def"]
StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
str - the String to parse, may be nullseparatorChars - the characters used as the delimiters,
null splits on whitespacenull if null String inputpublic static String[] splitPreserveAllTokens(String str, String separatorChars)
Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators. This is an alternative to using StringTokenizer.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.
A null input String returns null.
A null separatorChars splits on whitespace.
StringUtils.splitPreserveAllTokens(null, *) = null
StringUtils.splitPreserveAllTokens("", *) = []
StringUtils.splitPreserveAllTokens("abc def", null) = ["abc", "def"]
StringUtils.splitPreserveAllTokens("abc def", " ") = ["abc", "def"]
StringUtils.splitPreserveAllTokens("abc def", " ") = ["abc", "", def"]
StringUtils.splitPreserveAllTokens("ab:cd:ef", ":") = ["ab", "cd", "ef"]
StringUtils.splitPreserveAllTokens("ab:cd:ef:", ":") = ["ab", "cd", "ef", ""]
StringUtils.splitPreserveAllTokens("ab:cd:ef::", ":") = ["ab", "cd", "ef", "", ""]
StringUtils.splitPreserveAllTokens("ab::cd:ef", ":") = ["ab", "", cd", "ef"]
StringUtils.splitPreserveAllTokens(":cd:ef", ":") = ["", cd", "ef"]
StringUtils.splitPreserveAllTokens("::cd:ef", ":") = ["", "", cd", "ef"]
StringUtils.splitPreserveAllTokens(":cd:ef:", ":") = ["", cd", "ef", ""]
str - the String to parse, may be nullseparatorChars - the characters used as the delimiters,
null splits on whitespacenull if null String inputpublic static String defaultString(String str)
Returns either the passed in String,
or if the String is null, an empty String ("").
StringUtils.defaultString(null) = ""
StringUtils.defaultString("") = ""
StringUtils.defaultString("bat") = "bat"
str - the String to check, may be nullnullString.valueOf(Object)public static File jarFile(Class sampleClass)
sampleClass - the class for which the jar is looked upCopyright © 2025 OWASP. All rights reserved.