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 SummaryModifier and TypeMethodDescriptionstatic StringarrayToString(Object[] a, String separator) static StringcollectionToString(Collection<?> collection, String separator) static StringdefaultString(String input, String def) Returns the default string in case the input is empty or nullstatic booleanCheck if a given string matches theincludesand not theexcludesstatic StringprintFileSize(long size) Formats a file size in human readable form (KB, MB, GB, TB)static StringprintFileSize(long size, Locale locale) Formats a file size in human readable form (KB, MB, GB, TB)static StringremoveNonUtf8Chars(String src) static StringSplits a string into tokens separated by a separatorstatic String[]Splits a string into an array of tokensstatic StringConverts the non Latin chars in the nearest ASCII charstatic StringwriteToString(InputStream is, String targetEncoding) static StringwriteToString(Reader reader) Writes to UFT-8 encoding.static StringwriteToString(Reader reader, String targetEncoding) Writes the content from the reader in a string encoded as specified.
- 
Method Details- 
splitSplits a string into tokens separated by a separator- Parameters:
- src- The source string
- separator- The separator character
- tokenSize- Size or each token
- Returns:
- the string with separators
 
- 
splitSplits a string into an array of tokens- Parameters:
- src- The source string
- tokenSize- size of each token
- Returns:
- array of splitted tokens
 
- 
writeToStringWrites 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 the- readerfailed to read or if the string cannot be written
 
- 
writeToStringWrites the content from the reader in a string encoded as specified.- Parameters:
- reader- Attention, this will be closed at the end of invocation
- targetEncoding- The output string encoding
- Returns:
- The encoded string
- Throws:
- IOException- raised in case the- readeris unable to get the contents
 
- 
writeToString- Throws:
- IOException
 
- 
arrayToString
- 
collectionToString
- 
removeNonUtf8Chars
- 
matchesCheck if a given string matches theincludesand not theexcludes- Parameters:
- str- The string to consider
- includes- list of includes regular expressions
- excludes- list of excludes regular expressions
- Returns:
- true only if the passed string matches the includes and not the excludes
 
- 
unaccentConverts the non Latin chars in the nearest ASCII char- Parameters:
- src- the source string to process
- Returns:
- the unaccented string
 
- 
printFileSizeFormats a file size in human readable form (KB, MB, GB, TB)- Parameters:
- size- the size to format
- Returns:
- the formatted string
 
- 
printFileSizeFormats a file size in human readable form (KB, MB, GB, TB)- Parameters:
- size- the size to format
- locale- the locale to use for the separators and decimals
- Returns:
- the formatted string
 
- 
defaultStringReturns the default string in case the input is empty or null- Parameters:
- input- the input string
- def- the default string
- Returns:
- input or default
 
 
-