Class StringUtils
java.lang.Object
is.galia.util.StringUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic String
decodeSlashes
(String uriPathComponent) Some web servers have issues dealing with encoded slashes ( %2F) in URIs.static String
encodeSlashes
(String uriPathComponent) static String
escapeHTML
(String html) static String
fromByteSize
(long byteSize) static String
static String
randomAlphanumeric
(int length) static String
removeTrailingZeroes
(double d) static String
static String
Recursively filters outremoveables
from the given dirty string.static String
Recursively filters outremoveables
from the given dirty string, replacing it withreplacement
.static String
Strips a string from the end of another string.static String
stripStart
(String str, String toStrip) Strips a string from the beginning of another string.static boolean
Converts a string to a boolean.static long
toByteSize
(String str) The following byte size formats are supported: Whole number Decimal number suffixed with K, KB, M, MB, G, GB, T, TB, P, PB Lowercase suffixes are allowed. Spaces are allowed between the number and suffix.static String
toHex
(byte[] bytes) wrap
(String str, FontMetrics fm, int maxWidth) Returns an array of strings, one for each line in the string after it has been wrapped to fit lines of maxWidth.
-
Field Details
-
ASCII_FILENAME_UNSAFE_REGEX
- See Also:
-
UNICODE_FILENAME_UNSAFE_REGEX
- See Also:
-
-
Method Details
-
decodeSlashes
Some web servers have issues dealing with encoded slashes ( %2F) in URIs. This method enables the use of an alternate string to represent a slash viaKey.SLASH_SUBSTITUTE
.- Parameters:
uriPathComponent
- Path component (a part of the path before, after, or between slashes).- Returns:
- Path component with slashes decoded.
- See Also:
-
encodeSlashes
-
escapeHTML
-
fromByteSize
- Parameters:
byteSize
- Size in bytes.- Returns:
- String with unit suffix.
-
md5
-
randomAlphanumeric
- Parameters:
length
- Length of the string.- Returns:
- Random alphanumeric string.
-
removeTrailingZeroes
- Returns:
- String representation of the given number with trailing zeroes removed.
-
reverse
-
sanitize
-
sanitize
-
stripEnd
-
stripStart
-
toBoolean
Converts a string to a boolean. 1 and true are accepted as true; 0 and false as false. All other arguments throw aNumberFormatException
, in contrast toBoolean.parseBoolean(String)
, which treats all non-true values as false.- Parameters:
str
- String to convert.- Returns:
- Boolean value of the given string.
- Throws:
NumberFormatException
- if the string has an unrecognized format.
-
toByteSize
The following byte size formats are supported:- Whole number
- Decimal number suffixed with K, KB,
M, MB, G, GB,
T, TB, P, PB
- Lowercase suffixes are allowed.
- Spaces are allowed between the number and suffix.
- Parameters:
str
- String byte size.- Returns:
- If the given string had no units, a long representation. Otherwise, a power of 1024.
-
toHex
- Parameters:
bytes
- Bytes to print.- Returns:
- Lowercase hexadecimal string.
-
wrap
Returns an array of strings, one for each line in the string after it has been wrapped to fit lines of maxWidth. Lines end with any of CR, LF, or CRLF. A line ending at the end of the string will not output a further, empty string.- Parameters:
str
- The string to split. Must not benull
.fm
- Used for string width calculations.maxWidth
- The max line width, in points.- Returns:
- List of strings.
-