Package ch.autumo.commons.utils.system
Class OSUtils
java.lang.Object
ch.autumo.commons.utils.system.OSUtils
OS Utils.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Close locked file.static void
deleteFiles
(File[] files) Delete files.static void
Exit console program, due to an error.static void
exit
(int code) Exit console program.static void
Exit console program, due to unprocessable error.static String
findExecutableOnPath
(String name) Find an executable on the environment path variable and return the full path or throw an exception.static String
Generates a GUID (48 chars).static String
getDefaultProjectRootPath
(String projectFolder) Get default project root path.static String
getFileExtension
(String fileName) Get lowered file name extension without dot.static String
Get MAC address.static int
Get major java version, without the old scheme for older version than Java version 9; Numbers from 1-20 (+).static String
Get manufacturer for this application/system.static int
Get amount of CPU cores or '-1' is it cannot be determined!static String
getOS()
Get operating system.static String
getPropertiesPath
(String appName) Get properties path.static String
Get root properties path.static String
getReadableDuration
(long durationInMilliseconds, TimeUnit printUpTo) Get readable duration.Get runtime parameter mapstatic String
Get temporary directory.static String
getUser()
Get user name.static void
Exit because of invalid argument use.static boolean
isMac()
Is Mac?static boolean
Is Solaris?static boolean
isUnix()
Is Unix?static boolean
Is Windows?static Properties
load
(RandomAccessFile file) Load properties from random access file.static void
markForDeletion
(File[] files) Mark files for deletion on exit.static void
Exit console program, due desired end.static RandomAccessFile
openAndlockFile
(String filePath) Open and lock a file for reading and writing.static int
randomInt
(int min, int max) Get random number.static String
randomString
(int size) Get random string.static boolean
writeAndCloseLockedFile
(RandomAccessFile file, Properties props) Write and close locked file.
-
Field Details
-
WIN_APPDATA_FOLDER
Get Windows APPDATA directory. -
USER_HOME
User home directory. -
LINE_SEPARATOR
System-specific separator. -
FILE_SEPARATOR
System-specific file separator. -
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
Get operating system.- Returns:
- true if so
-
getUser
Get user name.- Returns:
- user name
-
getManufacturer
Get manufacturer for this application/system.- Returns:
- manufacturer name
-
getPropertiesRootPath
Get root properties path.- Returns:
- root properties path
-
getPropertiesPath
Get properties path.- Parameters:
appName
- app name- Returns:
- properties path
-
getDefaultProjectRootPath
Get default project root path.- Parameters:
projectFolder
- project folder- Returns:
- default project root path
-
getReadableDuration
Get readable duration.- Parameters:
durationInMilliseconds
- duration in msprintUpTo
- The maximum timeunit that should be printed- Returns:
- readable duration
-
findExecutableOnPath
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
Get MAC address.- Returns:
- mac address
-
getRuntimeParameters
Get runtime parameter map- Returns:
- RT parameter map
-
randomInt
public static int randomInt(int min, int max) Get random number.- Parameters:
min
- minmax
- max- Returns:
- random number
-
randomString
Get random string.- Parameters:
size
- size- Returns:
- random string
-
openAndlockFile
Open and lock a file for reading and writing.- Parameters:
filePath
- file path- Returns:
- file or null
-
load
Load properties from random access file.- Parameters:
file
- file- Returns:
- props
-
writeAndCloseLockedFile
Write and close locked file.- Parameters:
file
- locked fileprops
- props- Returns:
- true, if successfull
-
closeLockedFile
Close locked file.- Parameters:
file
- locked file- Returns:
- true, if successfull
-
generateGUID
Generates a GUID (48 chars).- Returns:
- The generated GUID.
-
getFileExtension
Get lowered file name extension without dot.- Parameters:
fileName
- file name- Returns:
- lowered file name extension
-
getTemporaryDirectory
Get temporary directory.- Returns:
- temporary directory
-
deleteFiles
Delete files.- Parameters:
files
- file list
-
markForDeletion
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
-