public final class SystemUtility extends Object
Modifier and Type | Method | Description |
---|---|---|
static String |
exec(String aCommand) |
Executes a command and returns the output.
|
static String |
getComputerName() |
Determines the computer's name.
|
static String |
getLineBreak() |
Determines the operating system as of
OperatingSystem.toOperatingSystem() and in case a
OperatingSystem.WINDOWS is being detected, then \r\n" (CRLF) is
returned, else "\n" (LF) is returned. |
static String |
getSystemEncoding() |
Determines the encoding of the system (system's console) in use as of
System.out . |
static File |
getTempDir() |
Returns the operating saystem's temp folder.
|
static int |
getTerminalHeight() |
Determines the height in characters of the system's terminal in use.
|
static int |
getTerminalWidth() |
Determines the width in characters of the system's terminal in use.
|
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 boolean |
isAnsiConsole() |
Determines whether ANSI escape sequences are forced to be supported or
not by REFCODES.ORG artifacts.
|
static boolean |
isAnsiTerminal() |
Determines whether ANSI escape sequences are supported by the terminal.
|
static boolean |
isUseLineBreak(int aRowWidth) |
Determines whether wee need an explicit line-break for the given width on
the current operating system and used terminal.
|
static int |
toAnsiconHeight(String aAnsiconEnvVarValue) |
Extracts the height from an "ANSICON" environment variable's value.
|
static int |
toAnsiconWidth(String aAnsiconEnvVarValue) |
Extracts the width from an "ANSICON" environment variable's value.
|
static int |
toConsoleHeight() |
Does some calculation to always return a sound console height (never
returns -1).
|
static int |
toConsoleWidth() |
Does some calculation to always return a sound console width (never
returns -1).
|
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 |
toLineBreak(int aRowWidth) |
Uses
isUseLineBreak(int) to retrieve the character sequence
required to suffix to a line in order to get a line break without risking
any empty lines as of automatic line wrapping. |
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 getLineBreak()
OperatingSystem.toOperatingSystem()
and in case a
OperatingSystem.WINDOWS
is being detected, then \r\n" (CRLF) is
returned, else "\n" (LF) is returned.
Can be overridden with the SystemProperty.CONSOLE_LINE_BREAK
(java -Dconsole.lineBreak=...
) and the
EnvironmentVariable.CONSOLE_LINE_BREAK
("export CONSOLE_LINE_BREAK=...
).public static boolean isUseLineBreak(int aRowWidth)
aRowWidth
- The row width you want to use when printing out to a
console.public static String toLineBreak(int aRowWidth)
isUseLineBreak(int)
to retrieve the character sequence
required to suffix to a line in order to get a line break without risking
any empty lines as of automatic line wrapping. Automatic line wrapping
can happen on Windows environment when the console width is reached. A
line break would cause a superfluous empty line (ugly).aRowWidth
- The row width you want to use when printing out to a
console.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 int getTerminalWidth()
public static int getTerminalHeight()
public static int toAnsiconWidth(String aAnsiconEnvVarValue) throws NumberFormatException
aAnsiconEnvVarValue
- The "ANSICON" formatted variable (e.g.
"91x19999 (91x51)").NumberFormatException
- Thrown in case no width was determinable
from the provided value.public static int toAnsiconHeight(String aAnsiconEnvVarValue) throws NumberFormatException
aAnsiconEnvVarValue
- The "ANSICON" formatted variable (e.g.
"91x19999 (91x51)").NumberFormatException
- Thrown in case no width was determinable
from the provided value.public static int toConsoleWidth()
public static int toConsoleHeight()
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(String aCommand) throws IOException, InterruptedException
aCommand
- 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 boolean isAnsiTerminal()
public static boolean isAnsiConsole()
isAnsiTerminal()
for the REFCODES.ORG artifacts. Various settings such as
SystemProperty.CONSOLE_ANSI
and (in this order)
EnvironmentVariable.CONSOLE_ANSI
overrule
isAnsiTerminal()
.public static File getTempDir()
public static String getSystemEncoding()
System.out
.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 © 2018. All rights reserved.