Package org.operaton.commons.utils
Class StringUtil
java.lang.Object
org.operaton.commons.utils.StringUtil
- Author:
- Sebastian Menski
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringdefaultString(String text) Returns either the passed in String, or if the String isnull, an empty String ("").static StringgetStackTrace(Throwable throwable) Fetches the stack trace of an exception as a String.static booleanisExpression(String text) Checks whether a String seams to be an expression or notstatic StringJoins a list of Strings to a single one.static StringSanitizes a given string for safe logging by escaping carriage return and newline characters.static String[]Splits a String by an expression.
-
Method Details
-
isExpression
Checks whether a String seams to be an expression or not- Parameters:
text- the text to check- Returns:
- true if the text seams to be an expression false otherwise
-
split
Splits a String by an expression.- Parameters:
text- the text to splitregex- the regex to split by- Returns:
- the parts of the text or null if text was null
-
join
Joins a list of Strings to a single one.- Parameters:
delimiter- the delimiter between the joined partsparts- the parts to join- Returns:
- the joined String or null if parts was null
-
defaultString
Returns either the passed in String, or if the String isnull, an empty String ("").StringUtils.defaultString(null) = "" StringUtils.defaultString("") = "" StringUtils.defaultString("bat") = "bat"- Parameters:
text- the String to check, may be null- Returns:
- the passed in String, or the empty String if it was
null
-
getStackTrace
Fetches the stack trace of an exception as a String.- Parameters:
throwable- to get the stack trace from- Returns:
- the stack trace as String
-
sanitize
Sanitizes a given string for safe logging by escaping carriage return and newline characters. This method replaces all occurrences of '\r' with '\\r' and '\n' with '\\n' to prevent multi-line log outputs which can disrupt log readability and parsing. If the input string is null, it returns the literal string "(null)".- Parameters:
input- the input string to sanitize, may be null- Returns:
- a sanitized string with escaped line breaks or "(null)" if input was null
-