Package com.logicaldoc.util
Class StringUtil
- java.lang.Object
-
- com.logicaldoc.util.StringUtil
-
public class StringUtil extends Object
Some utility methods specialized in string manipulation- Since:
- 4.5
- Author:
- Marco Meschieri - LogicalDOC
-
-
Constructor Summary
Constructors Constructor Description StringUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringarrayToString(Object[] a, String separator)static StringcollectionToString(Collection<?> collection, String separator)static booleanmatches(String str, String[] includes, String[] excludes)Check if a given string matches theincludesand not theexcludesstatic StringprintFileSize(long size)Formats a file size in human readable form (KB, MB, GB, TB)static StringremoveNonUtf8Chars(String src)static Stringsplit(String src, char separator, int tokenSize)Splits a string into tokens separated by a separatorstatic String[]split(String src, int tokenSize)Splits a string into an array of tokensstatic Stringunaccent(String src)Converts 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 Detail
-
split
public static String split(String src, char separator, int tokenSize)
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
public static String[] split(String src, int tokenSize)
Splits a string into an array of tokens- Parameters:
src- The source stringtokenSize- size of each token- Returns:
- array of splitted tokens
-
writeToString
public static String writeToString(Reader reader) throws IOException
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 thereaderfailed to read or if the string cannot be written
-
writeToString
public static String writeToString(Reader reader, String targetEncoding) throws IOException
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 thereaderis unable to get the contents
-
writeToString
public static String writeToString(InputStream is, String targetEncoding) throws IOException
- Throws:
IOException
-
collectionToString
public static String collectionToString(Collection<?> collection, String separator)
-
removeNonUtf8Chars
public static String removeNonUtf8Chars(String src) throws CharacterCodingException
- Throws:
CharacterCodingException
-
matches
public static boolean matches(String str, String[] includes, String[] excludes)
Check if a given string matches theincludesand 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
public static String unaccent(String src)
Converts the non latin chars in the nearest ASCII char- Parameters:
src- the source string to process- Returns:
- the unaccented string
-
printFileSize
public static String printFileSize(long size)
Formats a file size in human readable form (KB, MB, GB, TB)- Parameters:
size- the size to format- Returns:
- the formatted string
-
-