Package fr.gouv.vitam.common
Class StringUtils
- java.lang.Object
-
- fr.gouv.vitam.common.StringUtils
-
public final class StringUtils extends java.lang.Object
String utils
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.Pattern
HTML_PATTERN
static java.util.List<java.lang.String>
RULES
static java.util.regex.Pattern
UNPRINTABLE_PATTERN
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
checkSanityString(java.lang.String value)
Check external argument to avoid Path Traversal attackstatic void
checkSanityString(java.lang.String... strings)
Check external argumentstatic byte[]
getBytesFromArraysToString(java.lang.String bytesString)
Revert Arrays.toString for bytesstatic java.lang.String
getClassName(java.lang.Object object)
static byte[]
getRandom(int length)
static java.lang.String
getStringFromInputStream(java.io.InputStream is)
Get text content of an input streamstatic java.lang.String
substringBeforeLast(java.lang.String source, java.lang.String separator)
Gets the substring before the last occurrence of a separator.static java.lang.String
substringBetween(java.lang.String source, java.lang.String start, java.lang.String end)
Gets the String that is nested in between two Strings.
-
-
-
Method Detail
-
checkSanityString
public static java.lang.String checkSanityString(java.lang.String value) throws InvalidParseOperationException
Check external argument to avoid Path Traversal attack- Parameters:
value
- to check- Throws:
InvalidParseOperationException
-
checkSanityString
public static void checkSanityString(java.lang.String... strings) throws InvalidParseOperationException
Check external argument- Parameters:
strings
-- Throws:
InvalidParseOperationException
-
getRandom
public static final byte[] getRandom(int length)
- Parameters:
length
- the length of rray- Returns:
- a byte array with random values
-
getBytesFromArraysToString
public static final byte[] getBytesFromArraysToString(java.lang.String bytesString)
Revert Arrays.toString for bytes- Parameters:
bytesString
- the string to transform- Returns:
- the array of bytes
- Throws:
java.lang.IllegalArgumentException
- if bytesString is null or empty
-
getClassName
public static final java.lang.String getClassName(java.lang.Object object)
- Parameters:
object
- to get its class name- Returns:
- the short name of the Class of this object
-
substringBetween
public static final java.lang.String substringBetween(java.lang.String source, java.lang.String start, java.lang.String end)
Gets the String that is nested in between two Strings. Only the first match is returned.- Parameters:
source
-start
-end
-- Returns:
- the substring, null if no match
-
substringBeforeLast
public static final java.lang.String substringBeforeLast(java.lang.String source, java.lang.String separator)
Gets the substring before the last occurrence of a separator. The separator is not returned.- Parameters:
source
-separator
-- Returns:
- the substring before the last occurrence of the separator, null if null String input
-
getStringFromInputStream
public static java.lang.String getStringFromInputStream(java.io.InputStream is) throws java.io.IOException
Get text content of an input stream- Parameters:
is
- input stream- Returns:
- text content
- Throws:
java.io.IOException
- when input stream unreadable
-
-