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 int DEFAULT_CONNECT_TIMEOUT
    Default timeout for connecting to URLs (10sec)
    static int DEFAULT_READ_TIMEOUT
    Default timeout for reading from URLs (20sec)
  • Constructor Summary

    Constructors 
    Constructor Description
    CommonUtils()  
  • Method Summary

    Modifier and Type Method Description
    static int compareVersion​(java.lang.String[] v1, java.lang.String[] v2)
    Compares versions.
    static int compareVersion​(java.lang.String v1, java.lang.String v2)
    Compares software versions.
    static java.text.DateFormat DATE_FORMATTER()
    The formatter for dates (see DateFormat.SHORT).
    static java.text.DateFormat DATE_TIME_FORMATTER()
    The formatter for dates incl.
    static java.lang.String debugObject​(java.lang.Object o)
    Recursively debugs objects.
    static void debugObject​(java.lang.StringBuffer s, java.lang.Object o)
    Recursively debugs objects and adds this in the string buffer.
    static void debugObject​(java.lang.StringBuilder s, java.lang.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 equals​(java.lang.Object o1, java.lang.Object o2)
    Checks for equality null-safe
    static void errorStackTrace​(Logger log)
    Dumps the stacktrace in ERROR mode.
    static int getConnectTimeout()
    Returns the URL connect timeout.
    static java.lang.String getDisplay​(java.lang.Enum<?> e)
    Returns the display string for the default locale.
    static java.lang.String getDisplay​(java.lang.Enum<?> e, java.util.Locale locale)
    Returns the display string for the given locale.
    static java.lang.String getDisplay​(java.lang.Object o)
    The display of the object
    static java.lang.String getDisplay​(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.String getOS()
    Returns the OS name.
    static int getReadTimeout()
    Returns the URL read timeout.
    static java.util.List<java.lang.String> getStackTrace​(int ignoreLines)
    Returns the current stacktrace.
    static long getUnixTimestamp()
    Returns the current time as UNIX timestamp.
    static long getUnixTimestamp​(long time)
    Returns the given Java time as UNIX timestamp.
    static long getUnixTimestamp​(java.util.Date date)
    Returns the given date as UNIX timestamp.
    static long getUnixTimestamp​(RsDate date)
    Returns the given date as UNIX timestamp.
    static void infoStackTrace​(Logger log)
    Dumps the stacktrace in INFO mode.
    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.
    static boolean isEmail​(java.lang.String s)
    Checks validity of an email address.
    static boolean isEmpty​(java.lang.String s)
    Returns true when the given string is null or - when trimmed - empty.
    static boolean isEmpty​(java.lang.String s, boolean trim)
    Returns true when the given string is null empty.
    static boolean isMac()
    Tells whether runtime is a Mac system.
    static boolean isSolaris()
    Tells whether runtime is a Windows system.
    static boolean isUnix()
    Tells whether runtime is a Unix system.
    static boolean isWindows()
    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.String join​(java.lang.String separator, java.lang.Object[] parts)
    Makes a join of an object array.
    static java.lang.String join​(java.lang.String separator, java.lang.Object[] parts, int startIndex)
    Makes a join of an object array.
    static java.lang.String join​(java.lang.String separator, java.lang.Object[] parts, int startIndex, int endIndex)
    Makes a join of an object array.
    static java.lang.String join​(java.lang.String separator, java.lang.String[] parts)
    Makes a join of a string array.
    static java.lang.String join​(java.lang.String separator, java.lang.String[] parts, int startIndex)
    Makes a join of a string array.
    static java.lang.String join​(java.lang.String separator, java.lang.String[] parts, int startIndex, int endIndex)
    Makes a join of a string array.
    static java.lang.String join​(java.lang.String separator, java.util.Collection<?> parts)
    Makes a join of a collection.
    static java.lang.String join​(java.lang.String separator, java.util.Collection<?> parts, int startIndex)
    Makes a join of a collection.
    static java.lang.String join​(java.lang.String separator, java.util.Collection<?> parts, int startIndex, int endIndex)
    Makes a join of a collection.
    static java.lang.String loadContent​(java.io.File f)
    Loads the content of a file as a string.
    static java.lang.String loadContent​(java.io.File f, java.nio.charset.Charset charset)
    Loads the content of a file as a string.
    static java.lang.String loadContent​(java.io.InputStream in)
    Loads the content of a stream as a string.
    static java.lang.String loadContent​(java.io.InputStream in, java.nio.charset.Charset charset)
    Loads the content of a stream as a string.
    static java.lang.String loadContent​(java.io.Reader reader)
    Loads the content of a reader as a string.
    static java.lang.String loadContent​(java.lang.String name)
    Loads the content of a file as a string.
    static java.lang.String loadContent​(java.lang.String name, java.nio.charset.Charset charset)
    Loads the content of a file as a string.
    static java.lang.String loadContent​(java.net.URL url)
    Loads the content of the URL as a string.
    static java.lang.String loadContent​(java.net.URLConnection con, java.nio.charset.Charset charset)
    Loads the content of the URL as a string.
    static java.lang.String loadContent​(java.net.URL url, java.nio.charset.Charset charset)
    Loads the content of the URL as a string.
    static java.util.Properties loadProperties​(java.io.File file)
    Loads a property file.
    static java.util.Properties loadProperties​(java.lang.String file)
    Loads a property file.
    static void loadProperties​(java.util.Properties props, java.io.File file)
    Loads a property file.
    static void loadProperties​(java.util.Properties props, java.lang.String file)
    Loads a property file.
    static void printStackTrace​(java.io.PrintStream out, int ignoreLines)
    Dumps the stacktrace into the print stream.
    static java.lang.String replaceEnvVariables​(java.lang.String s)
    Replaces environment variables.
    static java.lang.String replaceRuntimeVariables​(java.lang.String s)
    Replaces environment variables.
    static java.lang.String replaceVariables​(java.lang.String s)
    Replaces environment and system variables.
    static java.net.URL setAnchor​(java.net.URL url, java.lang.String anchor)
    Set the anchor id for at the given URL.
    static void setConnectTimeout​(int connectTimeout)
    Sets the URL connect timeout.
    static java.lang.String setMarkers​(java.lang.String template, java.lang.String prefix, java.lang.Object valueObject)
    Sets markers in a template.
    static void setReadTimeout​(int readTimeout)
    Sets the URL read timeout.
    static java.text.NumberFormat SIMPLE_INT_FORMATTER()
    Formatter for integers.
    static java.text.NumberFormat SIMPLE_NUMBER_FORMATTER()
    Formatter for real numbers.
    static void stderrStackTrace()
    Dumps the stacktrace so stderr.
    static void stdoutStackTrace()
    Dumps the stacktrace so stdout.
    static void storeProperties​(java.util.Properties props, java.io.File file)
    Stores a property file.
    static void storeProperties​(java.util.Properties props, java.lang.String file)
    Stores a property file.
    static java.lang.String toString​(byte[] b)
    Generates a string presentation of the given bytes.
    static java.lang.String toString​(float amount)
    Formats the money value.
    static java.lang.String toString​(java.lang.Object[] o)
    Generates a string presentation of the given objects.
    static java.lang.String toString​(java.lang.String o)
    Formats the string for display.
    static java.lang.String toString​(RsDate date)
    Formats the given date.
    static java.lang.String toString​(RsDay day)
    Formats the given day.
    static java.lang.String toString​(RsMonth month)
    Formats the given month (1st day of month).
    static java.lang.String toString​(RsYear year)
    Formats the given year.
    static void traceStackTrace​(Logger log)
    Dumps the stacktrace in TRACE mode.
    static void writeContent​(java.io.File f, java.lang.String content)
    Writes the string to a file.
    static void writeContent​(java.io.File f, java.lang.String content, java.nio.charset.Charset charset)
    Writes the string to a file.
    static void writeContent​(java.io.OutputStream out, java.lang.String content)
    Writes the string to a stream.
    static void writeContent​(java.io.OutputStream out, java.lang.String content, java.nio.charset.Charset charset)
    Writes the string to a stream.
    static void writeContent​(java.io.Writer writer, java.lang.String content)
    Writes the string to a writer.
    static void writeContent​(java.lang.String name, java.lang.String content)
    Writes the string to a file.
    static void writeContent​(java.lang.String name, java.lang.String content, java.nio.charset.Charset charset)
    Writes the string to a file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_CONNECT_TIMEOUT

      public static int DEFAULT_CONNECT_TIMEOUT
      Default timeout for connecting to URLs (10sec)
    • DEFAULT_READ_TIMEOUT

      public static int DEFAULT_READ_TIMEOUT
      Default timeout for reading from URLs (20sec)
  • Constructor Details

  • Method Details

    • DATE_FORMATTER

      public static java.text.DateFormat DATE_FORMATTER()
      The formatter for dates (see DateFormat.SHORT).
      Returns:
      the formatter
    • DATE_TIME_FORMATTER

      public static java.text.DateFormat DATE_TIME_FORMATTER()
      The formatter for dates incl. times (see DateFormat.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

      public static java.lang.String toString​(RsDate date)
      Formats the given date.
      Parameters:
      date - date to format
      Returns:
      the formatted string (see DATE_TIME_FORMATTER())
    • toString

      public static java.lang.String toString​(RsDay day)
      Formats the given day.
      Parameters:
      day - day to format
      Returns:
      the formatted string (see DATE_FORMATTER())
    • toString

      public static java.lang.String toString​(RsYear year)
      Formats the given year.
      Parameters:
      year - year to format
      Returns:
      the formatted string
    • toString

      public static java.lang.String toString​(RsMonth month)
      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 1
      o2 - 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 checked
      trim - 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 class
      locale - 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 value
      locale - 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 class
      display - 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 class
      display - display of enum
      locale - 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 1
      v2 - - 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 parts
      v2 - - 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 parts
      parts - - 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 parts
      parts - - 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 parts
      parts - - 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 parts
      parts - - the parts to join
      startIndex - - 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 parts
      parts - - the collection to join
      startIndex - - 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 parts
      parts - - the parts to join
      startIndex - - 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 parts
      parts - - the parts to join
      startIndex - - 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 parts
      parts - - the parts to join
      startIndex - - 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 parts
      parts - - the collection to join
      startIndex - - 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 enhance
      o - 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 enhance
      o - 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

      public static long getUnixTimestamp​(RsDate 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

      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 used
      ignoreLines - the number of lines to be ignored at top of trace
    • errorStackTrace

      public static void errorStackTrace​(Logger log)
      Dumps the stacktrace in ERROR mode.
      Parameters:
      log - the logger to be used
    • infoStackTrace

      public static void infoStackTrace​(Logger log)
      Dumps the stacktrace in INFO mode.
      Parameters:
      log - the logger to be used
    • debugStackTrace

      public static void debugStackTrace​(Logger log)
      Dumps the stacktrace in DEBUG mode.
      Parameters:
      log - the logger to be used
    • traceStackTrace

      public static void traceStackTrace​(Logger log)
      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.IOException
      Loads 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.IOException
      Loads 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.IOException
      Loads a property file.
      Parameters:
      props - the properties object
      file - 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.IOException
      Loads a property file.
      Parameters:
      props - the properties object
      file - 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.IOException
      Stores a property file.
      Parameters:
      props - the properties object
      file - 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.IOException
      Stores a property file.
      Parameters:
      props - the properties object
      file - 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.IOException
      Loads 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.IOException
      Loads the content of the URL as a string.
      Parameters:
      url - URL to be loaded
      charset - the charset of the content (null for default 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.IOException
      Loads the content of the URL as a string.
      Parameters:
      con - URL connection to be used
      charset - the charset of the content (null for default 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.IOException
      Loads 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.IOException
      Loads the content of a file as a string.
      Parameters:
      name - name of file to be loaded
      charset - the charset of the content (null for default 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.IOException
      Loads 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.IOException
      Loads the content of a file as a string.
      Parameters:
      f - file to be loaded
      charset - the charset of the content (null for default 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.IOException
      Loads 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.IOException
      Loads the content of a stream as a string.
      Parameters:
      in - stream to be loaded
      charset - the charset of the content (null for default 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.IOException
      Loads 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.IOException
      Writes the string to a file.
      Parameters:
      name - name of file to be written to
      content - 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.IOException
      Writes the string to a file.
      Parameters:
      name - name of file to be written to
      content - the content to be written
      charset - the charset of the content (null for default 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.IOException
      Writes the string to a file.
      Parameters:
      f - file to be written to
      content - 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.IOException
      Writes the string to a file.
      Parameters:
      f - file to be written to
      content - the content to be written
      charset - the charset of the content (null for default 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.IOException
      Writes the string to a stream.
      Parameters:
      out - stream to be written to
      content - 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.IOException
      Writes the string to a stream.
      Parameters:
      out - stream to be written to
      content - the content to be written
      charset - the charset of the content (null for default 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.IOException
      Writes the string to a writer.
      Parameters:
      writer - writer to be written to
      content - 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:
      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

      public static boolean isEmail​(java.lang.String s)
      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

      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 detects IDisplayable, IDisplayProvider and NamedObject.
      Parameters:
      o - the object to be displayed
      locale - Locale to be used for IDisplayable
      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 modified
      anchor - 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 template
      prefix - the marker prefix
      valueObject - the object that contains values
      Returns:
      the template with markers replaced