CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-github-oshi--oshi-core

JNA-based operating system and hardware information library for Java providing cross-platform access to system metrics

Pending
Overview
Eval results
Files

system-info.mddocs/

System Information

Core entry point and platform detection for accessing system information across different operating systems.

SystemInfo Class

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();
}

Constructor

  • 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.

Methods

  • getOperatingSystem() - Creates a new instance of the appropriate platform-specific OperatingSystem implementation
  • getHardware() - Creates a new instance of the appropriate platform-specific HardwareAbstractionLayer implementation
  • getCurrentPlatform() - Static method that gets the PlatformEnum value representing the current system

PlatformEnum

Enumeration 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);
}

Constants

All supported platform constants with their friendly names:

  • MACOS - macOS
  • LINUX - Linux
  • WINDOWS - Microsoft Windows
  • SOLARIS - Solaris (SunOS)
  • FREEBSD - FreeBSD
  • OPENBSD - OpenBSD
  • WINDOWSCE - Windows Embedded Compact
  • AIX - IBM AIX
  • ANDROID - Android
  • GNU - GNU operating system
  • KFREEBSD - Debian GNU/kFreeBSD
  • NETBSD - NetBSD
  • UNKNOWN - Unspecified system

Methods

  • getName() - Gets the friendly name of the platform
  • getName(int osType) - Static method that gets the friendly name of the specified JNA Platform type
  • getValue(int osType) - Static method that gets the PlatformEnum value corresponding to the specified JNA Platform type

Usage Examples

Basic System Information

import 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();

Platform-Specific Code

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());
}

Memory Management

// 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 times

Install with Tessl CLI

npx tessl i tessl/maven-com-github-oshi--oshi-core

docs

file-system.md

hardware.md

index.md

network.md

operating-system.md

process-management.md

system-info.md

tile.json