Package org.daiitech.naftah.utils
Class OS
java.lang.Object
org.daiitech.naftah.utils.OS
Utility class for detecting the current operating system's properties,
including name, architecture, version, and system family.
Provides a set of static methods for querying the current environment, particularly useful for platform-specific behavior.
This class is not instantiable.
Examples:
if (OS.isFamilyWindows()) {
// Windows-specific logic
}
Internally uses System.getProperty and lowercase matching.
- Author:
- Chakib Daii
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringIdentifier for DOS family.private static final StringIdentifier for Mac family.private static final StringIdentifier for NetWare family.private static final StringIdentifier for OpenVMS family.private static final StringIdentifier for OS/2 family.private static final StringIdentifier for OS/400 family.private static final StringIdentifier for Tandem family.private static final StringIdentifier for Unix family.private static final StringIdentifier for Windows 9x family (legacy Windows).private static final StringIdentifier for Windows family.private static final StringIdentifier for z/OS family.private static final booleanWhether the current OS is running under Windows Subsystem for Linux (WSL).private static final booleanWhether the current terminal is a real XTerm instance.private static final StringThe OS architecture in lowercase, retrieved from system properties.static final StringSystem property key for the operating system architecture.private static final StringThe OS name in lowercase, retrieved from system properties.static final StringSystem property key for the operating system name.private static final StringThe OS version in lowercase, retrieved from system properties.static final StringSystem property key for the operating system version.private static final StringThe system path separator character(s).static final StringTerminal type identifier provided via terminfo (often misleading).static final StringWSL environment variable containing the current Linux distribution name.static final StringWSL-specific environment variable controlling Windows–Linux env propagation.static final StringWSL environment variable used for Windows–Linux process interop.static final StringSet only by real xterm to expose its version and identify the emulator. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleanDetects whether the JVM is running inside a real XTerm terminal.private static booleanDetects whether the JVM is running inside Windows Subsystem for Linux (WSL).static booleanChecks whether the current OS architecture matches the given arch exactly.private static booleanChecks if the current OS matches the specified family.static booleanChecks if the current OS belongs to the DOS family.static booleanChecks if the current OS belongs to the Mac family.static booleanChecks if the current OS belongs to the NetWare family.static booleanChecks if the current OS belongs to the OpenVMS family.static booleanChecks if the current OS belongs to the OS/2 family.static booleanChecks if the current OS belongs to the OS/400 family.static booleanChecks if the current OS belongs to the Tandem family.static booleanChecks if the current OS belongs to the Unix family.static booleanChecks if the current OS belongs to the legacy Windows 9x family.static booleanChecks if the current OS belongs to the Windows family.static booleanChecks if the current OS belongs to the z/OS family.static booleanChecks whether the current OS name matches the given name exactly.static booleanChecks whether the current OS matches a combination of criteria.static booleanChecks whether the current terminal is a real XTerm instance.static booleanChecks whether the current OS version matches the given version exactly.static booleanisWSL()Checks whether the current OS is running under Windows Subsystem for Linux (WSL).
-
Field Details
-
OS_NAME_PROPERTY
System property key for the operating system name.- See Also:
-
OS_ARCH_PROPERTY
System property key for the operating system architecture.- See Also:
-
OS_VERSION_PROPERTY
System property key for the operating system version.- See Also:
-
WSL_DISTRO_NAME_ENV
WSL environment variable containing the current Linux distribution name.- See Also:
-
WSL_INTEROP_ENV
WSL environment variable used for Windows–Linux process interop.- See Also:
-
WSL_ENV
WSL-specific environment variable controlling Windows–Linux env propagation.- See Also:
-
TERM_ENV
Terminal type identifier provided via terminfo (often misleading).- See Also:
-
XTERM_VERSION_ENV
Set only by real xterm to expose its version and identify the emulator.- See Also:
-
FAMILY_OS_400
Identifier for OS/400 family.- See Also:
-
FAMILY_Z_OS
Identifier for z/OS family.- See Also:
-
FAMILY_WIN9X
Identifier for Windows 9x family (legacy Windows).- See Also:
-
FAMILY_OPENVMS
Identifier for OpenVMS family.- See Also:
-
FAMILY_UNIX
Identifier for Unix family.- See Also:
-
FAMILY_TANDEM
Identifier for Tandem family.- See Also:
-
FAMILY_MAC
Identifier for Mac family.- See Also:
-
FAMILY_DOS
Identifier for DOS family.- See Also:
-
FAMILY_NETWARE
Identifier for NetWare family.- See Also:
-
FAMILY_OS_2
Identifier for OS/2 family.- See Also:
-
FAMILY_WINDOWS
Identifier for Windows family.- See Also:
-
IS_WSL
private static final boolean IS_WSLWhether the current OS is running under Windows Subsystem for Linux (WSL). -
IS_XTERM
private static final boolean IS_XTERMWhether the current terminal is a real XTerm instance. -
OS_NAME
The OS name in lowercase, retrieved from system properties. -
OS_ARCH
The OS architecture in lowercase, retrieved from system properties. -
OS_VERSION
The OS version in lowercase, retrieved from system properties. -
PATH_SEP
The system path separator character(s).
-
-
Constructor Details
-
OS
private OS()Private constructor to prevent instantiation. Always throws aNaftahBugErrorwhen called.
-
-
Method Details
-
checkIfInsideWSL
private static boolean checkIfInsideWSL()Detects whether the JVM is running inside Windows Subsystem for Linux (WSL).Checks environment variables first, then falls back to inspecting the kernel version in /proc/version for "Microsoft".
- Returns:
- true if running inside WSL, false otherwise
-
checkIfInsideRealXTerm
private static boolean checkIfInsideRealXTerm()Detects whether the JVM is running inside a real XTerm terminal.Relies on TERM and XTERM_VERSION environment variables to distinguish XTerm from other terminal emulators (like GNOME Terminal or Kitty).
- Returns:
- true if running inside XTerm, false otherwise
-
isFamily
Checks if the current OS matches the specified family.- Parameters:
family- the OS family name to check- Returns:
- true if current OS belongs to that family
-
isFamilyDOS
public static boolean isFamilyDOS()Checks if the current OS belongs to the DOS family.- Returns:
trueif the OS is in the DOS family,falseotherwise.
-
isFamilyMac
public static boolean isFamilyMac()Checks if the current OS belongs to the Mac family.- Returns:
trueif the OS is in the Mac family,falseotherwise.
-
isFamilyNetware
public static boolean isFamilyNetware()Checks if the current OS belongs to the NetWare family.- Returns:
trueif the OS is in the NetWare family,falseotherwise.
-
isFamilyOS2
public static boolean isFamilyOS2()Checks if the current OS belongs to the OS/2 family.- Returns:
trueif the OS is in the OS/2 family,falseotherwise.
-
isFamilyTandem
public static boolean isFamilyTandem()Checks if the current OS belongs to the Tandem family.- Returns:
trueif the OS is in the Tandem family,falseotherwise.
-
isFamilyUnix
public static boolean isFamilyUnix()Checks if the current OS belongs to the Unix family.- Returns:
trueif the OS is in the Unix family,falseotherwise.
-
isFamilyWindows
public static boolean isFamilyWindows()Checks if the current OS belongs to the Windows family.- Returns:
trueif the OS is in the Windows family,falseotherwise.
-
isWSL
public static boolean isWSL()Checks whether the current OS is running under Windows Subsystem for Linux (WSL).- Returns:
trueif running in WSL,falseotherwise
-
isRealXTerm
public static boolean isRealXTerm()Checks whether the current terminal is a real XTerm instance.- Returns:
trueif running inside XTerm,falseotherwise
-
isFamilyWin9x
public static boolean isFamilyWin9x()Checks if the current OS belongs to the legacy Windows 9x family.- Returns:
trueif the OS is in the Windows 9x family,falseotherwise.
-
isFamilyZOS
public static boolean isFamilyZOS()Checks if the current OS belongs to the z/OS family.- Returns:
trueif the OS is in the z/OS family,falseotherwise.
-
isFamilyOS400
public static boolean isFamilyOS400()Checks if the current OS belongs to the OS/400 family.- Returns:
trueif the OS is in the OS/400 family,falseotherwise.
-
isFamilyOpenVms
public static boolean isFamilyOpenVms()Checks if the current OS belongs to the OpenVMS family.- Returns:
trueif the OS is in the OpenVMS family,falseotherwise.
-
isName
Checks whether the current OS name matches the given name exactly.- Parameters:
name- the OS name to check- Returns:
- true if matched
-
isArch
Checks whether the current OS architecture matches the given arch exactly.- Parameters:
arch- the architecture string to match- Returns:
- true if matched
-
isVersion
Checks whether the current OS version matches the given version exactly.- Parameters:
version- the OS version to check- Returns:
- true if matched
-
isOs
Checks whether the current OS matches a combination of criteria. Anynullparameter is ignored in the match.- Parameters:
family- the OS family name (e.g., "windows")name- the OS name (e.g., "Windows 10")arch- the architecture (e.g., "x86_64")version- the version (e.g., "10.0")- Returns:
- true if all specified parameters match the current system
- Throws:
NaftahBugError- if an unknown family is passed
-