public class SystemUtil extends Object
Modifier and Type | Field and Description |
---|---|
static long |
PID_NOT_FOUND
PID value if a process id could not be determined.
|
Constructor and Description |
---|
SystemUtil() |
Modifier and Type | Method and Description |
---|---|
static long |
getDurationInNanos(String propertyName,
long defaultValue)
Get a string representation of a time duration with an optional suffix of 's', 'ms', 'us', or 'ns' suffix to
indicate seconds, milliseconds, microseconds, or nanoseconds respectively.
|
static long |
getPid()
Return the current process id from the OS.
|
static int |
getSizeAsInt(String propertyName,
int defaultValue)
Get a size value as an int from a system property.
|
static long |
getSizeAsLong(String propertyName,
long defaultValue)
Get a size value as a long from a system property.
|
static boolean |
isDebuggerAttached()
Is a debugger attached to the JVM?
|
static void |
loadPropertiesFile(String filenameOrUrl)
Load system properties from a given filename or url.
|
static void |
loadPropertiesFiles(String[] filenamesOrUrls)
Load system properties from a given set of filenames or URLs.
|
static String |
osName()
Get the name of the operating system as a lower case String.
|
static long |
parseDuration(String propertyName,
String propertyValue)
Parse a string representation of a time duration with an optional suffix of 's', 'ms', 'us', or 'ns' to
indicate seconds, milliseconds, microseconds, or nanoseconds respectively.
|
static long |
parseSize(String propertyName,
String propertyValue)
Parse a string representation of a value with optional suffix of 'g', 'm', and 'k' suffix to indicate
gigabytes, megabytes, or kilobytes respectively.
|
static String |
threadDump()
Get a formatted dump of all threads with associated state and stack traces.
|
static String |
tmpDirName()
Return the system property for java.io.tmpdir ensuring a
File.separator is at the end. |
public static final long PID_NOT_FOUND
public static String osName()
This is what is returned from System.getProperty("os.name").toLowerCase().
public static long getPid()
PID_NOT_FOUND
if PID was not able to be found.PID_NOT_FOUND
public static boolean isDebuggerAttached()
public static String tmpDirName()
File.separator
is at the end.public static String threadDump()
public static void loadPropertiesFile(String filenameOrUrl)
File is first searched for in resources using the system ClassLoader
,
then file system, then URL. All are loaded if multiples found.
filenameOrUrl
- that holds properties.public static void loadPropertiesFiles(String[] filenamesOrUrls)
filenamesOrUrls
- that holds properties.loadPropertiesFile(String)
public static int getSizeAsInt(String propertyName, int defaultValue)
propertyName
- to lookup.defaultValue
- to be applied if the system property is not set.NumberFormatException
- if the value is out of range or mal-formatted.public static long getSizeAsLong(String propertyName, long defaultValue)
propertyName
- to lookup.defaultValue
- to be applied if the system property is not set.NumberFormatException
- if the value is out of range or mal-formatted.public static long parseSize(String propertyName, String propertyValue)
propertyName
- that associated with the size value.propertyValue
- to be parsed.NumberFormatException
- if the value is out of range or mal-formatted.public static long getDurationInNanos(String propertyName, long defaultValue)
If the resulting duration is greater than Long.MAX_VALUE
then Long.MAX_VALUE
is used.
propertyName
- associated with the duration value.defaultValue
- to be used if the property is not present.NumberFormatException
- if the value is negative or malformed.public static long parseDuration(String propertyName, String propertyValue)
If the resulting duration is greater than Long.MAX_VALUE
then Long.MAX_VALUE
is used.
propertyName
- associated with the duration value.propertyValue
- to be parsed.NumberFormatException
- if the value is negative or malformed.Copyright © 2014-2019 Real Logic Ltd. All Rights Reserved.