Class ConfigPropertiesCascadeCommonUtils
- java.lang.Object
-
- org.owasp.csrfguard.config.overlay.ConfigPropertiesCascadeCommonUtils
-
- Direct Known Subclasses:
ConfigPropertiesCascadeUtils
public class ConfigPropertiesCascadeCommonUtils extends Object
utility methods for grouper. This code is copied from the Grouper project- Author:
- mchyzer
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEThe name says it all.static String[]EMPTY_STRING_ARRAYAn empty immutableStringarray.
-
Constructor Summary
Constructors Constructor Description ConfigPropertiesCascadeCommonUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static ClassLoaderclassLoader()fast class loaderstatic StringclassName(Object object)null safe classname method, gets the unenhanced namestatic voidcloseQuietly(InputStream input)Unconditionally close anInputStream.static URLcomputeUrl(String resourceName, boolean canBeNull)compute a url of a resourcestatic voidcopy(InputStream input, Writer output, String encoding)Copy and convert bytes from anInputStreamto chars on aWriter, using the specified encoding.static intcopy(Reader input, Writer output)Copy chars from aReaderto aWriter.static StringdefaultString(String str)Returns either the passed in String, or if the String isnull, an empty String ("").static <E extends Enum<?>>
EenumValueOfIgnoreCase(Class<E> theEnumClass, String string, boolean exceptionOnNotFound)do a case-insensitive matchingstatic booleanequals(String first, String second)null safe string comparestatic booleanequalsIgnoreCase(String str1, String str2)null-safe equalsignorecasestatic StringfileCanonicalPath(File file)get canonical path of filestatic intintValue(Object input)convert an object to a intstatic booleanisBlank(String str)Checks if a String is whitespace, empty ("") or null.static FilejarFile(Class sampleClass)get a jar file from a sample classstatic StringmapToString(Map map)convert a set to a string (comma separate)static StringMapToString(Map map)Deprecated.use mapToString(map)static <T> TnewInstance(Class<T> theClass)Construct a classstatic <T> TnewInstance(Class<T> theClass, boolean allowPrivateConstructor)Construct a classstatic StringprefixOrSuffix(String startString, String separator, boolean isPrefix)get the prefix or suffix of a string based on a separatorstatic 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 StringstripLastSlashIfExists(String input)strip the last slash (/ or \) from a string if it existsstatic <T> List<T>toList(T... objects)return a list of objects from varargs.static StringtoString(InputStream input, String encoding)Get the contents of anInputStreamas a String.static Stringtrim(String str)trim whitespace from string
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
The name says it all.- See Also:
- Constant Field Values
-
EMPTY_STRING_ARRAY
public static final String[] EMPTY_STRING_ARRAY
An empty immutableStringarray.
-
-
Method Detail
-
fileCanonicalPath
public static String fileCanonicalPath(File file)
get canonical path of file- Parameters:
file- The file from which the canonical path will be extracted- Returns:
- the canonical path
- See Also:
File.getCanonicalPath()
-
computeUrl
public static URL computeUrl(String resourceName, boolean canBeNull)
compute a url of a resource- Parameters:
resourceName- The resource name for which a URL will be builtcanBeNull- if can't be null, throw runtime- Returns:
- the URL for the resource name
- See Also:
ClassLoader.getResource(String)
-
classLoader
public static ClassLoader classLoader()
fast class loader- Returns:
- the class loader
-
prefixOrSuffix
public static String prefixOrSuffix(String startString, String separator, boolean isPrefix)
get the prefix or suffix of a string based on a separator- Parameters:
startString- is the string to start withseparator- is the separator to split onisPrefix- if thre prefix or suffix should be returned- Returns:
- the prefix or suffix, if the separator isnt there, return the original string
-
newInstance
public static <T> T newInstance(Class<T> theClass)
Construct a class- Type Parameters:
T- template type- Parameters:
theClass- the class- Returns:
- the instance
-
newInstance
public static <T> T newInstance(Class<T> theClass, boolean allowPrivateConstructor)
Construct a class- Type Parameters:
T- template type- Parameters:
theClass- the classallowPrivateConstructor- true if should allow private constructors- Returns:
- the instance
-
MapToString
@Deprecated public static String MapToString(Map map)
Deprecated.use mapToString(map)convert a set to a string (comma separate)- Parameters:
map- the map to convert into a human-readable string- Returns:
- the String
-
mapToString
public static String mapToString(Map map)
convert a set to a string (comma separate)- Parameters:
map- the map to convert into a human-readable string- Returns:
- the String
-
splitTrim
public 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)- Parameters:
input- is the delimited input to split and trimseparator- is what to split on- Returns:
- the array of items after split and trimmed, or null if input is null. will be trimmed to empty
-
splitTrimToList
public 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)- Parameters:
input- is the delimited input to split and trimseparator- is what to split on- Returns:
- the list of items after split and trimmed, or null if input is null. will be trimmed to empty
-
splitTrim
public 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)- Parameters:
input- is the delimited input to split and trimseparator- is what to split ontreatAdjacentSeparatorsAsOne- when true, adjacent separators are treaded as one- Returns:
- the array of items after split and trimmed, or null if input is null. will be trimmed to empty
-
toList
public static <T> List<T> toList(T... objects)
return a list of objects from varargs. Though if there is one object, and it is a list, return it.- Type Parameters:
T- template type of the objects- Parameters:
objects- The arguments to be returned as a List- Returns:
- the list or null if objects is null
-
className
public static String className(Object object)
null safe classname method, gets the unenhanced name- Parameters:
object- The object whose class name is desired- Returns:
- the classname, or null if the object was null
-
intValue
public static int intValue(Object input)
convert an object to a int- Parameters:
input- the object (String or Number) to parse or convert to an int- Returns:
- the number
-
closeQuietly
public static void closeQuietly(InputStream input)
Unconditionally close anInputStream. Equivalent toInputStream.close(), except any exceptions will be ignored.- Parameters:
input- A (possibly null) InputStream
-
toString
public static String toString(InputStream input, String encoding) throws IOException
Get the contents of anInputStreamas a String.- Parameters:
input- theInputStreamto read fromencoding- The name of a supported character encoding. See the IANA Charset Registry for a list of valid encoding types.- Returns:
- the requested
String - Throws:
IOException- In case of an I/O problem
-
copy
public static void copy(InputStream input, Writer output, String encoding) throws IOException
Copy and convert bytes from anInputStreamto chars on aWriter, using the specified encoding.- Parameters:
input- theInputStreamto read fromoutput- theWriterto write toencoding- The name of a supported character encoding. See the IANA Charset Registry for a list of valid encoding types.- Throws:
IOException- In case of an I/O problem
-
copy
public static int copy(Reader input, Writer output) throws IOException
Copy chars from aReaderto aWriter.- Parameters:
input- theReaderto read fromoutput- theWriterto write to- Returns:
- the number of characters copied
- Throws:
IOException- In case of an I/O problem
-
enumValueOfIgnoreCase
public static <E extends Enum<?>> E enumValueOfIgnoreCase(Class<E> theEnumClass, String string, boolean exceptionOnNotFound) throws RuntimeException
do a case-insensitive matching- Type Parameters:
E- generic type- Parameters:
theEnumClass- class of the enumstring- The name of an enum constantexceptionOnNotFound- true if exception should be thrown on not found- Returns:
- the enum or null or exception if not found
- Throws:
RuntimeException- if there is a problem
-
equals
public static boolean equals(String first, String second)
null safe string compare- Parameters:
first- first string, or nullsecond- second string, or null- Returns:
- true if equal
-
isBlank
public 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- Parameters:
str- the String to check, may be null- Returns:
trueif the String is null, empty or whitespace- Since:
- 2.0
-
trim
public static String trim(String str)
trim whitespace from string- Parameters:
str- string to trim- Returns:
- trimmed string
-
equalsIgnoreCase
public static boolean equalsIgnoreCase(String str1, String str2)
null-safe equalsignorecase- Parameters:
str1- first stringstr2- second string- Returns:
- true if the strings are equal ignore case
-
split
public 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
nullinput String returnsnull. AnullseparatorChars 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"]- Parameters:
str- the String to parse, may be nullseparatorChars- the characters used as the delimiters,nullsplits on whitespace- Returns:
- an array of parsed Strings,
nullif null String input
-
splitPreserveAllTokens
public 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
nullinput String returnsnull. AnullseparatorChars 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", ""]- Parameters:
str- the String to parse, may benullseparatorChars- the characters used as the delimiters,nullsplits on whitespace- Returns:
- an array of parsed Strings,
nullif null String input - Since:
- 2.1
-
defaultString
public 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"- Parameters:
str- the String to check, may be null- Returns:
- the passed in String, or the empty String if it
was
null - See Also:
String.valueOf(Object)
-
jarFile
public static File jarFile(Class sampleClass)
get a jar file from a sample class- Parameters:
sampleClass- the class for which the jar is looked up- Returns:
- the jar file
-
-