Code polish

This commit is contained in:
Robinson 2021-02-15 02:05:16 +01:00
parent c075333b53
commit a2887a8716

View File

@ -213,7 +213,7 @@ class OSUtil {
} }
try { try {
List<File> releaseFiles = new LinkedList<File>(); List<File> releaseFiles = new LinkedList<>();
int totalLength = 0; int totalLength = 0;
// looking for files like /etc/os-release // looking for files like /etc/os-release
@ -233,12 +233,9 @@ class OSUtil {
if (totalLength > 0) { if (totalLength > 0) {
StringBuilder fileContents = new StringBuilder(totalLength); StringBuilder fileContents = new StringBuilder(totalLength);
BufferedReader reader = null;
for (File releaseFile : releaseFiles) { for (File releaseFile : releaseFiles) {
try { try (BufferedReader reader = new BufferedReader(new FileReader(releaseFile))) {
reader = new BufferedReader(new FileReader(releaseFile));
String currentLine; String currentLine;
// NAME="Arch Linux" // NAME="Arch Linux"
@ -256,10 +253,6 @@ class OSUtil {
fileContents.append(currentLine) fileContents.append(currentLine)
.append(OS.LINE_SEPARATOR_UNIX); .append(OS.LINE_SEPARATOR_UNIX);
} }
} finally {
if (reader != null) {
reader.close();
}
} }
} }
@ -472,19 +465,12 @@ class OSUtil {
// looking for /proc/version // looking for /proc/version
File file = new File("/proc/version"); File file = new File("/proc/version");
if (file.canRead()) { if (file.canRead()) {
BufferedReader reader = null; try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
try {
reader = new BufferedReader(new FileReader(file));
// Linux version 4.4.0-19041-Microsoft (Microsoft@Microsoft.com) (gcc version 5.4.0 (GCC) ) #488-Microsoft Mon Sep 01 13:43:00 PST 2020 // Linux version 4.4.0-19041-Microsoft (Microsoft@Microsoft.com) (gcc version 5.4.0 (GCC) ) #488-Microsoft Mon Sep 01 13:43:00 PST 2020
String currentLine = reader.readLine(); String currentLine = reader.readLine();
isWSL = currentLine.contains("-Microsoft"); isWSL = currentLine.contains("-Microsoft");
} catch (Throwable ignored) { } catch (Throwable ignored) {
} finally {
if (reader != null) {
reader.close();
}
} }
} }
@ -1006,7 +992,7 @@ class OSUtil {
try { try {
// xfconf-query -c xfce4-panel -l // xfconf-query -c xfce4-panel -l
List<String> commands = new ArrayList<String>(); List<String> commands = new ArrayList<>();
commands.add("xfconf-query"); commands.add("xfconf-query");
commands.add("-c " + channel); commands.add("-c " + channel);