public class OSUtilities
extends java.lang.Object
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
.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
LINE_SEPARATOR
Platform specific line separator.
|
Constructor and Description |
---|
OSUtilities() |
Modifier and Type | Method and 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 name
binaryName 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 name
binaryName in the set of paths denoted
by pathSet . |
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 for
getSafeOSPath(boolean) with root=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() |
public static final java.lang.String LINE_SEPARATOR
public static boolean isUnix()
true
if the operating system is UNIX like.public static boolean isWindows()
true
if the operating system is a MS Windows type.public static boolean isMacOS()
true
if the the operating system is a flavor of Mac OS X.public static java.lang.String getCompatibleComputerPlatform()
public static java.lang.String getCPUArchitecture()
public static java.lang.String getOSName()
public static java.lang.String getComputerPlatform()
public static java.lang.String getUsername()
public static boolean isRoot()
true
if the user that runs this program is known to have root privileges
(based on his name).public static java.util.Set<java.lang.String> getOSPath()
public static java.util.Set<java.lang.String> getSafeOSPath(boolean root)
root
- Whether the path should be prepared for root or not.getOSPath()
public static java.util.Set<java.lang.String> getSafeOSPath()
getSafeOSPath(boolean)
with root=false
.getSafeOSPath(boolean)
public static java.io.File findExecutable(java.lang.String executableName)
binaryName
in the operating system
path..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.null
, if no binary
file could be found.public static java.io.File findExecutable(java.lang.String executableName, java.util.Set<java.lang.String> pathSet)
binaryName
in the set of paths denoted
by pathSet
.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
the LinkedHashSet
here in order to get results that are independent of the
JRE implementation.null
, if no binary
file could be found.public static boolean executableExists(java.lang.String executableName)
true
if and only if an executable of name executableName
exists.public static boolean executableExists(java.io.File executable)
true
if and only if an executable of name executableName
exists.