Package rs.baselib.util
Class CommonUtils
java.lang.Object
rs.baselib.util.CommonUtils
public class CommonUtils
extends java.lang.Object
Common Utils.
- Author:
- ralph
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_CONNECT_TIMEOUTDefault timeout for connecting to URLs (10sec)static intDEFAULT_READ_TIMEOUTDefault timeout for reading from URLs (20sec) -
Constructor Summary
Constructors Constructor Description CommonUtils() -
Method Summary
Modifier and Type Method Description static intcompareVersion(java.lang.String[] v1, java.lang.String[] v2)Compares versions.static intcompareVersion(java.lang.String v1, java.lang.String v2)Compares software versions.static java.text.DateFormatDATE_FORMATTER()The formatter for dates (seeDateFormat.SHORT).static java.text.DateFormatDATE_TIME_FORMATTER()The formatter for dates incl.static java.lang.StringdebugObject(java.lang.Object o)Recursively debugs objects.static voiddebugObject(java.lang.StringBuffer s, java.lang.Object o)Recursively debugs objects and adds this in the string buffer.static voiddebugObject(java.lang.StringBuilder s, java.lang.Object o)Recursively debugs objects and adds this in the string builder.static voiddebugStackTrace(Logger log)Dumps the stacktrace in DEBUG mode.static booleanequals(java.lang.Object o1, java.lang.Object o2)Checks for equality null-safestatic voiderrorStackTrace(Logger log)Dumps the stacktrace in ERROR mode.static intgetConnectTimeout()Returns the URL connect timeout.static java.lang.StringgetDisplay(java.lang.Enum<?> e)Returns the display string for the default locale.static java.lang.StringgetDisplay(java.lang.Enum<?> e, java.util.Locale locale)Returns the display string for the given locale.static java.lang.StringgetDisplay(java.lang.Object o)The display of the objectstatic java.lang.StringgetDisplay(java.lang.Object o, java.util.Locale locale)Returns the display string of an object.static java.lang.Enum<?>getEnum(java.lang.Class<? extends java.lang.Enum<?>> clazz, java.lang.String display)Returns the enum constant for given display in default locale.static java.lang.Enum<?>getEnum(java.lang.Class<? extends java.lang.Enum<?>> clazz, java.lang.String display, java.util.Locale locale)Returns the enum constant for given display in given locale.static java.util.List<java.lang.Enum<?>>getOptionList(java.lang.Class<? extends java.lang.Enum<?>> clazz)Returns a list of options from an enumeration class.static java.lang.String[]getOptions(java.lang.Class<? extends java.lang.Enum<?>> clazz)Returns a list of options for display in default locale.static java.lang.String[]getOptions(java.lang.Class<? extends java.lang.Enum<?>> clazz, java.util.Locale locale)Returns a list of options for display in given locale.static java.lang.StringgetOS()Returns the OS name.static intgetReadTimeout()Returns the URL read timeout.static java.util.List<java.lang.String>getStackTrace(int ignoreLines)Returns the current stacktrace.static longgetUnixTimestamp()Returns the current time as UNIX timestamp.static longgetUnixTimestamp(long time)Returns the given Java time as UNIX timestamp.static longgetUnixTimestamp(java.util.Date date)Returns the given date as UNIX timestamp.static longgetUnixTimestamp(RsDate date)Returns the given date as UNIX timestamp.static voidinfoStackTrace(Logger log)Dumps the stacktrace in INFO mode.static booleanisCompatibleVersion(java.lang.String minVersion, java.lang.String maxVersion, java.lang.String version)Returns true if version is in range of minVersion and maxVersion.static booleanisEmail(java.lang.String s)Checks validity of an email address.static booleanisEmpty(java.lang.String s)Returns true when the given string is null or - when trimmed - empty.static booleanisEmpty(java.lang.String s, boolean trim)Returns true when the given string is null empty.static booleanisMac()Tells whether runtime is a Mac system.static booleanisSolaris()Tells whether runtime is a Windows system.static booleanisUnix()Tells whether runtime is a Unix system.static booleanisWindows()Tells whether runtime is a Windows system.static <T> java.lang.Iterable<T>iterable(java.util.Iterator<T> iterator)Returns an iterable for the given iterator.static java.lang.Stringjoin(java.lang.String separator, java.lang.Object[] parts)Makes a join of an object array.static java.lang.Stringjoin(java.lang.String separator, java.lang.Object[] parts, int startIndex)Makes a join of an object array.static java.lang.Stringjoin(java.lang.String separator, java.lang.Object[] parts, int startIndex, int endIndex)Makes a join of an object array.static java.lang.Stringjoin(java.lang.String separator, java.lang.String[] parts)Makes a join of a string array.static java.lang.Stringjoin(java.lang.String separator, java.lang.String[] parts, int startIndex)Makes a join of a string array.static java.lang.Stringjoin(java.lang.String separator, java.lang.String[] parts, int startIndex, int endIndex)Makes a join of a string array.static java.lang.Stringjoin(java.lang.String separator, java.util.Collection<?> parts)Makes a join of a collection.static java.lang.Stringjoin(java.lang.String separator, java.util.Collection<?> parts, int startIndex)Makes a join of a collection.static java.lang.Stringjoin(java.lang.String separator, java.util.Collection<?> parts, int startIndex, int endIndex)Makes a join of a collection.static java.lang.StringloadContent(java.io.File f)Loads the content of a file as a string.static java.lang.StringloadContent(java.io.File f, java.nio.charset.Charset charset)Loads the content of a file as a string.static java.lang.StringloadContent(java.io.InputStream in)Loads the content of a stream as a string.static java.lang.StringloadContent(java.io.InputStream in, java.nio.charset.Charset charset)Loads the content of a stream as a string.static java.lang.StringloadContent(java.io.Reader reader)Loads the content of a reader as a string.static java.lang.StringloadContent(java.lang.String name)Loads the content of a file as a string.static java.lang.StringloadContent(java.lang.String name, java.nio.charset.Charset charset)Loads the content of a file as a string.static java.lang.StringloadContent(java.net.URL url)Loads the content of the URL as a string.static java.lang.StringloadContent(java.net.URLConnection con, java.nio.charset.Charset charset)Loads the content of the URL as a string.static java.lang.StringloadContent(java.net.URL url, java.nio.charset.Charset charset)Loads the content of the URL as a string.static java.util.PropertiesloadProperties(java.io.File file)Loads a property file.static java.util.PropertiesloadProperties(java.lang.String file)Loads a property file.static voidloadProperties(java.util.Properties props, java.io.File file)Loads a property file.static voidloadProperties(java.util.Properties props, java.lang.String file)Loads a property file.static voidprintStackTrace(java.io.PrintStream out, int ignoreLines)Dumps the stacktrace into the print stream.static java.lang.StringreplaceEnvVariables(java.lang.String s)Replaces environment variables.static java.lang.StringreplaceRuntimeVariables(java.lang.String s)Replaces environment variables.static java.lang.StringreplaceVariables(java.lang.String s)Replaces environment and system variables.static java.net.URLsetAnchor(java.net.URL url, java.lang.String anchor)Set the anchor id for at the given URL.static voidsetConnectTimeout(int connectTimeout)Sets the URL connect timeout.static java.lang.StringsetMarkers(java.lang.String template, java.lang.String prefix, java.lang.Object valueObject)Sets markers in a template.static voidsetReadTimeout(int readTimeout)Sets the URL read timeout.static java.text.NumberFormatSIMPLE_INT_FORMATTER()Formatter for integers.static java.text.NumberFormatSIMPLE_NUMBER_FORMATTER()Formatter for real numbers.static voidstderrStackTrace()Dumps the stacktrace so stderr.static voidstdoutStackTrace()Dumps the stacktrace so stdout.static voidstoreProperties(java.util.Properties props, java.io.File file)Stores a property file.static voidstoreProperties(java.util.Properties props, java.lang.String file)Stores a property file.static java.lang.StringtoString(byte[] b)Generates a string presentation of the given bytes.static java.lang.StringtoString(float amount)Formats the money value.static java.lang.StringtoString(java.lang.Object[] o)Generates a string presentation of the given objects.static java.lang.StringtoString(java.lang.String o)Formats the string for display.static java.lang.StringtoString(RsDate date)Formats the given date.static java.lang.StringtoString(RsDay day)Formats the given day.static java.lang.StringtoString(RsMonth month)Formats the given month (1st day of month).static java.lang.StringtoString(RsYear year)Formats the given year.static voidtraceStackTrace(Logger log)Dumps the stacktrace in TRACE mode.static voidwriteContent(java.io.File f, java.lang.String content)Writes the string to a file.static voidwriteContent(java.io.File f, java.lang.String content, java.nio.charset.Charset charset)Writes the string to a file.static voidwriteContent(java.io.OutputStream out, java.lang.String content)Writes the string to a stream.static voidwriteContent(java.io.OutputStream out, java.lang.String content, java.nio.charset.Charset charset)Writes the string to a stream.static voidwriteContent(java.io.Writer writer, java.lang.String content)Writes the string to a writer.static voidwriteContent(java.lang.String name, java.lang.String content)Writes the string to a file.static voidwriteContent(java.lang.String name, java.lang.String content, java.nio.charset.Charset charset)Writes the string to a file.
-
Field Details
-
DEFAULT_CONNECT_TIMEOUT
public static int DEFAULT_CONNECT_TIMEOUTDefault timeout for connecting to URLs (10sec) -
DEFAULT_READ_TIMEOUT
public static int DEFAULT_READ_TIMEOUTDefault timeout for reading from URLs (20sec)
-
-
Constructor Details
-
CommonUtils
public CommonUtils()
-
-
Method Details
-
DATE_FORMATTER
public static java.text.DateFormat DATE_FORMATTER()The formatter for dates (seeDateFormat.SHORT).- Returns:
- the formatter
-
DATE_TIME_FORMATTER
public static java.text.DateFormat DATE_TIME_FORMATTER()The formatter for dates incl. times (seeDateFormat.SHORT).- Returns:
- the formatter
-
SIMPLE_NUMBER_FORMATTER
public static java.text.NumberFormat SIMPLE_NUMBER_FORMATTER()Formatter for real numbers.- Returns:
- the formatter
-
SIMPLE_INT_FORMATTER
public static java.text.NumberFormat SIMPLE_INT_FORMATTER()Formatter for integers.- Returns:
- the formatter
-
toString
public static java.lang.String toString(java.lang.String o)Formats the string for display.- Parameters:
o- the category- Returns:
- string display
-
toString
public static java.lang.String toString(float amount)Formats the money value.- Parameters:
amount- amount to be formatted- Returns:
- formatted string
-
toString
Formats the given date.- Parameters:
date- date to format- Returns:
- the formatted string (see
DATE_TIME_FORMATTER())
-
toString
Formats the given day.- Parameters:
day- day to format- Returns:
- the formatted string (see
DATE_FORMATTER())
-
toString
Formats the given year.- Parameters:
year- year to format- Returns:
- the formatted string
-
toString
Formats the given month (1st day of month).- Parameters:
month- date to format- Returns:
- the formatted string (see
DATE_FORMATTER())
-
toString
public static java.lang.String toString(byte[] b)Generates a string presentation of the given bytes.- Parameters:
b- byte array- Returns:
- string representation (Hex)
-
toString
public static java.lang.String toString(java.lang.Object[] o)Generates a string presentation of the given objects.- Parameters:
o- object array- Returns:
- string representation
-
equals
public static boolean equals(java.lang.Object o1, java.lang.Object o2)Checks for equality null-safe- Parameters:
o1- object 1o2- object 2- Returns:
- true when both values are equal
-
isEmpty
public static boolean isEmpty(java.lang.String s)Returns true when the given string is null or - when trimmed - empty.- Parameters:
s- the string to be checked- Returns:
- true when string must be regarded as empty
-
isEmpty
public static boolean isEmpty(java.lang.String s, boolean trim)Returns true when the given string is null empty.- Parameters:
s- the string to be checkedtrim- whether whitespaces shall be trimmed first- Returns:
- true when string must be regarded as empty
-
getOptions
public static java.lang.String[] getOptions(java.lang.Class<? extends java.lang.Enum<?>> clazz)Returns a list of options for display in default locale.- Parameters:
clazz- enum class- Returns:
- list of display options
-
getOptions
public static java.lang.String[] getOptions(java.lang.Class<? extends java.lang.Enum<?>> clazz, java.util.Locale locale)Returns a list of options for display in given locale.- Parameters:
clazz- enum classlocale- locale- Returns:
- list of display options
-
getOptionList
public static java.util.List<java.lang.Enum<?>> getOptionList(java.lang.Class<? extends java.lang.Enum<?>> clazz)Returns a list of options from an enumeration class.- Parameters:
clazz- enum class- Returns:
- list of display options
-
getDisplay
public static java.lang.String getDisplay(java.lang.Enum<?> e)Returns the display string for the default locale.- Parameters:
e- enum value- Returns:
- display
-
getDisplay
public static java.lang.String getDisplay(java.lang.Enum<?> e, java.util.Locale locale)Returns the display string for the given locale.- Parameters:
e- enum valuelocale- locale- Returns:
- display
-
getEnum
public static java.lang.Enum<?> getEnum(java.lang.Class<? extends java.lang.Enum<?>> clazz, java.lang.String display)Returns the enum constant for given display in default locale.- Parameters:
clazz- enum classdisplay- display of enum- Returns:
- enum constant
-
getEnum
public static java.lang.Enum<?> getEnum(java.lang.Class<? extends java.lang.Enum<?>> clazz, java.lang.String display, java.util.Locale locale)Returns the enum constant for given display in given locale.- Parameters:
clazz- enum classdisplay- display of enumlocale- locale- Returns:
- enum constant
-
isCompatibleVersion
public static boolean isCompatibleVersion(java.lang.String minVersion, java.lang.String maxVersion, java.lang.String version)Returns true if version is in range of minVersion and maxVersion. Note that 1.2.0 is greater than 1.2- Parameters:
minVersion- - minimum required version (can be null)maxVersion- - maximum required version (can be null)version- - version to check- Returns:
- true when version is within range
-
compareVersion
public static int compareVersion(java.lang.String v1, java.lang.String v2)Compares software versions.- Parameters:
v1- - version 1v2- - version 2- Returns:
- -1 if v1 < v2, 1 if v1 > v2, 0 if v1 = v2
-
compareVersion
public static int compareVersion(java.lang.String[] v1, java.lang.String[] v2)Compares versions.- Parameters:
v1- - version 1 divided into separate partsv2- - version 2 divided into separate parts- Returns:
- -1 if v1 < v2, 1 if v1 > v2, 0 if v1 = v2
-
join
public static java.lang.String join(java.lang.String separator, java.util.Collection<?> parts)Makes a join of a collection.- Parameters:
separator- - the string to be used inbetween partsparts- - the collection to join- Returns:
- the joined string
-
join
public static java.lang.String join(java.lang.String separator, java.lang.String[] parts)Makes a join of a string array.- Parameters:
separator- - the string to be used inbetween partsparts- - the parts to join- Returns:
- the joined string
-
join
public static java.lang.String join(java.lang.String separator, java.lang.Object[] parts)Makes a join of an object array.- Parameters:
separator- - the string to be used inbetween partsparts- - the parts to join- Returns:
- the joined string
- Since:
- 1.2.9
-
join
public static java.lang.String join(java.lang.String separator, java.lang.String[] parts, int startIndex)Makes a join of a string array.- Parameters:
separator- - the string to be used inbetween partsparts- - the parts to joinstartIndex- - starting index (negative values not allowed)- Returns:
- the joined string
-
join
public static java.lang.String join(java.lang.String separator, java.util.Collection<?> parts, int startIndex)Makes a join of a collection.- Parameters:
separator- - the string to be used inbetween partsparts- - the collection to joinstartIndex- - starting index (negative values not allowed)- Returns:
- the joined string
- Since:
- 1.2.9
-
join
public static java.lang.String join(java.lang.String separator, java.lang.Object[] parts, int startIndex)Makes a join of an object array.- Parameters:
separator- - the string to be used inbetween partsparts- - the parts to joinstartIndex- - starting index (negative values not allowed)- Returns:
- the joined string
- Since:
- 1.2.9
-
join
public static java.lang.String join(java.lang.String separator, java.lang.String[] parts, int startIndex, int endIndex)Makes a join of a string array.- Parameters:
separator- - the string to be used inbetween partsparts- - the parts to joinstartIndex- - starting index (negative values not allowed)endIndex- - endIndex (bigger values than number or array elements have no effect)- Returns:
- the joined string
-
join
public static java.lang.String join(java.lang.String separator, java.lang.Object[] parts, int startIndex, int endIndex)Makes a join of an object array.- Parameters:
separator- - the string to be used inbetween partsparts- - the parts to joinstartIndex- - starting index (negative values not allowed)endIndex- - endIndex (bigger values than number or array elements have no effect)- Returns:
- the joined string
- Since:
- 1.2.9
-
join
public static java.lang.String join(java.lang.String separator, java.util.Collection<?> parts, int startIndex, int endIndex)Makes a join of a collection.- Parameters:
separator- - the string to be used inbetween partsparts- - the collection to joinstartIndex- - starting index (negative values not allowed)endIndex- - endIndex (bigger values than number or collection elements have no effect)- Returns:
- the joined string
- Since:
- 1.2.9
-
debugObject
public static java.lang.String debugObject(java.lang.Object o)Recursively debugs objects.- Parameters:
o- object to debug- Returns:
- the debug string
- Since:
- 1.2.3
-
debugObject
public static void debugObject(java.lang.StringBuffer s, java.lang.Object o)Recursively debugs objects and adds this in the string buffer.- Parameters:
s- string buffer to enhanceo- object to debug
-
debugObject
public static void debugObject(java.lang.StringBuilder s, java.lang.Object o)Recursively debugs objects and adds this in the string builder.- Parameters:
s- string builder to enhanceo- object to debug- Since:
- 1.2.3
-
getUnixTimestamp
public static long getUnixTimestamp()Returns the current time as UNIX timestamp.- Returns:
- time in seconds since January 1st, 1970, 00:00:00 UTC.
-
getUnixTimestamp
public static long getUnixTimestamp(java.util.Date date)Returns the given date as UNIX timestamp.- Parameters:
date- date object.- Returns:
- time in seconds since January 1st, 1970, 00:00:00 UTC.
-
getUnixTimestamp
Returns the given date as UNIX timestamp.- Parameters:
date- date object.- Returns:
- time in seconds since January 1st, 1970, 00:00:00 UTC.
-
getUnixTimestamp
public static long getUnixTimestamp(long time)Returns the given Java time as UNIX timestamp.- Parameters:
time- Java timestamp- Returns:
- time in seconds since January 1st, 1970, 00:00:00 UTC.
-
iterable
public static <T> java.lang.Iterable<T> iterable(java.util.Iterator<T> iterator)Returns an iterable for the given iterator.- Type Parameters:
T- type of objects in the iterator- Parameters:
iterator- the iterator to be wrapped- Returns:
- the iterable.
-
getStackTrace
public static java.util.List<java.lang.String> getStackTrace(int ignoreLines)Returns the current stacktrace.- Parameters:
ignoreLines- the number of lines to be ignored at the top of the trace- Returns:
- the stacktrace
-
stdoutStackTrace
public static void stdoutStackTrace()Dumps the stacktrace so stdout. -
stderrStackTrace
public static void stderrStackTrace()Dumps the stacktrace so stderr. -
printStackTrace
public static void printStackTrace(java.io.PrintStream out, int ignoreLines)Dumps the stacktrace into the print stream.- Parameters:
out- the stream to be usedignoreLines- the number of lines to be ignored at top of trace
-
errorStackTrace
Dumps the stacktrace in ERROR mode.- Parameters:
log- the logger to be used
-
infoStackTrace
Dumps the stacktrace in INFO mode.- Parameters:
log- the logger to be used
-
debugStackTrace
Dumps the stacktrace in DEBUG mode.- Parameters:
log- the logger to be used
-
traceStackTrace
Dumps the stacktrace in TRACE mode.- Parameters:
log- the logger to be used
-
loadProperties
public static java.util.Properties loadProperties(java.io.File file) throws java.io.IOExceptionLoads a property file.- Parameters:
file- the file to load- Returns:
- the properties
- Throws:
java.io.IOException- when file cannot be loaded
-
loadProperties
public static java.util.Properties loadProperties(java.lang.String file) throws java.io.IOExceptionLoads a property file.- Parameters:
file- the file to load- Returns:
- the properties
- Throws:
java.io.IOException- when file cannot be loaded
-
loadProperties
public static void loadProperties(java.util.Properties props, java.io.File file) throws java.io.IOExceptionLoads a property file.- Parameters:
props- the properties objectfile- the file to load- Throws:
java.io.IOException- when file cannot be loaded
-
loadProperties
public static void loadProperties(java.util.Properties props, java.lang.String file) throws java.io.IOExceptionLoads a property file.- Parameters:
props- the properties objectfile- the file to load- Throws:
java.io.IOException- when file cannot be loaded
-
storeProperties
public static void storeProperties(java.util.Properties props, java.io.File file) throws java.io.IOExceptionStores a property file.- Parameters:
props- the properties objectfile- the file to load- Throws:
java.io.IOException- when file cannot be stored
-
storeProperties
public static void storeProperties(java.util.Properties props, java.lang.String file) throws java.io.IOExceptionStores a property file.- Parameters:
props- the properties objectfile- the file to load- Throws:
java.io.IOException- when file cannot be stored
-
getConnectTimeout
public static int getConnectTimeout()Returns the URL connect timeout.- Returns:
- the connectTimeout
-
setConnectTimeout
public static void setConnectTimeout(int connectTimeout)Sets the URL connect timeout.- Parameters:
connectTimeout- the connectTimeout to set
-
getReadTimeout
public static int getReadTimeout()Returns the URL read timeout.- Returns:
- the readTimeout
-
setReadTimeout
public static void setReadTimeout(int readTimeout)Sets the URL read timeout.- Parameters:
readTimeout- the readTimeout to set
-
loadContent
public static java.lang.String loadContent(java.net.URL url) throws java.io.IOExceptionLoads the content of the URL as a string.- Parameters:
url- URL to be loaded- Returns:
- the content of the URL
- Throws:
java.io.IOException- when content of URL cannot be loaded
-
loadContent
public static java.lang.String loadContent(java.net.URL url, java.nio.charset.Charset charset) throws java.io.IOExceptionLoads the content of the URL as a string.- Parameters:
url- URL to be loadedcharset- the charset of the content (nullfordefault charset)- Returns:
- the content of the URL
- Throws:
java.io.IOException- when content of URL cannot be loaded
-
loadContent
public static java.lang.String loadContent(java.net.URLConnection con, java.nio.charset.Charset charset) throws java.io.IOExceptionLoads the content of the URL as a string.- Parameters:
con- URL connection to be usedcharset- the charset of the content (nullfordefault charset)- Returns:
- the content of the URL
- Throws:
java.io.IOException- when content of URL cannot be loaded
-
loadContent
public static java.lang.String loadContent(java.lang.String name) throws java.io.IOExceptionLoads the content of a file as a string.- Parameters:
name- name of file to be loaded- Returns:
- the content of the file
- Throws:
java.io.IOException- when content of file cannot be loaded
-
loadContent
public static java.lang.String loadContent(java.lang.String name, java.nio.charset.Charset charset) throws java.io.IOExceptionLoads the content of a file as a string.- Parameters:
name- name of file to be loadedcharset- the charset of the content (nullfordefault charset)- Returns:
- the content of the file
- Throws:
java.io.IOException- when content of file cannot be loaded
-
loadContent
public static java.lang.String loadContent(java.io.File f) throws java.io.IOExceptionLoads the content of a file as a string.- Parameters:
f- file to be loaded- Returns:
- the content of the file
- Throws:
java.io.IOException- when content of file cannot be loaded
-
loadContent
public static java.lang.String loadContent(java.io.File f, java.nio.charset.Charset charset) throws java.io.IOExceptionLoads the content of a file as a string.- Parameters:
f- file to be loadedcharset- the charset of the content (nullfordefault charset)- Returns:
- the content of the file
- Throws:
java.io.IOException- when content of file cannot be loaded
-
loadContent
public static java.lang.String loadContent(java.io.InputStream in) throws java.io.IOExceptionLoads the content of a stream as a string.- Parameters:
in- stream to be loaded- Returns:
- the content of the stream
- Throws:
java.io.IOException- when content of stream cannot be loaded
-
loadContent
public static java.lang.String loadContent(java.io.InputStream in, java.nio.charset.Charset charset) throws java.io.IOExceptionLoads the content of a stream as a string.- Parameters:
in- stream to be loadedcharset- the charset of the content (nullfordefault charset)- Returns:
- the content of the stream
- Throws:
java.io.IOException- when content of stream cannot be loaded
-
loadContent
public static java.lang.String loadContent(java.io.Reader reader) throws java.io.IOExceptionLoads the content of a reader as a string.- Parameters:
reader- reader to be loaded- Returns:
- the content of the reader
- Throws:
java.io.IOException- when content of reader cannot be loaded
-
writeContent
public static void writeContent(java.lang.String name, java.lang.String content) throws java.io.IOExceptionWrites the string to a file.- Parameters:
name- name of file to be written tocontent- the content to be written- Throws:
java.io.IOException- when content cannot be written
-
writeContent
public static void writeContent(java.lang.String name, java.lang.String content, java.nio.charset.Charset charset) throws java.io.IOExceptionWrites the string to a file.- Parameters:
name- name of file to be written tocontent- the content to be writtencharset- the charset of the content (nullfordefault charset)- Throws:
java.io.IOException- when content cannot be written
-
writeContent
public static void writeContent(java.io.File f, java.lang.String content) throws java.io.IOExceptionWrites the string to a file.- Parameters:
f- file to be written tocontent- the content to be written- Throws:
java.io.IOException- when content cannot be written
-
writeContent
public static void writeContent(java.io.File f, java.lang.String content, java.nio.charset.Charset charset) throws java.io.IOExceptionWrites the string to a file.- Parameters:
f- file to be written tocontent- the content to be writtencharset- the charset of the content (nullfordefault charset)- Throws:
java.io.IOException- when content cannot be written
-
writeContent
public static void writeContent(java.io.OutputStream out, java.lang.String content) throws java.io.IOExceptionWrites the string to a stream.- Parameters:
out- stream to be written tocontent- the content to be written- Throws:
java.io.IOException- when content cannot be written
-
writeContent
public static void writeContent(java.io.OutputStream out, java.lang.String content, java.nio.charset.Charset charset) throws java.io.IOExceptionWrites the string to a stream.- Parameters:
out- stream to be written tocontent- the content to be writtencharset- the charset of the content (nullfordefault charset)- Throws:
java.io.IOException- when content cannot be written
-
writeContent
public static void writeContent(java.io.Writer writer, java.lang.String content) throws java.io.IOExceptionWrites the string to a writer.- Parameters:
writer- writer to be written tocontent- the content to be written- Throws:
java.io.IOException- when content cannot be written
-
isWindows
public static boolean isWindows()Tells whether runtime is a Windows system.- Returns:
truewhen OS is a Windows system
-
isMac
public static boolean isMac()Tells whether runtime is a Mac system.- Returns:
truewhen OS is a Mac system
-
isUnix
public static boolean isUnix()Tells whether runtime is a Unix system.- Returns:
truewhen OS is a Unix system
-
isSolaris
public static boolean isSolaris()Tells whether runtime is a Windows system.- Returns:
truewhen OS is a Windows system
-
isEmail
public static boolean isEmail(java.lang.String s)Checks validity of an email address.- Parameters:
s- the string to be checked- Returns:
truewhen string is a valid email address- Since:
- 1.2.9
-
getOS
public static java.lang.String getOS()Returns the OS name.- Returns:
- the OS name as returned by
System.getProperty("os.name")
-
getDisplay
public static java.lang.String getDisplay(java.lang.Object o)The display of the object- Parameters:
o- the object to be displayed- Returns:
- the display version
-
getDisplay
public static java.lang.String getDisplay(java.lang.Object o, java.util.Locale locale)Returns the display string of an object. The method detectsIDisplayable,IDisplayProviderandNamedObject.- Parameters:
o- the object to be displayedlocale- Locale to be used forIDisplayable- Returns:
- a displayable string
-
setAnchor
public static java.net.URL setAnchor(java.net.URL url, java.lang.String anchor)Set the anchor id for at the given URL.- Parameters:
url- url to be modifiedanchor- new anchor to be set- Returns:
- the modified URL but other components are kept
-
replaceEnvVariables
public static java.lang.String replaceEnvVariables(java.lang.String s)Replaces environment variables.The variables must be formed as
$ENV{<name>}, e.g.$ENV{PATH}.- Parameters:
s- string to be analyzed (can be null or empty)- Returns:
- string with variables replaced
-
replaceRuntimeVariables
public static java.lang.String replaceRuntimeVariables(java.lang.String s)Replaces environment variables.The variables must be formed as
$SYSTEM{<name>}, e.g.$SYSTEM{user.home}.- Parameters:
s- string to be analyzed (can be null or empty)- Returns:
- string with variables replaced
-
replaceVariables
public static java.lang.String replaceVariables(java.lang.String s)Replaces environment and system variables.The variables must be formed as:
$ENV{<name>}, e.g.$ENV{PATH}$SYSTEM{<name>}, e.g.$SYSTEM{user.home}
- Parameters:
s- string to be analyzed (can be null or empty)- Returns:
- string with variables replaced
-
setMarkers
public static java.lang.String setMarkers(java.lang.String template, java.lang.String prefix, java.lang.Object valueObject)Sets markers in a template.The markers must be like {@prefix:attribute-name}. The attribute value is the value of the getter method of the value object.
- Parameters:
template- the templateprefix- the marker prefixvalueObject- the object that contains values- Returns:
- the template with markers replaced
-