public final class SystemUtility extends Object
Modifier and Type | Method | Description |
---|---|---|
static String |
exec(int aTimeoutMillis,
String aCommandLine) |
Executes a command and returns the output.
|
static String |
exec(int aTimeoutMillis,
String... aCommandLine) |
Executes a command and returns the output.
|
static String |
exec(String aCommandLine) |
Executes a command and returns the output.
|
static String |
exec(String... aCommandLine) |
Executes a command and returns the output.
|
static String |
getComputerName() |
Determines the computer's name.
|
static String |
getUname() |
If on a *nix alike system, this method returns the output of the "uname
-a" command: "uname" prints system information, "-a" instructs it to
print all information.
|
static byte[] |
toHostIpAddress() |
Tries to determine a no-localhost IP-Address for this machine.
|
static byte[] |
toHostMacAddress() |
Tries to determine the host Mac-Address for this machine.
|
static String |
toPrettySystemInfo() |
Gathers all available system information from this Artifac's point of
view.
|
static String |
toPropertyValue(String aDefaultValue,
org.refcodes.data.SystemProperty aSystemProperty,
org.refcodes.data.EnvironmentVariable... aEnvironmentProperties) |
Gets the value for the provided properties, if non was found then the
default value is taken.
|
static String |
toPropertyValue(org.refcodes.data.SystemProperty aSystemProperty,
org.refcodes.data.EnvironmentVariable... aEnvironmentProperties) |
Gets the value for the provided properties, if non was found then null is
returned.
|
static Map<String,String> |
toSystemInfo() |
Gathers all available system information from this Artifac's point of
view.
|
public static String getComputerName()
InetAddress
, if it fails it tries to get it from the system's
environment using the EnvironmentVariable.COMPUTERNAME
(on
Windows machines only) and if both fails, it returns the default
Literal.LOCALHOST
identifier.Literal.LOCALHOST
("localhost") is returned.public static String getUname()
public static String toPropertyValue(String aDefaultValue, org.refcodes.data.SystemProperty aSystemProperty, org.refcodes.data.EnvironmentVariable... aEnvironmentProperties)
SystemProperty
elements wins over the
EnvironmentVariable
elements. The preceding
EnvironmentVariable
element wins over the succeeding
EnvironmentVariable
element. The default value is taken if non
property had a value (a String with length > 0).aDefaultValue
- The default value to take when none other value was
set.aSystemProperty
- The system-property passed via java
-D<name>=<value>
aEnvironmentProperties
- The properties looked for in the system's
environment variables.public static String toPropertyValue(org.refcodes.data.SystemProperty aSystemProperty, org.refcodes.data.EnvironmentVariable... aEnvironmentProperties)
SystemProperty
elements wins over the
EnvironmentVariable
elements. The preceding
EnvironmentVariable
element wins over the succeeding
EnvironmentVariable
element. A null is taken if non property had
a value (a String with length > 0).aSystemProperty
- The system-property passed via java
-D<name>=<value>
aEnvironmentProperties
- The properties looked for in the system's
environment variables.public static String exec(int aTimeoutMillis, String aCommandLine) throws IOException, InterruptedException
aTimeoutMillis
- The time in milliseconds to wait till the process
is killed when not terminated yet.aCommandLine
- the commandString
stands fur successful execution.IOException
- in case there were problems executing the command.InterruptedException
- thrown in case execution as been
interrupted.public static String exec(int aTimeoutMillis, String... aCommandLine) throws IOException, InterruptedException
aTimeoutMillis
- The time in milliseconds to wait till the process
is killed when not terminated yet.aCommandLine
- the command with the arguments to be passed to the
command.String
stands fur successful execution.IOException
- in case there were problems executing the command.InterruptedException
- thrown in case execution as been
interrupted.public static String exec(String aCommandLine) throws IOException
aCommandLine
- the commandString
stands fur successful execution.IOException
- in case there were problems executing the command.public static String exec(String... aCommandLine) throws IOException
aCommandLine
- the command with the arguments to be passed to the
command.String
stands fur successful execution.IOException
- in case there were problems executing the command.public static Map<String,String> toSystemInfo()
Map
containing the available information being
gathered.public static String toPrettySystemInfo()
toSystemInfo()
.String
containing the available information being
gathered.public static byte[] toHostIpAddress() throws SocketException, UnknownHostException
InetAddress.getLocalHost()
).InetAddress.getLocalHost()
may be returned.SocketException
- Thrown to indicate that accessing the network
interfaces caused a problem.UnknownHostException
- Thrown to indicate that the IP address of
the local host could not be determined.public static byte[] toHostMacAddress() throws SocketException, UnknownHostException
SocketException
- Thrown to indicate that accessing the network
interfaces caused a problem.UnknownHostException
- Thrown to indicate that the IP address of
the local host could not be determined.Copyright © 2021. All rights reserved.