Class SystemPropertyUtil


  • public final class SystemPropertyUtil
    extends java.lang.Object
    A collection of utility methods to retrieve and parse the values of the Java system properties.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  SystemPropertyUtil.Platform
      Inspired from http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/ SystemUtils.html
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String FILE_ENCODING
      Default File encoding field
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clear​(java.lang.String key)
      Remove the key of the Java system property with the specified key.
      static boolean contains​(java.lang.String key)
      Returns true if and only if the system property with the specified key exists.
      static void debug​(java.io.PrintStream out)
      Print to System.out the content of the properties
      static java.lang.String get​(java.lang.String key)
      Returns the value of the Java system property with the specified key, while falling back to null if the property access fails.
      static boolean get​(java.lang.String key, boolean def)
      Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
      static int get​(java.lang.String key, int def)
      Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
      static long get​(java.lang.String key, long def)
      Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
      static java.lang.String get​(java.lang.String key, java.lang.String def)
      Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
      static boolean getAndSet​(java.lang.String key, boolean def)
      Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
      static int getAndSet​(java.lang.String key, int def)
      Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
      static long getAndSet​(java.lang.String key, long def)
      Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
      static java.lang.String getAndSet​(java.lang.String key, java.lang.String def)
      Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
      static java.lang.String getNoCheck​(java.lang.String key)
      Returns the value of the Java system property with the specified key, while falling back to null if the property access fails.
      static SystemPropertyUtil.Platform getOS()  
      static boolean isFileEncodingCorrect()  
      static boolean isMac()  
      static boolean isSolaris()  
      static boolean isUnix()  
      static boolean isWindows()  
      static void refresh()
      Re-retrieves all system properties so that any post-launch properties updates are retrieved.
      static boolean set​(java.lang.String key, boolean def)
      Set the value of the Java system property with the specified key to the specified default value.
      static int set​(java.lang.String key, int def)
      Set the value of the Java system property with the specified key to the specified default value.
      static long set​(java.lang.String key, long def)
      Set the value of the Java system property with the specified key to the specified default value.
      static java.lang.String set​(java.lang.String key, java.lang.String def)
      Set the value of the Java system property with the specified key to the specified default value.
      • Methods inherited from class java.lang.Object

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

      • FILE_ENCODING

        public static final java.lang.String FILE_ENCODING
        Default File encoding field
        See Also:
        Constant Field Values
    • Method Detail

      • refresh

        public static void refresh()
        Re-retrieves all system properties so that any post-launch properties updates are retrieved.
      • isFileEncodingCorrect

        public static boolean isFileEncodingCorrect()
        Returns:
        True if Encoding is Correct
      • contains

        public static final boolean contains​(java.lang.String key)
        Returns true if and only if the system property with the specified key exists.
        Parameters:
        key - as String to verify
        Returns:
        True if the key is contained
        Throws:
        java.lang.IllegalArgumentException - key null
      • get

        public static final java.lang.String get​(java.lang.String key)
        Returns the value of the Java system property with the specified key, while falling back to null if the property access fails.
        Parameters:
        key - of system property to get
        Returns:
        the property value or null
        Throws:
        java.lang.IllegalArgumentException - key null
      • getNoCheck

        public static final java.lang.String getNoCheck​(java.lang.String key)
        Returns the value of the Java system property with the specified key, while falling back to null if the property access fails.
        Parameters:
        key - of system property to get
        Returns:
        the property value or null
        Throws:
        java.lang.IllegalArgumentException - key null
      • get

        public static final java.lang.String get​(java.lang.String key,
                                                 java.lang.String def)
        Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
        Parameters:
        key - of system property
        def - the default value
        Returns:
        the property value. def if there's no such property or if an access to the specified property is not allowed.
        Throws:
        java.lang.IllegalArgumentException - key null
      • get

        public static boolean get​(java.lang.String key,
                                  boolean def)
        Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
        Parameters:
        key - of system property
        def - the default value
        Returns:
        the property value. def if there's no such property or if an access to the specified property is not allowed.
        Throws:
        java.lang.IllegalArgumentException - key null
      • get

        public static int get​(java.lang.String key,
                              int def)
        Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
        Parameters:
        key - the system property
        def - the default value
        Returns:
        the property value. def if there's no such property or if an access to the specified property is not allowed.
        Throws:
        java.lang.IllegalArgumentException - key null
      • get

        public static long get​(java.lang.String key,
                               long def)
        Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
        Parameters:
        key - of system property
        def - the default value
        Returns:
        the property value. def if there's no such property or if an access to the specified property is not allowed.
        Throws:
        java.lang.IllegalArgumentException - key null
      • getAndSet

        public static java.lang.String getAndSet​(java.lang.String key,
                                                 java.lang.String def)
        Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
        Parameters:
        key - of system property
        def - the default value
        Returns:
        the property value. def if there's no such property or if an access to the specified property is not allowed.
        Throws:
        java.lang.IllegalArgumentException - key or def null
      • getAndSet

        public static boolean getAndSet​(java.lang.String key,
                                        boolean def)
        Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
        Parameters:
        key - of system property
        def - the default value
        Returns:
        the property value. def if there's no such property or if an access to the specified property is not allowed.
        Throws:
        java.lang.IllegalArgumentException - key null
      • getAndSet

        public static int getAndSet​(java.lang.String key,
                                    int def)
        Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
        Parameters:
        key - of system property
        def - the default value
        Returns:
        the property value. def if there's no such property or if an access to the specified property is not allowed.
        Throws:
        java.lang.IllegalArgumentException - key null
      • getAndSet

        public static long getAndSet​(java.lang.String key,
                                     long def)
        Returns the value of the Java system property with the specified key, while falling back to the specified default value if the property access fails.
        Parameters:
        key - of system property
        def - the default value
        Returns:
        the property value. def if there's no such property or if an access to the specified property is not allowed.
        Throws:
        java.lang.IllegalArgumentException - key null
      • set

        public static java.lang.String set​(java.lang.String key,
                                           java.lang.String def)
        Set the value of the Java system property with the specified key to the specified default value.
        Parameters:
        key - of system property
        def - the default value
        Returns:
        the ancient value.
        Throws:
        java.lang.IllegalArgumentException - key or def null
      • set

        public static boolean set​(java.lang.String key,
                                  boolean def)
        Set the value of the Java system property with the specified key to the specified default value.
        Parameters:
        key - of system property
        def - the default value
        Returns:
        the ancient value.
        Throws:
        java.lang.IllegalArgumentException - key null
      • set

        public static int set​(java.lang.String key,
                              int def)
        Set the value of the Java system property with the specified key to the specified default value.
        Parameters:
        key - of system property
        def - the default value
        Returns:
        the ancient value.
        Throws:
        java.lang.IllegalArgumentException - key null
      • set

        public static long set​(java.lang.String key,
                               long def)
        Set the value of the Java system property with the specified key to the specified default value.
        Parameters:
        key - of system property
        def - the default value
        Returns:
        the ancient value.
        Throws:
        java.lang.IllegalArgumentException - key null
      • clear

        public static void clear​(java.lang.String key)
        Remove the key of the Java system property with the specified key.
        Parameters:
        key - of system property
        Throws:
        java.lang.IllegalArgumentException - key null
      • debug

        public static void debug​(java.io.PrintStream out)
        Print to System.out the content of the properties
        Parameters:
        out - the output stream to be used
        Throws:
        java.lang.IllegalArgumentException - out null
      • isWindows

        public static boolean isWindows()
        Returns:
        True if Windows
      • isMac

        public static boolean isMac()
        Returns:
        True if Mac
      • isUnix

        public static boolean isUnix()
        Returns:
        True if Unix
      • isSolaris

        public static boolean isSolaris()
        Returns:
        True if Solaris