or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

file-system.mdhardware.mdindex.mdnetwork.mdoperating-system.mdprocess-management.mdsystem-info.md

system-info.mddocs/

0

# System Information

1

2

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

3

4

## SystemInfo Class

5

6

The `SystemInfo` class is the main entry point to OSHI and provides access to cross-platform hardware and software information.

7

8

```java { .api }

9

class SystemInfo {

10

SystemInfo();

11

OperatingSystem getOperatingSystem();

12

HardwareAbstractionLayer getHardware();

13

static PlatformEnum getCurrentPlatform();

14

}

15

```

16

17

### Constructor

18

19

- **`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.

20

21

### Methods

22

23

- **`getOperatingSystem()`** - Creates a new instance of the appropriate platform-specific OperatingSystem implementation

24

- **`getHardware()`** - Creates a new instance of the appropriate platform-specific HardwareAbstractionLayer implementation

25

- **`getCurrentPlatform()`** - Static method that gets the PlatformEnum value representing the current system

26

27

## PlatformEnum

28

29

Enumeration of supported operating systems matching the osType constants in the JNA Platform class.

30

31

```java { .api }

32

enum PlatformEnum {

33

MACOS("macOS"),

34

LINUX("Linux"),

35

WINDOWS("Windows"),

36

SOLARIS("Solaris"),

37

FREEBSD("FreeBSD"),

38

OPENBSD("OpenBSD"),

39

WINDOWSCE("Windows CE"),

40

AIX("AIX"),

41

ANDROID("Android"),

42

GNU("GNU"),

43

KFREEBSD("kFreeBSD"),

44

NETBSD("NetBSD"),

45

UNKNOWN("Unknown");

46

47

String getName();

48

static String getName(int osType);

49

static PlatformEnum getValue(int osType);

50

}

51

```

52

53

### Constants

54

55

All supported platform constants with their friendly names:

56

57

- **`MACOS`** - macOS

58

- **`LINUX`** - Linux

59

- **`WINDOWS`** - Microsoft Windows

60

- **`SOLARIS`** - Solaris (SunOS)

61

- **`FREEBSD`** - FreeBSD

62

- **`OPENBSD`** - OpenBSD

63

- **`WINDOWSCE`** - Windows Embedded Compact

64

- **`AIX`** - IBM AIX

65

- **`ANDROID`** - Android

66

- **`GNU`** - GNU operating system

67

- **`KFREEBSD`** - Debian GNU/kFreeBSD

68

- **`NETBSD`** - NetBSD

69

- **`UNKNOWN`** - Unspecified system

70

71

### Methods

72

73

- **`getName()`** - Gets the friendly name of the platform

74

- **`getName(int osType)`** - Static method that gets the friendly name of the specified JNA Platform type

75

- **`getValue(int osType)`** - Static method that gets the PlatformEnum value corresponding to the specified JNA Platform type

76

77

## Usage Examples

78

79

### Basic System Information

80

81

```java

82

import oshi.SystemInfo;

83

import oshi.PlatformEnum;

84

85

// Get current platform

86

PlatformEnum platform = SystemInfo.getCurrentPlatform();

87

System.out.println("Running on: " + platform.getName());

88

89

// Create SystemInfo instance

90

SystemInfo si = new SystemInfo();

91

92

// Access hardware and OS information

93

var hardware = si.getHardware();

94

var os = si.getOperatingSystem();

95

```

96

97

### Platform-Specific Code

98

99

```java

100

import oshi.SystemInfo;

101

import oshi.PlatformEnum;

102

103

SystemInfo si = new SystemInfo();

104

PlatformEnum platform = SystemInfo.getCurrentPlatform();

105

106

switch (platform) {

107

case WINDOWS:

108

// Windows-specific logic

109

break;

110

case LINUX:

111

case ANDROID:

112

// Linux-based systems

113

break;

114

case MACOS:

115

// macOS-specific logic

116

break;

117

default:

118

// Handle other platforms

119

System.out.println("Platform: " + platform.getName());

120

}

121

```

122

123

### Memory Management

124

125

```java

126

// For memory-conscious applications - create new instances

127

SystemInfo si1 = new SystemInfo();

128

var os1 = si1.getOperatingSystem();

129

// Use os1...

130

131

SystemInfo si2 = new SystemInfo();

132

var os2 = si2.getOperatingSystem();

133

// Use os2...

134

135

// For performance-conscious applications - reuse instances

136

SystemInfo si = new SystemInfo();

137

var os = si.getOperatingSystem();

138

var hardware = si.getHardware();

139

// Reuse si, os, hardware multiple times

140

```