Class OSUtils

java.lang.Object
ch.autumo.commons.utils.system.OSUtils

public class OSUtils extends Object
OS Utils.
  • Field Details

    • WIN_APPDATA_FOLDER

      public static final String WIN_APPDATA_FOLDER
      Get Windows APPDATA directory.
    • USER_HOME

      public static final String USER_HOME
      User home directory.
    • LINE_SEPARATOR

      public static final String LINE_SEPARATOR
      System-specific separator.
    • FILE_SEPARATOR

      public static final String FILE_SEPARATOR
      System-specific file separator.
    • DIR_TEMP

      public static final String DIR_TEMP
      System-specific temporary directory.
  • Method Details

    • isWindows

      public static boolean isWindows()
      Is Windows?
      Returns:
      true if so
    • isMac

      public static boolean isMac()
      Is Mac?
      Returns:
      true if so
    • isUnix

      public static boolean isUnix()
      Is Unix?
      Returns:
      true if so
    • isSolaris

      public static boolean isSolaris()
      Is Solaris?
      Returns:
      true if so
    • getOS

      public static String getOS()
      Get operating system.
      Returns:
      true if so
    • getUser

      public static String getUser()
      Get user name.
      Returns:
      user name
    • getManufacturer

      public static String getManufacturer()
      Get manufacturer for this application/system.
      Returns:
      manufacturer name
    • getPropertiesRootPath

      public static String getPropertiesRootPath()
      Get root properties path.
      Returns:
      root properties path
    • getPropertiesPath

      public static String getPropertiesPath(String appName)
      Get properties path.
      Parameters:
      appName - app name
      Returns:
      properties path
    • getDefaultProjectRootPath

      public static String getDefaultProjectRootPath(String projectFolder)
      Get default project root path.
      Parameters:
      projectFolder - project folder
      Returns:
      default project root path
    • getReadableDuration

      public static String getReadableDuration(long durationInMilliseconds, TimeUnit printUpTo)
      Get readable duration.
      Parameters:
      durationInMilliseconds - duration in ms
      printUpTo - The maximum timeunit that should be printed
      Returns:
      readable duration
    • findExecutableOnPath

      public static String findExecutableOnPath(String name) throws IOException
      Find an executable on the environment path variable and return the full path or throw an exception.
      Parameters:
      name - executable name, with or without extension
      Returns:
      full path of executable
      Throws:
      IOException - if executable cannot be found in PATH on OS
    • getMacAddress

      public static String getMacAddress()
      Get MAC address.
      Returns:
      mac address
    • getRuntimeParameters

      public static Map<String,String> getRuntimeParameters()
      Get runtime parameter map
      Returns:
      RT parameter map
    • randomInt

      public static int randomInt(int min, int max)
      Get random number.
      Parameters:
      min - min
      max - max
      Returns:
      random number
    • randomString

      public static String randomString(int size)
      Get random string.
      Parameters:
      size - size
      Returns:
      random string
    • openAndlockFile

      public static RandomAccessFile openAndlockFile(String filePath)
      Open and lock a file for reading and writing.
      Parameters:
      filePath - file path
      Returns:
      file or null
    • load

      public static Properties load(RandomAccessFile file)
      Load properties from random access file.
      Parameters:
      file - file
      Returns:
      props
    • writeAndCloseLockedFile

      public static boolean writeAndCloseLockedFile(RandomAccessFile file, Properties props)
      Write and close locked file.
      Parameters:
      file - locked file
      props - props
      Returns:
      true, if successfull
    • closeLockedFile

      public static boolean closeLockedFile(RandomAccessFile file)
      Close locked file.
      Parameters:
      file - locked file
      Returns:
      true, if successfull
    • generateGUID

      public static String generateGUID()
      Generates a GUID (48 chars).
      Returns:
      The generated GUID.
    • getFileExtension

      public static String getFileExtension(String fileName)
      Get lowered file name extension without dot.
      Parameters:
      fileName - file name
      Returns:
      lowered file name extension
    • getTemporaryDirectory

      public static String getTemporaryDirectory()
      Get temporary directory.
      Returns:
      temporary directory
    • deleteFiles

      public static void deleteFiles(File[] files)
      Delete files.
      Parameters:
      files - file list
    • markForDeletion

      public static void markForDeletion(File[] files)
      Mark files for deletion on exit.
      Parameters:
      files - file list
    • getMajorJavaVersion

      public static int getMajorJavaVersion()
      Get major java version, without the old scheme for older version than Java version 9; Numbers from 1-20 (+).
      Returns:
      java major version
    • getNumberOfCPUCores

      public static int getNumberOfCPUCores()
      Get amount of CPU cores or '-1' is it cannot be determined!
      Returns:
      amount of CPU cores
    • fatalExit

      public static void fatalExit()
      Exit console program, due to unprocessable error.
    • errorExit

      public static void errorExit()
      Exit console program, due to an error.
    • invalidArgumentsExit

      public static void invalidArgumentsExit()
      Exit because of invalid argument use.
    • normalExit

      public static void normalExit()
      Exit console program, due desired end.
    • exit

      public static void exit(int code)
      Exit console program.
      Parameters:
      code - exit code