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 booleanClose locked file.static voiddeleteFiles(File[] files) Delete files.static voidExit console program, due to an error.static voidexit(int code) Exit console program.static voidExit console program, due to unprocessable error.static StringfindExecutableOnPath(String name) Find an executable on the environment path variable and return the full path or throw an exception.static StringGenerates a GUID (48 chars).static StringgetDefaultProjectRootPath(String projectFolder) Get default project root path.static StringgetFileExtension(String fileName) Get lowered file name extension without dot.static StringGet MAC address.static intGet major java version, without the old scheme for older version than Java version 9; Numbers from 1-20 (+).static StringGet manufacturer for this application/system.static intGet amount of CPU cores or '-1' is it cannot be determined!static StringgetOS()Get operating system.static StringgetPropertiesPath(String appName) Get properties path.static StringGet root properties path.static StringgetReadableDuration(long durationInMilliseconds, TimeUnit printUpTo) Get readable duration.Get runtime parameter mapstatic StringGet temporary directory.static StringgetUser()Get user name.static voidExit because of invalid argument use.static booleanisMac()Is Mac?static booleanIs Solaris?static booleanisUnix()Is Unix?static booleanIs Windows?static Propertiesload(RandomAccessFile file) Load properties from random access file.static voidmarkForDeletion(File[] files) Mark files for deletion on exit.static voidExit console program, due desired end.static RandomAccessFileopenAndlockFile(String filePath) Open and lock a file for reading and writing.static intrandomInt(int min, int max) Get random number.static StringrandomString(int size) Get random string.static booleanwriteAndCloseLockedFile(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
-