Package com.logicaldoc.util
Class StringUtil
java.lang.Object
com.logicaldoc.util.StringUtil
Some utility methods specialized in string manipulation
- Since:
- 4.5
- Author:
- Marco Meschieri - LogicalDOC
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
arrayToString
(Object[] a, String separator) static String
collectionToString
(Collection<?> collection, String separator) static String
defaultString
(String input, String def) Returns the default string in case the input is empty or nullstatic boolean
Check if a given string matches theincludes
and not theexcludes
static String
printFileSize
(long size) Formats a file size in human readable form (KB, MB, GB, TB)static String
printFileSize
(long size, Locale locale) Formats a file size in human readable form (KB, MB, GB, TB)static String
removeNonUtf8Chars
(String src) static String
Splits a string into tokens separated by a separatorstatic String[]
Splits a string into an array of tokensstatic String
Converts the non latin chars in the nearest ASCII charstatic String
writeToString
(InputStream is, String targetEncoding) static String
writeToString
(Reader reader) Writes to UFT-8 encoding.static String
writeToString
(Reader reader, String targetEncoding) Writes the content from the reader in a string encoded as specified.
-
Method Details
-
split
Splits a string into tokens separated by a separator- Parameters:
src
- The source stringseparator
- The separator charactertokenSize
- Size or each token- Returns:
- the string with separators
-
split
Splits a string into an array of tokens- Parameters:
src
- The source stringtokenSize
- size of each token- Returns:
- array of splitted tokens
-
writeToString
Writes to UFT-8 encoding.- Parameters:
reader
- the reader over a string- Returns:
- a string with the contents readed from the
reader
- Throws:
IOException
- raised in case thereader
failed to read or if the string cannot be written
-
writeToString
Writes the content from the reader in a string encoded as specified.- Parameters:
reader
- Attention, this will be closed at the end of invocationtargetEncoding
- The output string encoding- Returns:
- The encoded string
- Throws:
IOException
- raised in case thereader
is unable to get the contents
-
writeToString
- Throws:
IOException
-
arrayToString
-
collectionToString
-
removeNonUtf8Chars
-
matches
Check if a given string matches theincludes
and not theexcludes
- Parameters:
str
- The string to considerincludes
- list of includes regular expressionsexcludes
- list of excludes regular expressions- Returns:
- true only if the passed string matches the includes and not the excludes
-
unaccent
Converts the non latin chars in the nearest ASCII char- Parameters:
src
- the source string to process- Returns:
- the unaccented string
-
printFileSize
Formats a file size in human readable form (KB, MB, GB, TB)- Parameters:
size
- the size to format- Returns:
- the formatted string
-
printFileSize
Formats a file size in human readable form (KB, MB, GB, TB)- Parameters:
size
- the size to formatlocale
- the locale to use for the separators and decimals- Returns:
- the formatted string
-
defaultString
Returns the default string in case the input is empty or null- Parameters:
input
- the input stringdef
- the default string- Returns:
- input or default
-