Package com.sodius.oslc.core.util
Class Sanitizers
- java.lang.Object
-
- com.sodius.oslc.core.util.Sanitizers
-
public class Sanitizers extends Object
Provider functions to clean up Strings.- Since:
- 3.5.0
-
-
Field Summary
Fields Modifier and Type Field Description static Function<String,String>
NON_PRINTABLE_CHARACTERS
Removes any character from the input String that cannot be printed, such as invisible control characters and unused code points.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BiFunction<String,Supplier<String>,String>
withContext(Function<String,String> sanitizer)
Converts the given sanitizer function to aBiFunction
, to provide context information when logging a trace message for characters that were removed.
-
-
-
Field Detail
-
NON_PRINTABLE_CHARACTERS
public static final Function<String,String> NON_PRINTABLE_CHARACTERS
Removes any character from the input String that cannot be printed, such as invisible control characters and unused code points. Does not filter out whitespace characters like tabs and line feeds.Logs a message listing the stripped out characters, when found and
TRACE
level is active for this class. You may combine withwithContext(Function)
to provide context information for this log message.
-
-
Method Detail
-
withContext
public static BiFunction<String,Supplier<String>,String> withContext(Function<String,String> sanitizer)
Converts the given sanitizer function to aBiFunction
, to provide context information when logging a trace message for characters that were removed.The first argument of the
BiFunction
is the value to sanitize. The second argument is to provide context information (e.g."description field of project Power-Training"
), to indicate from where the value comes in the application. This context is used to log an accurate message, when some characters are stripped out andTRACE
level is active for this class. It helps an administrator to identify the offending artifact in the application and sanitize it there directly, if desired.- Parameters:
sanitizer
- the sanitizing function provided by the Sanitizers class- Returns:
- a BiFunction wrapping the given function
- Throws:
NullPointerException
- if sanitizer is nullIllegalArgumentException
- if sanitizer is not a function provided by the Sanitizers class- Since:
- 3.7.0
-
-