1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package oshi.software.os.linux;
18
19 import java.io.FileNotFoundException;
20 import java.io.FileReader;
21 import java.util.Scanner;
22
23 import oshi.software.os.OperatingSystem;
24 import oshi.software.os.OperatingSystemVersion;
25 import oshi.software.os.linux.proc.OSVersionInfoEx;
26
27
28
29
30
31
32
33 public class LinuxOperatingSystem implements OperatingSystem {
34
35 private OperatingSystemVersion _version = null;
36 private String _family = null;
37
38 @Override
39 public String getFamily() {
40 if (this._family == null) {
41 try (final Scanner in = new Scanner(new FileReader("/etc/os-release"))) {
42 in.useDelimiter("\n");
43 while (in.hasNext()) {
44 String[] splittedLine = in.next().split("=");
45 if (splittedLine[0].equals("NAME")) {
46
47
48 this._family = splittedLine[1].replaceAll("^\"|\"$", "");
49 break;
50 }
51 }
52 } catch (FileNotFoundException e) {
53 return "";
54 }
55 }
56 return this._family;
57 }
58
59 @Override
60 public String getManufacturer() {
61 return "GNU/Linux";
62 }
63
64 @Override
65 public OperatingSystemVersion getVersion() {
66 if (this._version == null) {
67 this._version = new OSVersionInfoEx();
68 }
69 return this._version;
70 }
71
72 @Override
73 public String toString() {
74 StringBuilder sb = new StringBuilder();
75 sb.append(getManufacturer());
76 sb.append(" ");
77 sb.append(getFamily());
78 sb.append(" ");
79 sb.append(getVersion().toString());
80 return sb.toString();
81 }
82 }