JNA-based operating system and hardware information library for Java providing cross-platform access to system metrics
—
Core entry point and platform detection for accessing system information across different operating systems.
The SystemInfo class is the main entry point to OSHI and provides access to cross-platform hardware and software information.
class SystemInfo {
SystemInfo();
OperatingSystem getOperatingSystem();
HardwareAbstractionLayer getHardware();
static PlatformEnum getCurrentPlatform();
}SystemInfo() - Creates a new SystemInfo instance. Platform-specific Hardware and Software objects are retrieved via memoized suppliers. To conserve memory at the cost of processing time, create new instances for subsequent calls. To conserve processing time at the cost of memory, re-use the same SystemInfo object.getOperatingSystem() - Creates a new instance of the appropriate platform-specific OperatingSystem implementationgetHardware() - Creates a new instance of the appropriate platform-specific HardwareAbstractionLayer implementationgetCurrentPlatform() - Static method that gets the PlatformEnum value representing the current systemEnumeration of supported operating systems matching the osType constants in the JNA Platform class.
enum PlatformEnum {
MACOS("macOS"),
LINUX("Linux"),
WINDOWS("Windows"),
SOLARIS("Solaris"),
FREEBSD("FreeBSD"),
OPENBSD("OpenBSD"),
WINDOWSCE("Windows CE"),
AIX("AIX"),
ANDROID("Android"),
GNU("GNU"),
KFREEBSD("kFreeBSD"),
NETBSD("NetBSD"),
UNKNOWN("Unknown");
String getName();
static String getName(int osType);
static PlatformEnum getValue(int osType);
}All supported platform constants with their friendly names:
MACOS - macOSLINUX - LinuxWINDOWS - Microsoft WindowsSOLARIS - Solaris (SunOS)FREEBSD - FreeBSDOPENBSD - OpenBSDWINDOWSCE - Windows Embedded CompactAIX - IBM AIXANDROID - AndroidGNU - GNU operating systemKFREEBSD - Debian GNU/kFreeBSDNETBSD - NetBSDUNKNOWN - Unspecified systemgetName() - Gets the friendly name of the platformgetName(int osType) - Static method that gets the friendly name of the specified JNA Platform typegetValue(int osType) - Static method that gets the PlatformEnum value corresponding to the specified JNA Platform typeimport oshi.SystemInfo;
import oshi.PlatformEnum;
// Get current platform
PlatformEnum platform = SystemInfo.getCurrentPlatform();
System.out.println("Running on: " + platform.getName());
// Create SystemInfo instance
SystemInfo si = new SystemInfo();
// Access hardware and OS information
var hardware = si.getHardware();
var os = si.getOperatingSystem();import oshi.SystemInfo;
import oshi.PlatformEnum;
SystemInfo si = new SystemInfo();
PlatformEnum platform = SystemInfo.getCurrentPlatform();
switch (platform) {
case WINDOWS:
// Windows-specific logic
break;
case LINUX:
case ANDROID:
// Linux-based systems
break;
case MACOS:
// macOS-specific logic
break;
default:
// Handle other platforms
System.out.println("Platform: " + platform.getName());
}// For memory-conscious applications - create new instances
SystemInfo si1 = new SystemInfo();
var os1 = si1.getOperatingSystem();
// Use os1...
SystemInfo si2 = new SystemInfo();
var os2 = si2.getOperatingSystem();
// Use os2...
// For performance-conscious applications - reuse instances
SystemInfo si = new SystemInfo();
var os = si.getOperatingSystem();
var hardware = si.getHardware();
// Reuse si, os, hardware multiple timesInstall with Tessl CLI
npx tessl i tessl/maven-com-github-oshi--oshi-core