Package ch.systemsx.cisd.base.utilities
Class OSUtilities
- java.lang.Object
-
- ch.systemsx.cisd.base.utilities.OSUtilities
-
public class OSUtilities extends java.lang.Object
Some useful methods related to the operating system.Does not depend on any library jar files. But before using or extending this class and if you do not mind using commons lang, then have a look on
SystemUtils
.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
LINE_SEPARATOR
Platform specific line separator.
-
Constructor Summary
Constructors Constructor Description OSUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
executableExists(java.io.File executable)
static boolean
executableExists(java.lang.String executableName)
static java.io.File
findExecutable(java.lang.String executableName)
Search for the binary program with namebinaryName
in the operating system path..static java.io.File
findExecutable(java.lang.String executableName, java.util.Set<java.lang.String> pathSet)
Search for the binary program with namebinaryName
in the set of paths denoted bypathSet
.static java.lang.String
getCompatibleComputerPlatform()
static java.lang.String
getComputerPlatform()
static java.lang.String
getCPUArchitecture()
static java.lang.String
getOSName()
static java.util.Set<java.lang.String>
getOSPath()
static java.util.Set<java.lang.String>
getSafeOSPath()
Convenience method forgetSafeOSPath(boolean)
withroot=false
.static java.util.Set<java.lang.String>
getSafeOSPath(boolean root)
static java.lang.String
getUsername()
static boolean
isMacOS()
static boolean
isRoot()
static boolean
isUnix()
static boolean
isWindows()
-
-
-
Method Detail
-
isUnix
public static boolean isUnix()
- Returns:
true
if the operating system is UNIX like.
-
isWindows
public static boolean isWindows()
- Returns:
true
if the operating system is a MS Windows type.
-
isMacOS
public static boolean isMacOS()
- Returns:
true
if the the operating system is a flavor of Mac OS X.
-
getCompatibleComputerPlatform
public static java.lang.String getCompatibleComputerPlatform()
- Returns:
- The name of the computer platform that is compatible with respect to executables (CPU architecture and OS name, both as precise as possible to be able to share libraries and binaries).
-
getCPUArchitecture
public static java.lang.String getCPUArchitecture()
- Returns:
- The name of the CPU architecture.
-
getOSName
public static java.lang.String getOSName()
- Returns:
- The name of the operating system.
-
getComputerPlatform
public static java.lang.String getComputerPlatform()
- Returns:
- The name of the computer platform (CPU architecture and OS name).
-
getUsername
public static java.lang.String getUsername()
- Returns:
- The name of user that runs this program.
-
isRoot
public static boolean isRoot()
- Returns:
true
if the user that runs this program is known to have root privileges (based on his name).
-
getOSPath
public static java.util.Set<java.lang.String> getOSPath()
- Returns:
- The PATH as provided by the operating system.
-
getSafeOSPath
public static java.util.Set<java.lang.String> getSafeOSPath(boolean root)
- Parameters:
root
- Whether the path should be prepared for root or not.- Returns:
- The path as provided by the operating system plus some path entries that should always be available.
- See Also:
getOSPath()
-
getSafeOSPath
public static java.util.Set<java.lang.String> getSafeOSPath()
Convenience method forgetSafeOSPath(boolean)
withroot=false
.- Returns:
- The path as provided by the operating system plus some path entries that should always be available.
- See Also:
getSafeOSPath(boolean)
-
findExecutable
public static java.io.File findExecutable(java.lang.String executableName)
Search for the binary program with namebinaryName
in the operating system path..- Parameters:
executableName
- The name of the executable to search for. Under Windows, a name with and without.exe
appended will work, but the executable found needs to have the .exe extension.- Returns:
- The binary file that has been found in the path, or
null
, if no binary file could be found.
-
findExecutable
public static java.io.File findExecutable(java.lang.String executableName, java.util.Set<java.lang.String> pathSet)
Search for the binary program with namebinaryName
in the set of paths denoted bypathSet
.- Parameters:
executableName
- The name of the executable to search for. Under Windows, a name with and without.exe
appended will work, but the executable found needs to have the .exe extension.pathSet
- The set of paths to search for. It is recommended to use an ordered set like theLinkedHashSet
here in order to get results that are independent of the JRE implementation.- Returns:
- The binary file that has been found in the path, or
null
, if no binary file could be found.
-
executableExists
public static boolean executableExists(java.lang.String executableName)
- Returns:
true
if and only if an executable of name executableName exists.
-
executableExists
public static boolean executableExists(java.io.File executable)
- Returns:
true
if and only if an executable of name executableName exists.
-
-