Class SystemUtils


  • class SystemUtils
    extends java.lang.Object
    Contains several OS-specific methods from Commons-Lang3's SystemUtils. We don't want to use that class because it uses enums for Java versions, which implies that with every new Java version a new commons-lang3 is required.
    Since:
    3.0.1
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean IS_OS_AIX
      Is true if this is AIX.
      static boolean IS_OS_MAC_OSX
      Is true if this is Mac.
      static boolean IS_OS_WINDOWS
      Is true if this is Windows.
      private static java.lang.String JAVA_HOME_KEY
      The System property key for the Java home directory.
      static java.lang.String LINE_SEPARATOR
      The line.separator System Property.
      static java.lang.String OS_NAME
      The os.name System Property.
      private static java.lang.String OS_NAME_WINDOWS_PREFIX
      The prefix String for all Windows OS.
    • Constructor Summary

      Constructors 
      Constructor Description
      SystemUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.File getJavaHome()
      Gets the Java home directory as a File.
      private static boolean getOSMatchesName​(java.lang.String osNamePrefix)
      Decides if the operating system matches.
      private static java.lang.String getSystemProperty​(java.lang.String property)
      Gets a System property, defaulting to null if the property cannot be read.
      (package private) static boolean isOSNameMatch​(java.lang.String osName, java.lang.String osNamePrefix)
      Decides if the operating system matches.
      • Methods inherited from class java.lang.Object

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

      • OS_NAME

        public static final java.lang.String OS_NAME

        The os.name System Property. Operating system name.

        Defaults to null if the runtime does not have security access to read this property or the property does not exist.

        This value is initialized when the class is loaded. If System.setProperty(String,String) or System.setProperties(java.util.Properties) is called after this class is loaded, the value will be out of sync with that System property.

        Since:
        Java 1.1
      • OS_NAME_WINDOWS_PREFIX

        private static final java.lang.String OS_NAME_WINDOWS_PREFIX
        The prefix String for all Windows OS.
        See Also:
        Constant Field Values
      • IS_OS_AIX

        public static final boolean IS_OS_AIX

        Is true if this is AIX.

        The field will return false if OS_NAME is null.

      • IS_OS_MAC_OSX

        public static final boolean IS_OS_MAC_OSX

        Is true if this is Mac.

        The field will return false if OS_NAME is null.

      • IS_OS_WINDOWS

        public static final boolean IS_OS_WINDOWS

        Is true if this is Windows.

        The field will return false if OS_NAME is null.

      • JAVA_HOME_KEY

        private static final java.lang.String JAVA_HOME_KEY
        The System property key for the Java home directory.
        See Also:
        Constant Field Values
      • LINE_SEPARATOR

        public static final java.lang.String LINE_SEPARATOR

        The line.separator System Property. Line separator ("\n" on UNIX).

        Defaults to null if the runtime does not have security access to read this property or the property does not exist.

        This value is initialized when the class is loaded. If System.setProperty(String,String) or System.setProperties(java.util.Properties) is called after this class is loaded, the value will be out of sync with that System property.

        Since:
        Java 1.1
    • Constructor Detail

      • SystemUtils

        SystemUtils()
    • Method Detail

      • getOSMatchesName

        private static boolean getOSMatchesName​(java.lang.String osNamePrefix)
        Decides if the operating system matches.
        Parameters:
        osNamePrefix - the prefix for the os name
        Returns:
        true if matches, or false if not or can't determine
      • isOSNameMatch

        static boolean isOSNameMatch​(java.lang.String osName,
                                     java.lang.String osNamePrefix)
        Decides if the operating system matches.

        This method is package private instead of private to support unit test invocation.

        Parameters:
        osName - the actual OS name
        osNamePrefix - the prefix for the expected OS name
        Returns:
        true if matches, or false if not or can't determine
      • getJavaHome

        public static java.io.File getJavaHome()

        Gets the Java home directory as a File.

        Returns:
        a directory
        Throws:
        java.lang.SecurityException - if a security manager exists and its checkPropertyAccess method doesn't allow access to the specified system property.
        Since:
        2.1
        See Also:
        System.getProperty(String)
      • getSystemProperty

        private static java.lang.String getSystemProperty​(java.lang.String property)

        Gets a System property, defaulting to null if the property cannot be read.

        If a SecurityException is caught, the return value is null and a message is written to System.err.

        Parameters:
        property - the system property name
        Returns:
        the system property value or null if a security problem occurs