Class CommonUtils
- Author:
- ralph
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
alpha chars (uper and lower case letters)static final String
alpha and numeric charsstatic final String
alpha and numeric and special charsstatic int
Default timeout for connecting to URLs (10sec)static int
Default timeout for reading from URLs (20sec)static final String
numeric chars (0-9)static final String
special chars (!\"&/()=?;*+'#;,:._-<>
) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
compareVersion
(String[] v1, String[] v2) Compares versions.static int
compareVersion
(String v1, String v2) Compares software versions.static DateFormat
The formatter for dates (seeDateFormat.SHORT
).static DateFormat
The formatter for dates incl.static String
Recursively debugs objects.static void
debugObject
(StringBuffer s, Object o) Recursively debugs objects and adds this in the string buffer.static void
debugObject
(StringBuilder s, Object o) Recursively debugs objects and adds this in the string builder.static void
debugStackTrace
(Logger log) Dumps the stacktrace in DEBUG mode.static boolean
Checks for equality null-safe.static boolean
equalsIgnoreCase
(String o1, String o2) Checks strings for equality null-safe and case ignore.static boolean
equalsIgnoreCase
(String o1, String o2, boolean trim) Checks strings for equality null-safe and case ignore.static void
errorStackTrace
(Logger log) Dumps the stacktrace in ERROR mode.static String
Generates a random string of length 10 withALPHA_NUM_SPECIAL_CHARS
.static String
generateRandomString
(int length) Generates a random string withALPHA_NUM_SPECIAL_CHARS
.static String
generateRandomString
(String allowedChars) Generates a random string of length 10.static String
generateRandomString
(String allowedChars, int length) Generates a random string.static int
Returns the URL connect timeout.static String
getOS()
Returns the OS name.static int
Returns the URL read timeout.getStackTrace
(int ignoreLines) Returns the current stacktrace.static long
Returns the current time as UNIX timestamp.static long
getUnixTimestamp
(long time) Returns the given Java time as UNIX timestamp.static long
getUnixTimestamp
(Date date) Returns the given date as UNIX timestamp.static void
infoStackTrace
(Logger log) Dumps the stacktrace in INFO mode.static boolean
isAllowedTrimmingChar
(char c) Returns true when the given character shall be kept when trimming a string.static boolean
isCompatibleVersion
(String minVersion, String maxVersion, String version) Returns true if version is in range of minVersion and maxVersion.static boolean
Checks validity of an email address.static boolean
Returns true when the given string is null or - when trimmed - empty.static boolean
Returns true when the given string is null empty.static boolean
isMac()
Tells whether runtime is a Mac system.static boolean
Tells whether runtime is a Windows system.static boolean
isUnix()
Tells whether runtime is a Unix system.static boolean
Tells whether runtime is a Windows system.static <T> Iterable<T>
Returns an iterable for the given iterator.static String
Makes a join of an object array.static String
Makes a join of an object array.static String
Makes a join of an object array.static String
Makes a join of a string array.static String
Makes a join of a string array.static String
Makes a join of a string array.static String
join
(String separator, Collection<?> parts) Makes a join of a collection.static String
join
(String separator, Collection<?> parts, int startIndex) Makes a join of a collection.static String
join
(String separator, Collection<?> parts, int startIndex, int endIndex) Makes a join of a collection.static String
loadContent
(File f) Loads the content of a file as a string.static String
loadContent
(File f, Charset charset) Loads the content of a file as a string.static String
Loads the content of a stream as a string.static String
loadContent
(InputStream in, Charset charset) Loads the content of a stream as a string.static String
loadContent
(Reader reader) Loads the content of a reader as a string.static String
loadContent
(String name) Loads the content of a file as a string.static String
loadContent
(String name, Charset charset) Loads the content of a file as a string.static String
loadContent
(URI uri) Loads the content of the URI as a string.static String
loadContent
(URI uri, Charset charset) Loads the content of the URI as a string.static String
loadContent
(URL url) Loads the content of the URL as a string.static String
loadContent
(URLConnection con, Charset charset) Loads the content of the URL as a string.static String
loadContent
(URL url, Charset charset) Loads the content of the URL as a string.static Properties
loadProperties
(File file) Loads a property file.static Properties
loadProperties
(String file) Loads a property file.static Properties
loadProperties
(URI uri) Loads a property file.static Properties
loadProperties
(URL url) Loads a property file.static void
loadProperties
(Properties props, File file) Loads a property file.static void
loadProperties
(Properties props, InputStream inputStream) Loads a property file.static void
loadProperties
(Properties props, String file) Loads a property file.static void
loadProperties
(Properties props, URI uri) Loads a property file.static void
loadProperties
(Properties props, URL url) Loads a property file.static <T> List<T>
newList
(T... elems) Creates a list from elements.static <T> Set<T>
newSet
(T... elems) Creates a set from elements.static void
printStackTrace
(PrintStream out, int ignoreLines) Dumps the stacktrace into the print stream.static String
Replaces environment variables.static String
Replaces environment variables.static String
Replaces environment and system variables.static URL
Set the anchor id for at the given URL.static void
setConnectTimeout
(int connectTimeout) Sets the URL connect timeout.static String
setMarkers
(String template, String prefix, Object valueObject) Sets markers in a template.static void
setReadTimeout
(int readTimeout) Sets the URL read timeout.static NumberFormat
Formatter for integers.static NumberFormat
Formatter for real numbers.static Collection<String>
Splits the string using comma as separation char.static <T extends Enum<T>>
Collection<T>Splits the string and returns a collection of Enum values from specified class.static <T extends Enum<T>>
Collection<T>Splits the string (by commas) and returns a collection of Enum values from specified class.static Collection<String>
split
(String s, String delim, Collection<String> defaultCollection) Splits the string using comma as separation char.static Collection<String>
split
(String s, Collection<String> defaultCollection) Splits the string using comma as separation char.static void
Dumps the stacktrace so stderr.static void
Dumps the stacktrace so stdout.static void
storeProperties
(Properties props, File file) Stores a property file.static void
storeProperties
(Properties props, String file) Stores a property file.static String
toString
(byte[] b) Generates a string presentation of the given bytes.static String
toString
(float amount) Formats the money value.static String
Generates a string presentation of the given objects.static String
Formats the string for display.static void
traceStackTrace
(Logger log) Dumps the stacktrace in TRACE mode.static String
Trims the string by removing whitespaces and newlines from begin and end of the string.static void
writeContent
(File f, String content) Writes the string to a file.static void
writeContent
(File f, String content, Charset charset) Writes the string to a file.static void
writeContent
(OutputStream out, String content) Writes the string to a stream.static void
writeContent
(OutputStream out, String content, Charset charset) Writes the string to a stream.static void
writeContent
(Writer writer, String content) Writes the string to a writer.static void
writeContent
(String name, String content) Writes the string to a file.static void
writeContent
(String name, String content, 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) -
ALPHA_CHARS
alpha chars (uper and lower case letters)- See Also:
-
NUM_CHARS
numeric chars (0-9)- See Also:
-
SPECIAL_CHARS
special chars (!\"&/()=?;*+'#;,:._-<>
)- See Also:
-
ALPHA_NUM_CHARS
alpha and numeric chars- See Also:
-
ALPHA_NUM_SPECIAL_CHARS
alpha and numeric and special chars- See Also:
-
-
Constructor Details
-
CommonUtils
public CommonUtils()
-
-
Method Details
-
DATE_FORMATTER
The formatter for dates (seeDateFormat.SHORT
).- Returns:
- the formatter
-
DATE_TIME_FORMATTER
The formatter for dates incl. times (seeDateFormat.SHORT
).- Returns:
- the formatter
-
SIMPLE_NUMBER_FORMATTER
Formatter for real numbers.- Returns:
- the formatter
-
SIMPLE_INT_FORMATTER
Formatter for integers.- Returns:
- the formatter
-
toString
Formats the string for display.- Parameters:
o
- the category- Returns:
- string display
-
toString
Formats the money value.- Parameters:
amount
- amount to be formatted- Returns:
- formatted string
-
toString
Generates a string presentation of the given bytes.- Parameters:
b
- byte array- Returns:
- string representation (Hex)
-
toString
Generates a string presentation of the given objects.- Parameters:
o
- object array- Returns:
- string representation
-
equals
Checks for equality null-safe.- Parameters:
o1
- object 1o2
- object 2- Returns:
- true when both values are equal
-
equalsIgnoreCase
Checks strings for equality null-safe and case ignore.Strings will not be trimmed before test.
- Parameters:
o1
- string 1o2
- string 2- Returns:
- true when both values are equal
-
equalsIgnoreCase
Checks strings for equality null-safe and case ignore.- Parameters:
o1
- string 1o2
- string 2trim
- whether to trim strings before comparison- Returns:
- true when both values are equal
-
isEmpty
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
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
-
trim
Trims the string by removing whitespaces and newlines from begin and end of the string.- Parameters:
s
- - the string to trim- Returns:
- the trimmed string (
null
if input wasnull
) - Since:
- 3.1.0
-
isAllowedTrimmingChar
public static boolean isAllowedTrimmingChar(char c) Returns true when the given character shall be kept when trimming a string.- Parameters:
c
- - character to check- Returns:
- true when character is allowed
- Since:
- 3.1.0
-
isCompatibleVersion
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
Compares software versions.- Parameters:
v1
- - version 1v2
- - version 2- Returns:
- -1 if v1 < v2, 1 if v1 > v2, 0 if v1 = v2
-
compareVersion
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
Makes a join of a collection.- Parameters:
separator
- - the string to be used inbetween partsparts
- - the collection to join- Returns:
- the joined string
-
join
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
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
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
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
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
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
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
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
-
split
Splits the string using comma as separation char.- Parameters:
s
- - the string to split- Returns:
- collection of separated entries
- Since:
- 3.1.0
-
split
Splits the string using comma as separation char.- Parameters:
s
- - the string to splitdefaultCollection
- - the default collection when input is empty.- Returns:
- collection of separated entries or the default collection
- Since:
- 3.1.0
-
split
public static Collection<String> split(String s, String delim, Collection<String> defaultCollection) Splits the string using comma as separation char.- Parameters:
s
- - the string to splitdelim
- - the delimiter characterdefaultCollection
- - the default collection when input is empty.- Returns:
- collection of separated entries or the default collection
- Since:
- 3.1.0
-
split
Splits the string and returns a collection of Enum values from specified class.Useful to convert a string into a collection of enum values.
- Type Parameters:
T
- - the Enum type- Parameters:
s
- - the string to splitenumClass
- - the Enum class- Returns:
- the list of Enum values
- Since:
- 3.1.0
-
split
Splits the string (by commas) and returns a collection of Enum values from specified class.Useful to convert a string into a collection of enum values.
- Type Parameters:
T
- - the Enum type- Parameters:
s
- - the string to splitdelim
- - the delimiter to split uponenumClass
- - the Enum class- Returns:
- the list of Enum values
- Since:
- 3.1.0
-
newList
Creates a list from elements.- Type Parameters:
T
- - the element type- Parameters:
elems
- - the elements- Returns:
- new
List
of elements - Since:
- 3.1.0
-
newSet
Creates a set from elements.- Type Parameters:
T
- - the element type- Parameters:
elems
- - the elements- Returns:
- new
Set
of elements - Since:
- 3.1.0
-
debugObject
Recursively debugs objects.- Parameters:
o
- object to debug- Returns:
- the debug string
- Since:
- 1.2.3
-
debugObject
Recursively debugs objects and adds this in the string buffer.- Parameters:
s
- string buffer to enhanceo
- object to debug
-
debugObject
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
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
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
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
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
Loads a property file.The URI resource is in a simple line-oriented format as specified in
Properties.load(Reader)
and is assumed to use the ISO 8859-1 character encoding; that is each byte is one Latin1 character. Characters not in Latin1, and certain special characters, are represented in keys and elements using Unicode escapes as defined in section 3.3 of The Java Language Specification.- Parameters:
uri
- the URI to load from- Returns:
- the properties
- Throws:
IOException
- when file cannot be loaded
-
loadProperties
Loads a property file.The URL resource is in a simple line-oriented format as specified in
Properties.load(Reader)
and is assumed to use the ISO 8859-1 character encoding; that is each byte is one Latin1 character. Characters not in Latin1, and certain special characters, are represented in keys and elements using Unicode escapes as defined in section 3.3 of The Java Language Specification.- Parameters:
url
- the URL to load from- Returns:
- the properties
- Throws:
IOException
- when file cannot be loaded
-
loadProperties
Loads a property file.The File resource is in a simple line-oriented format as specified in
Properties.load(Reader)
and is assumed to use the ISO 8859-1 character encoding; that is each byte is one Latin1 character. Characters not in Latin1, and certain special characters, are represented in keys and elements using Unicode escapes as defined in section 3.3 of The Java Language Specification.- Parameters:
file
- the file to load- Returns:
- the properties
- Throws:
IOException
- when file cannot be loaded
-
loadProperties
Loads a property file.The file resource is in a simple line-oriented format as specified in
Properties.load(Reader)
and is assumed to use the ISO 8859-1 character encoding; that is each byte is one Latin1 character. Characters not in Latin1, and certain special characters, are represented in keys and elements using Unicode escapes as defined in section 3.3 of The Java Language Specification.- Parameters:
file
- the file to load- Returns:
- the properties
- Throws:
IOException
- when file cannot be loaded
-
loadProperties
Loads a property file.The File resource is in a simple line-oriented format as specified in
Properties.load(Reader)
and is assumed to use the ISO 8859-1 character encoding; that is each byte is one Latin1 character. Characters not in Latin1, and certain special characters, are represented in keys and elements using Unicode escapes as defined in section 3.3 of The Java Language Specification.- Parameters:
props
- the properties objectfile
- the file to load- Throws:
IOException
- when file cannot be loaded
-
loadProperties
Loads a property file.The URI resource is in a simple line-oriented format as specified in
Properties.load(Reader)
and is assumed to use the ISO 8859-1 character encoding; that is each byte is one Latin1 character. Characters not in Latin1, and certain special characters, are represented in keys and elements using Unicode escapes as defined in section 3.3 of The Java Language Specification.- Parameters:
props
- the properties objecturi
- the uri to load- Throws:
IOException
- when file cannot be loaded
-
loadProperties
Loads a property file.The URL resource is in a simple line-oriented format as specified in
Properties.load(Reader)
and is assumed to use the ISO 8859-1 character encoding; that is each byte is one Latin1 character. Characters not in Latin1, and certain special characters, are represented in keys and elements using Unicode escapes as defined in section 3.3 of The Java Language Specification.- Parameters:
props
- the properties objecturl
- the url to load- Throws:
IOException
- when file cannot be loaded
-
loadProperties
Loads a property file.The input stream is in a simple line-oriented format as specified in
Properties.load(Reader)
and is assumed to use the ISO 8859-1 character encoding; that is each byte is one Latin1 character. Characters not in Latin1, and certain special characters, are represented in keys and elements using Unicode escapes as defined in section 3.3 of The Java Language Specification.- Parameters:
props
- the properties objectinputStream
- the stream to load from- Throws:
IOException
- when file cannot be loaded
-
loadProperties
Loads a property file.The file resource is in a simple line-oriented format as specified in
Properties.load(Reader)
and is assumed to use the ISO 8859-1 character encoding; that is each byte is one Latin1 character. Characters not in Latin1, and certain special characters, are represented in keys and elements using Unicode escapes as defined in section 3.3 of The Java Language Specification.- Parameters:
props
- the properties objectfile
- the file to load- Throws:
IOException
- when file cannot be loaded
-
storeProperties
Stores a property file.- Parameters:
props
- the properties objectfile
- the file to load- Throws:
IOException
- when file cannot be stored
-
storeProperties
Stores a property file.- Parameters:
props
- the properties objectfile
- the file to load- Throws:
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
Loads the content of the URI as a string.- Parameters:
uri
- URI to be loaded- Returns:
- the content of the URI
- Throws:
IOException
- when content of URI cannot be loaded
-
loadContent
Loads the content of the URI as a string.- Parameters:
uri
- URI to be loadedcharset
- the charset of the content (null
fordefault charset
)- Returns:
- the content of the URI
- Throws:
IOException
- when content of URI cannot be loaded
-
loadContent
Loads the content of the URL as a string.- Parameters:
url
- URL to be loaded- Returns:
- the content of the URL
- Throws:
IOException
- when content of URL cannot be loaded
-
loadContent
Loads the content of the URL as a string.- Parameters:
url
- URL to be loadedcharset
- the charset of the content (null
fordefault charset
)- Returns:
- the content of the URL
- Throws:
IOException
- when content of URL cannot be loaded
-
loadContent
Loads the content of the URL as a string.- Parameters:
con
- URL connection to be usedcharset
- the charset of the content (null
fordefault charset
)- Returns:
- the content of the URL
- Throws:
IOException
- when content of URL cannot be loaded
-
loadContent
Loads the content of a file as a string.- Parameters:
name
- name of file to be loaded- Returns:
- the content of the file
- Throws:
IOException
- when content of file cannot be loaded
-
loadContent
Loads the content of a file as a string.- Parameters:
name
- name of file to be loadedcharset
- the charset of the content (null
fordefault charset
)- Returns:
- the content of the file
- Throws:
IOException
- when content of file cannot be loaded
-
loadContent
Loads the content of a file as a string.- Parameters:
f
- file to be loaded- Returns:
- the content of the file
- Throws:
IOException
- when content of file cannot be loaded
-
loadContent
Loads the content of a file as a string.- Parameters:
f
- file to be loadedcharset
- the charset of the content (null
fordefault charset
)- Returns:
- the content of the file
- Throws:
IOException
- when content of file cannot be loaded
-
loadContent
Loads the content of a stream as a string.- Parameters:
in
- stream to be loaded- Returns:
- the content of the stream
- Throws:
IOException
- when content of stream cannot be loaded
-
loadContent
Loads the content of a stream as a string.- Parameters:
in
- stream to be loadedcharset
- the charset of the content (null
fordefault charset
)- Returns:
- the content of the stream
- Throws:
IOException
- when content of stream cannot be loaded
-
loadContent
Loads the content of a reader as a string.- Parameters:
reader
- reader to be loaded- Returns:
- the content of the reader
- Throws:
IOException
- when content of reader cannot be loaded
-
writeContent
Writes the string to a file.- Parameters:
name
- name of file to be written tocontent
- the content to be written- Throws:
IOException
- when content cannot be written
-
writeContent
Writes the string to a file.- Parameters:
name
- name of file to be written tocontent
- the content to be writtencharset
- the charset of the content (null
fordefault charset
)- Throws:
IOException
- when content cannot be written
-
writeContent
Writes the string to a file.- Parameters:
f
- file to be written tocontent
- the content to be written- Throws:
IOException
- when content cannot be written
-
writeContent
Writes the string to a file.- Parameters:
f
- file to be written tocontent
- the content to be writtencharset
- the charset of the content (null
fordefault charset
)- Throws:
IOException
- when content cannot be written
-
writeContent
Writes the string to a stream.- Parameters:
out
- stream to be written tocontent
- the content to be written- Throws:
IOException
- when content cannot be written
-
writeContent
public static void writeContent(OutputStream out, String content, Charset charset) throws IOException Writes the string to a stream.- Parameters:
out
- stream to be written tocontent
- the content to be writtencharset
- the charset of the content (null
fordefault charset
)- Throws:
IOException
- when content cannot be written
-
writeContent
Writes the string to a writer.- Parameters:
writer
- writer to be written tocontent
- the content to be written- Throws:
IOException
- when content cannot be written
-
isWindows
public static boolean isWindows()Tells whether runtime is a Windows system.- Returns:
true
when OS is a Windows system
-
isMac
public static boolean isMac()Tells whether runtime is a Mac system.- Returns:
true
when OS is a Mac system
-
isUnix
public static boolean isUnix()Tells whether runtime is a Unix system.- Returns:
true
when OS is a Unix system
-
isSolaris
public static boolean isSolaris()Tells whether runtime is a Windows system.- Returns:
true
when OS is a Windows system
-
isEmail
Checks validity of an email address.- Parameters:
s
- the string to be checked- Returns:
true
when string is a valid email address- Since:
- 1.2.9
-
getOS
Returns the OS name.- Returns:
- the OS name as returned by
System.getProperty("os.name")
-
setAnchor
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
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
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
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
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
-
generateRandomString
Generates a random string of length 10 withALPHA_NUM_SPECIAL_CHARS
.- Returns:
- the generated random string
- Since:
- 4.0.2
-
generateRandomString
Generates a random string withALPHA_NUM_SPECIAL_CHARS
.- Parameters:
length
- - length of string (using 10 if less than 1)- Returns:
- the generated random string
- Since:
- 4.0.2
-
generateRandomString
Generates a random string of length 10.- Parameters:
allowedChars
- - allowed chars (usingALPHA_NUM_SPECIAL_CHARS
whennull
)- Returns:
- the generated random string
- Since:
- 4.0.2
-
generateRandomString
Generates a random string.- Parameters:
allowedChars
- - allowed chars (usingALPHA_NUM_SPECIAL_CHARS
whennull
)length
- - length of string (using 10 if less than 1)- Returns:
- the generated random string
- Since:
- 4.0.2
-