Class SystemUtils
- java.lang.Object
-
- io.microsphere.util.SystemUtils
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
FILE_ENCODING
The System property for the file encoding, the default is "UTF-8"static java.lang.String
FILE_ENCODING_PROPERTY_KEY
The System property key for the file encoding : "file.encoding"static java.lang.String
FILE_SEPARATOR_PROPERTY_KEY
The System property key for the File separator ("/" on UNIX) : "file.separator"static boolean
IS_JAVA_10
Istrue
if this is Java version 10.xstatic boolean
IS_JAVA_11
Istrue
if this is Java version 11.xstatic boolean
IS_JAVA_12
Istrue
if this is Java version 12.xstatic boolean
IS_JAVA_13
Istrue
if this is Java version 13.xstatic boolean
IS_JAVA_14
Istrue
if this is Java version 14.xstatic boolean
IS_JAVA_15
Istrue
if this is Java version 15.xstatic boolean
IS_JAVA_16
Istrue
if this is Java version 16.xstatic boolean
IS_JAVA_17
Istrue
if this is Java version 17.xstatic boolean
IS_JAVA_18
Istrue
if this is Java version 18.xstatic boolean
IS_JAVA_19
Istrue
if this is Java version 19.xstatic boolean
IS_JAVA_20
Istrue
if this is Java version 20.xstatic boolean
IS_JAVA_21
Istrue
if this is Java version 21.xstatic boolean
IS_JAVA_22
Istrue
if this is Java version 22.xstatic boolean
IS_JAVA_23
Istrue
if this is Java version 23.xstatic boolean
IS_JAVA_24
Istrue
if this is Java version 24.xstatic boolean
IS_JAVA_8
Istrue
if this is Java 8static boolean
IS_JAVA_9
Istrue
if this is Java version 9.xstatic boolean
IS_LTS_JAVA_VERSION
Istrue
if current Java version is Long Term Supported(LTS)static boolean
IS_OS_WINDOWS
Istrue
if this is Windows.static java.lang.String
JAVA_CLASS_PATH
The System property for the Java class path.static java.lang.String
JAVA_CLASS_PATH_PROPERTY_KEY
The System property key for the Java class path : "java.class.path"static java.lang.String
JAVA_CLASS_VERSION
The System property for the Java class format version number.static java.lang.String
JAVA_CLASS_VERSION_PROPERTY_KEY
The System property key for the Java class format version number : "java.class.version"static java.lang.String
JAVA_COMPILER
The System property for the Name of JIT compiler to use.static java.lang.String
JAVA_COMPILER_PROPERTY_KEY
The System property key for the Name of JIT compiler to use : "java.compiler"static java.lang.String
JAVA_EXT_DIRS
The System property for the Path of extension directory or directories Deprecated.static java.lang.String
JAVA_EXT_DIRS_PROPERTY_KEY
Deprecated.static java.lang.String
JAVA_HOME
The System property for the Java installation directory.static java.lang.String
JAVA_HOME_PROPERTY_KEY
The System property key for the Java installation directory : "java.home"static java.lang.String
JAVA_IO_TMPDIR
The System property for the Default temp file path.static java.lang.String
JAVA_IO_TMPDIR_PROPERTY_KEY
The System property key for the Default temp file path : "java.io.tmpdir"static java.lang.String
JAVA_LIBRARY_PATH
The System property for the List of paths to search when loading libraries.static java.lang.String
JAVA_LIBRARY_PATH_PROPERTY_KEY
The System property key for the List of paths to search when loading libraries : "java.library.path"static java.lang.String
JAVA_SPECIFICATION_NAME
The System property for the Java Runtime Environment specification name.static java.lang.String
JAVA_SPECIFICATION_NAME_PROPERTY_KEY
The System property key for the Java Runtime Environment specification name : "java.specification.name"static java.lang.String
JAVA_SPECIFICATION_VENDOR
The System property for the Java Runtime Environment specification vendor.static java.lang.String
JAVA_SPECIFICATION_VENDOR_PROPERTY_KEY
The System property key for the Java Runtime Environment specification vendor : "java.specification.vendor"static java.lang.String
JAVA_SPECIFICATION_VERSION
The System property for the Java Runtime Environment specification version.static java.lang.String
JAVA_SPECIFICATION_VERSION_PROPERTY_KEY
The System property key for the Java Runtime Environment specification version : "java.specification.version"static java.lang.String
JAVA_VENDOR
The System property for the Java Runtime Environment vendor.static java.lang.String
JAVA_VENDOR_PROPERTY_KEY
The System property key for the Java Runtime Environment vendor : "java.vendor"static java.lang.String
JAVA_VENDOR_URL
The System property for the Java vendor URL.static java.lang.String
JAVA_VENDOR_URL_PROPERTY_KEY
The System property key for the Java vendor URL : "java.vendor.url"static java.lang.String
JAVA_VERSION
The System property for the Java Runtime Environment version.static java.lang.String
JAVA_VERSION_PROPERTY_KEY
The System property key for the Java Runtime Environment version : "java.version"static java.lang.String
JAVA_VM_NAME
The System property for the Java Virtual Machine implementation name.static java.lang.String
JAVA_VM_NAME_PROPERTY_KEY
The System property key for the Java Virtual Machine implementation name : "java.vm.name"static java.lang.String
JAVA_VM_SPECIFICATION_NAME
The System property for the Java Virtual Machine specification name.static java.lang.String
JAVA_VM_SPECIFICATION_NAME_PROPERTY_KEY
The System property key for the Java Virtual Machine specification name : "java.vm.specification.name"static java.lang.String
JAVA_VM_SPECIFICATION_VENDOR
The System property for the Java Virtual Machine specification vendor.static java.lang.String
JAVA_VM_SPECIFICATION_VENDOR_PROPERTY_KEY
The System property key for the Java Virtual Machine specification vendor : "java.vm.specification.vendor"static java.lang.String
JAVA_VM_SPECIFICATION_VERSION
The System property for the Java Virtual Machine specification version.static java.lang.String
JAVA_VM_SPECIFICATION_VERSION_PROPERTY_KEY
The System property key for the Java Virtual Machine specification version : "java.vm.specification.version"static java.lang.String
JAVA_VM_VENDOR
The System property for the Java Virtual Machine implementation vendor.static java.lang.String
JAVA_VM_VENDOR_PROPERTY_KEY
The System property key for the Java Virtual Machine implementation vendor : "java.vm.vendor"static java.lang.String
JAVA_VM_VERSION
The System property for the Java Virtual Machine implementation version.static java.lang.String
JAVA_VM_VERSION_PROPERTY_KEY
The System property key for the Java Virtual Machine implementation version : "java.vm.version"static java.lang.String
LINE_SEPARATOR_PROPERTY_KEY
The System property key for the Line separator ("\n" on UNIX) : "line.separator"static java.lang.String
NATIVE_ENCODING
The System property for the native encodingstatic java.lang.String
NATIVE_ENCODING_PROPERTY_KEY
The System property key for the native encoding : "native.encoding"static java.lang.String
OS_ARCH
The System property for the Operating system architecture.static java.lang.String
OS_ARCH_PROPERTY_KEY
The System property key for the Operating system architecture : "os.arch"static java.lang.String
OS_NAME
The System property for the Operating system name.static java.lang.String
OS_NAME_PROPERTY_KEY
The System property key for the Operating system name : "os.name"static java.lang.String
OS_NAME_WINDOWS_PREFIX
static java.lang.String
OS_VERSION
The System property for the Operating system version.static java.lang.String
OS_VERSION_PROPERTY_KEY
The System property key for the Operating system version : "os.version"static java.lang.String
PATH_SEPARATOR_PROPERTY_KEY
The System property key for the Path separator (":" on UNIX) : "path.separator"static java.lang.String
USER_DIR
The System property for the User's current working directory.static java.lang.String
USER_DIR_PROPERTY_KEY
The System property key for the User's current working directory : "user.dir"static java.lang.String
USER_HOME
The System property for the User's home directory.static java.lang.String
USER_HOME_PROPERTY_KEY
The System property key for the User's home directory : "user.home"static java.lang.String
USER_NAME
The System property for the User's account name.static java.lang.String
USER_NAME_PROPERTY_KEY
The System property key for the User's account name : "user.name"
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
copySystemProperties()
Copies the current system properties into an internal map for later access.static java.lang.String
getSystemProperty(java.lang.String key)
Gets a system property with the given key, defaulting tonull
if the property cannot be read.static java.lang.String
getSystemProperty(java.lang.String key, java.lang.String defaultValue)
Gets a system property with the given key, defaulting to the provideddefaultValue
if the property cannot be read.protected static java.lang.String
getSystemPropertyFromCopy(java.lang.String key)
protected static void
resetSystemPropertiesCopy()
Reset thesystemPropertiesCopy
to benull
, mainly used for testing
-
-
-
Field Detail
-
OS_NAME_WINDOWS_PREFIX
public static final java.lang.String OS_NAME_WINDOWS_PREFIX
- See Also:
- Constant Field Values
-
JAVA_CLASS_PATH_PROPERTY_KEY
public static final java.lang.String JAVA_CLASS_PATH_PROPERTY_KEY
The System property key for the Java class path : "java.class.path"- See Also:
- Constant Field Values
-
USER_NAME_PROPERTY_KEY
public static final java.lang.String USER_NAME_PROPERTY_KEY
The System property key for the User's account name : "user.name"- See Also:
- Constant Field Values
-
JAVA_EXT_DIRS_PROPERTY_KEY
@Deprecated public static final java.lang.String JAVA_EXT_DIRS_PROPERTY_KEY
Deprecated.The System property key for the Path of extension directory or directories Deprecated. This property, and the mechanism which implements it, may be removed in a future release : "java.ext.dirs"- See Also:
- Constant Field Values
-
JAVA_VENDOR_PROPERTY_KEY
public static final java.lang.String JAVA_VENDOR_PROPERTY_KEY
The System property key for the Java Runtime Environment vendor : "java.vendor"- See Also:
- Constant Field Values
-
JAVA_SPECIFICATION_VERSION_PROPERTY_KEY
public static final java.lang.String JAVA_SPECIFICATION_VERSION_PROPERTY_KEY
The System property key for the Java Runtime Environment specification version : "java.specification.version"- See Also:
- Constant Field Values
-
LINE_SEPARATOR_PROPERTY_KEY
public static final java.lang.String LINE_SEPARATOR_PROPERTY_KEY
The System property key for the Line separator ("\n" on UNIX) : "line.separator"- See Also:
- Constant Field Values
-
JAVA_CLASS_VERSION_PROPERTY_KEY
public static final java.lang.String JAVA_CLASS_VERSION_PROPERTY_KEY
The System property key for the Java class format version number : "java.class.version"- See Also:
- Constant Field Values
-
JAVA_SPECIFICATION_NAME_PROPERTY_KEY
public static final java.lang.String JAVA_SPECIFICATION_NAME_PROPERTY_KEY
The System property key for the Java Runtime Environment specification name : "java.specification.name"- See Also:
- Constant Field Values
-
JAVA_VENDOR_URL_PROPERTY_KEY
public static final java.lang.String JAVA_VENDOR_URL_PROPERTY_KEY
The System property key for the Java vendor URL : "java.vendor.url"- See Also:
- Constant Field Values
-
JAVA_VM_VERSION_PROPERTY_KEY
public static final java.lang.String JAVA_VM_VERSION_PROPERTY_KEY
The System property key for the Java Virtual Machine implementation version : "java.vm.version"- See Also:
- Constant Field Values
-
OS_NAME_PROPERTY_KEY
public static final java.lang.String OS_NAME_PROPERTY_KEY
The System property key for the Operating system name : "os.name"- See Also:
- Constant Field Values
-
OS_ARCH_PROPERTY_KEY
public static final java.lang.String OS_ARCH_PROPERTY_KEY
The System property key for the Operating system architecture : "os.arch"- See Also:
- Constant Field Values
-
JAVA_HOME_PROPERTY_KEY
public static final java.lang.String JAVA_HOME_PROPERTY_KEY
The System property key for the Java installation directory : "java.home"- See Also:
- Constant Field Values
-
OS_VERSION_PROPERTY_KEY
public static final java.lang.String OS_VERSION_PROPERTY_KEY
The System property key for the Operating system version : "os.version"- See Also:
- Constant Field Values
-
JAVA_COMPILER_PROPERTY_KEY
public static final java.lang.String JAVA_COMPILER_PROPERTY_KEY
The System property key for the Name of JIT compiler to use : "java.compiler"- See Also:
- Constant Field Values
-
JAVA_VERSION_PROPERTY_KEY
public static final java.lang.String JAVA_VERSION_PROPERTY_KEY
The System property key for the Java Runtime Environment version : "java.version"- See Also:
- Constant Field Values
-
JAVA_VM_SPECIFICATION_VERSION_PROPERTY_KEY
public static final java.lang.String JAVA_VM_SPECIFICATION_VERSION_PROPERTY_KEY
The System property key for the Java Virtual Machine specification version : "java.vm.specification.version"- See Also:
- Constant Field Values
-
USER_DIR_PROPERTY_KEY
public static final java.lang.String USER_DIR_PROPERTY_KEY
The System property key for the User's current working directory : "user.dir"- See Also:
- Constant Field Values
-
JAVA_SPECIFICATION_VENDOR_PROPERTY_KEY
public static final java.lang.String JAVA_SPECIFICATION_VENDOR_PROPERTY_KEY
The System property key for the Java Runtime Environment specification vendor : "java.specification.vendor"- See Also:
- Constant Field Values
-
JAVA_VM_SPECIFICATION_NAME_PROPERTY_KEY
public static final java.lang.String JAVA_VM_SPECIFICATION_NAME_PROPERTY_KEY
The System property key for the Java Virtual Machine specification name : "java.vm.specification.name"- See Also:
- Constant Field Values
-
JAVA_VM_VENDOR_PROPERTY_KEY
public static final java.lang.String JAVA_VM_VENDOR_PROPERTY_KEY
The System property key for the Java Virtual Machine implementation vendor : "java.vm.vendor"- See Also:
- Constant Field Values
-
FILE_SEPARATOR_PROPERTY_KEY
public static final java.lang.String FILE_SEPARATOR_PROPERTY_KEY
The System property key for the File separator ("/" on UNIX) : "file.separator"- See Also:
- Constant Field Values
-
PATH_SEPARATOR_PROPERTY_KEY
public static final java.lang.String PATH_SEPARATOR_PROPERTY_KEY
The System property key for the Path separator (":" on UNIX) : "path.separator"- See Also:
- Constant Field Values
-
JAVA_LIBRARY_PATH_PROPERTY_KEY
public static final java.lang.String JAVA_LIBRARY_PATH_PROPERTY_KEY
The System property key for the List of paths to search when loading libraries : "java.library.path"- See Also:
- Constant Field Values
-
USER_HOME_PROPERTY_KEY
public static final java.lang.String USER_HOME_PROPERTY_KEY
The System property key for the User's home directory : "user.home"- See Also:
- Constant Field Values
-
JAVA_VM_NAME_PROPERTY_KEY
public static final java.lang.String JAVA_VM_NAME_PROPERTY_KEY
The System property key for the Java Virtual Machine implementation name : "java.vm.name"- See Also:
- Constant Field Values
-
JAVA_VM_SPECIFICATION_VENDOR_PROPERTY_KEY
public static final java.lang.String JAVA_VM_SPECIFICATION_VENDOR_PROPERTY_KEY
The System property key for the Java Virtual Machine specification vendor : "java.vm.specification.vendor"- See Also:
- Constant Field Values
-
JAVA_IO_TMPDIR_PROPERTY_KEY
public static final java.lang.String JAVA_IO_TMPDIR_PROPERTY_KEY
The System property key for the Default temp file path : "java.io.tmpdir"- See Also:
- Constant Field Values
-
FILE_ENCODING_PROPERTY_KEY
public static final java.lang.String FILE_ENCODING_PROPERTY_KEY
The System property key for the file encoding : "file.encoding"- See Also:
- Constant Field Values
-
NATIVE_ENCODING_PROPERTY_KEY
public static final java.lang.String NATIVE_ENCODING_PROPERTY_KEY
The System property key for the native encoding : "native.encoding"- See Also:
- Constant Field Values
-
JAVA_CLASS_PATH
public static final java.lang.String JAVA_CLASS_PATH
The System property for the Java class path.
-
USER_NAME
public static final java.lang.String USER_NAME
The System property for the User's account name.
-
JAVA_EXT_DIRS
public static final java.lang.String JAVA_EXT_DIRS
The System property for the Path of extension directory or directories Deprecated. This property, and the mechanism which implements it, may be removed in a future release..
-
JAVA_VENDOR
public static final java.lang.String JAVA_VENDOR
The System property for the Java Runtime Environment vendor.
-
JAVA_SPECIFICATION_VERSION
public static final java.lang.String JAVA_SPECIFICATION_VERSION
The System property for the Java Runtime Environment specification version.
-
JAVA_CLASS_VERSION
public static final java.lang.String JAVA_CLASS_VERSION
The System property for the Java class format version number.
-
JAVA_SPECIFICATION_NAME
public static final java.lang.String JAVA_SPECIFICATION_NAME
The System property for the Java Runtime Environment specification name.
-
JAVA_VENDOR_URL
public static final java.lang.String JAVA_VENDOR_URL
The System property for the Java vendor URL.
-
JAVA_VM_VERSION
public static final java.lang.String JAVA_VM_VERSION
The System property for the Java Virtual Machine implementation version.
-
OS_NAME
public static final java.lang.String OS_NAME
The System property for the Operating system name.
-
OS_ARCH
public static final java.lang.String OS_ARCH
The System property for the Operating system architecture.
-
JAVA_HOME
public static final java.lang.String JAVA_HOME
The System property for the Java installation directory.
-
OS_VERSION
public static final java.lang.String OS_VERSION
The System property for the Operating system version.
-
JAVA_COMPILER
public static final java.lang.String JAVA_COMPILER
The System property for the Name of JIT compiler to use.
-
JAVA_VERSION
public static final java.lang.String JAVA_VERSION
The System property for the Java Runtime Environment version.
-
JAVA_VM_SPECIFICATION_VERSION
public static final java.lang.String JAVA_VM_SPECIFICATION_VERSION
The System property for the Java Virtual Machine specification version.
-
USER_DIR
public static final java.lang.String USER_DIR
The System property for the User's current working directory.
-
JAVA_SPECIFICATION_VENDOR
public static final java.lang.String JAVA_SPECIFICATION_VENDOR
The System property for the Java Runtime Environment specification vendor.
-
JAVA_VM_SPECIFICATION_NAME
public static final java.lang.String JAVA_VM_SPECIFICATION_NAME
The System property for the Java Virtual Machine specification name.
-
JAVA_VM_VENDOR
public static final java.lang.String JAVA_VM_VENDOR
The System property for the Java Virtual Machine implementation vendor.
-
JAVA_LIBRARY_PATH
public static final java.lang.String JAVA_LIBRARY_PATH
The System property for the List of paths to search when loading libraries.
-
USER_HOME
public static final java.lang.String USER_HOME
The System property for the User's home directory.
-
JAVA_VM_NAME
public static final java.lang.String JAVA_VM_NAME
The System property for the Java Virtual Machine implementation name.
-
JAVA_VM_SPECIFICATION_VENDOR
public static final java.lang.String JAVA_VM_SPECIFICATION_VENDOR
The System property for the Java Virtual Machine specification vendor.
-
JAVA_IO_TMPDIR
public static final java.lang.String JAVA_IO_TMPDIR
The System property for the Default temp file path.
-
FILE_ENCODING
public static final java.lang.String FILE_ENCODING
The System property for the file encoding, the default is "UTF-8"
-
NATIVE_ENCODING
public static final java.lang.String NATIVE_ENCODING
The System property for the native encoding
-
IS_OS_WINDOWS
public static final boolean IS_OS_WINDOWS
Is
true
if this is Windows.The field will return
false
ifOS_NAME
isnull
.
-
IS_JAVA_8
public static final boolean IS_JAVA_8
Is
true
if this is Java 8The field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_9
public static final boolean IS_JAVA_9
Is
true
if this is Java version 9.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_10
public static final boolean IS_JAVA_10
Is
true
if this is Java version 10.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_11
public static final boolean IS_JAVA_11
Is
true
if this is Java version 11.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_12
public static final boolean IS_JAVA_12
Is
true
if this is Java version 12.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_13
public static final boolean IS_JAVA_13
Is
true
if this is Java version 13.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_14
public static final boolean IS_JAVA_14
Is
true
if this is Java version 14.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_15
public static final boolean IS_JAVA_15
Is
true
if this is Java version 15.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_16
public static final boolean IS_JAVA_16
Is
true
if this is Java version 16.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_17
public static final boolean IS_JAVA_17
Is
true
if this is Java version 17.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_18
public static final boolean IS_JAVA_18
Is
true
if this is Java version 18.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_19
public static final boolean IS_JAVA_19
Is
true
if this is Java version 19.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_20
public static final boolean IS_JAVA_20
Is
true
if this is Java version 20.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_21
public static final boolean IS_JAVA_21
Is
true
if this is Java version 21.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_22
public static final boolean IS_JAVA_22
Is
true
if this is Java version 22.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_23
public static final boolean IS_JAVA_23
Is
true
if this is Java version 23.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_JAVA_24
public static final boolean IS_JAVA_24
Is
true
if this is Java version 24.xThe field will return
false
ifJAVA_VERSION
isnull
.
-
IS_LTS_JAVA_VERSION
public static final boolean IS_LTS_JAVA_VERSION
Istrue
if current Java version is Long Term Supported(LTS)
-
-
Method Detail
-
copySystemProperties
public static void copySystemProperties()
Copies the current system properties into an internal map for later access.
This method is useful when you want to capture the system properties at a certain point in time and access them later without querying the system again. It ensures that the properties are copied in a thread-safe manner.
Example Usage
SystemUtils.copySystemProperties();
-
getSystemProperty
@Nullable public static java.lang.String getSystemProperty(java.lang.String key)
Gets a system property with the given key, defaulting to
If anull
if the property cannot be read.SecurityException
is caught, the return value isnull
and a message is written toSystem.err
.Example Usage
String javaVersion = SystemUtils.getSystemProperty("java.version");
- Parameters:
key
- the name of the system property- Returns:
- the string value of the system property, or
null
if the property is not found or access is denied
-
getSystemProperty
@Nullable public static java.lang.String getSystemProperty(java.lang.String key, java.lang.String defaultValue)
Gets a system property with the given key, defaulting to the provided
defaultValue
if the property cannot be read.If a
SecurityException
is caught while trying to access the system property, the method returns the specified default value and logs a warning message using the logger associated with this class.Example Usage
String customProperty = SystemUtils.getSystemProperty("my.custom.property", "default-value");
- Parameters:
key
- the name of the system propertydefaultValue
- the default value to return if the property is not found or access is denied- Returns:
- the string value of the system property, or the provided default value if the property is inaccessible or not found
-
resetSystemPropertiesCopy
protected static void resetSystemPropertiesCopy()
Reset thesystemPropertiesCopy
to benull
, mainly used for testing
-
getSystemPropertyFromCopy
protected static java.lang.String getSystemPropertyFromCopy(java.lang.String key)
-
-