Class OsUtils

java.lang.Object
de.iip_ecosphere.platform.support.OsUtils

public class OsUtils extends Object
Access to static operating system level information.
Author:
Holger Eichelberger, SSE
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The System property key for the Java home directory.
    static final String
    The System property key for the user home directory.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Preventing external creation.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    getBooleanPropertyOrEnv(String key, boolean dflt)
    Returns a boolean value from the system properties or system environment, either as given or all in capital characters with dots replaced by underscores.
    static String
    Returns a value from the system environment, either as given or all in capital characters with dots replaced by underscores.
    static File
    Gets the Java home directory as a File.
    static String
    The Java Runtime Environment specification version.
    static final int
    Returns the number of CPU cores.
    static final String
    Returns the operating system architecture.
    static final String
    Returns the operating system name.
    static String
    Returns a value from the system properties or system environment, either as given or all in capital characters with dots replaced by underscores.
    static String
    Returns a value from the system properties or system environment, either as given or all in capital characters with dots replaced by underscores.
    static final String
    Returns the user.home System Property.
    static boolean
    Returns whether we are running on Java 9 or newer.
    static boolean
    Returns whether we are running on Java 1.8.
    static boolean
    Returns whether we are running on Linux.
    static boolean
    Returns whether we are running on Mac.
    static boolean
    Returns whether we are running on Unix.
    static boolean
    Returns whether we are running on windows.

    Methods inherited from class java.lang.Object

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

    • PROP_JAVA_HOME

      public static final String PROP_JAVA_HOME
      The System property key for the Java home directory.
      See Also:
    • PROP_USER_HOME

      public static final String PROP_USER_HOME
      The System property key for the user home directory.
      See Also:
  • Constructor Details

    • OsUtils

      private OsUtils()
      Preventing external creation.
  • Method Details

    • getUserHome

      public static final String getUserHome()
      Returns the user.home System Property. User's home directory.
    • getOsName

      public static final String getOsName()
      Returns the operating system name.
      Returns:
      the operating system name
    • getJavaHome

      public static File getJavaHome()
      Gets the Java home directory as a File.
      Returns:
      a directory
      Throws:
      SecurityException - if a security manager exists and its checkPropertyAccess method doesn't allow access to the specified system property.
    • getJavaSpecificationVersion

      public static String getJavaSpecificationVersion()
      The Java Runtime Environment specification version.
    • getOsArch

      public static final String getOsArch()
      Returns the operating system architecture.
      Returns:
      the operating system architecture.
    • getNumCpuCores

      public static final int getNumCpuCores()
      Returns the number of CPU cores.
      Returns:
      the number of CPU cores
    • getEnv

      public static String getEnv(String key)
      Returns a value from the system environment, either as given or all in capital characters with dots replaced by underscores.
      Parameters:
      key - the key to look for
      Returns:
      the value, may by null for none
    • getPropertyOrEnv

      public static String getPropertyOrEnv(String key, String dflt)
      Returns a value from the system properties or system environment, either as given or all in capital characters with dots replaced by underscores.
      Parameters:
      key - the key to look for
      dflt - the default value for none
      Returns:
      the value, may by dflt for none
      See Also:
    • getBooleanPropertyOrEnv

      public static boolean getBooleanPropertyOrEnv(String key, boolean dflt)
      Returns a boolean value from the system properties or system environment, either as given or all in capital characters with dots replaced by underscores.
      Parameters:
      key - the key to look for
      dflt - the default value for none
      Returns:
      the value, may by dflt for none
      See Also:
    • getPropertyOrEnv

      public static String getPropertyOrEnv(String key)
      Returns a value from the system properties or system environment, either as given or all in capital characters with dots replaced by underscores.
      Parameters:
      key - the key to look for
      Returns:
      the value, may by null for none
      See Also:
    • isWindows

      public static boolean isWindows()
      Returns whether we are running on windows.
      Returns:
      true for windows, false else
    • isLinux

      public static boolean isLinux()
      Returns whether we are running on Linux.
      Returns:
      true for Linux, false else
    • isUnix

      public static boolean isUnix()
      Returns whether we are running on Unix.
      Returns:
      true for Unix, false else
    • isMac

      public static boolean isMac()
      Returns whether we are running on Mac.
      Returns:
      true for Mac, false else
    • isJava1_8

      public static boolean isJava1_8()
      Returns whether we are running on Java 1.8.
      Returns:
      true for Java 1.8, false else
    • isAtLeastJava9

      public static boolean isAtLeastJava9()
      Returns whether we are running on Java 9 or newer.
      Returns:
      true for Java 9 nor newer, false else