From a2887a87162fa27fdc5b851a07fbdd8aadbd466c Mon Sep 17 00:00:00 2001 From: Robinson Date: Mon, 15 Feb 2021 02:05:16 +0100 Subject: [PATCH] Code polish --- src/dorkbox/os/OSUtil.java | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/dorkbox/os/OSUtil.java b/src/dorkbox/os/OSUtil.java index 84614df..57671ff 100644 --- a/src/dorkbox/os/OSUtil.java +++ b/src/dorkbox/os/OSUtil.java @@ -213,7 +213,7 @@ class OSUtil { } try { - List releaseFiles = new LinkedList(); + List releaseFiles = new LinkedList<>(); int totalLength = 0; // looking for files like /etc/os-release @@ -233,12 +233,9 @@ class OSUtil { if (totalLength > 0) { StringBuilder fileContents = new StringBuilder(totalLength); - BufferedReader reader = null; for (File releaseFile : releaseFiles) { - try { - reader = new BufferedReader(new FileReader(releaseFile)); - + try (BufferedReader reader = new BufferedReader(new FileReader(releaseFile))) { String currentLine; // NAME="Arch Linux" @@ -256,10 +253,6 @@ class OSUtil { fileContents.append(currentLine) .append(OS.LINE_SEPARATOR_UNIX); } - } finally { - if (reader != null) { - reader.close(); - } } } @@ -472,19 +465,12 @@ class OSUtil { // looking for /proc/version File file = new File("/proc/version"); if (file.canRead()) { - BufferedReader reader = null; - try { - reader = new BufferedReader(new FileReader(file)); - + try (BufferedReader 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 String currentLine = reader.readLine(); isWSL = currentLine.contains("-Microsoft"); } catch (Throwable ignored) { - } finally { - if (reader != null) { - reader.close(); - } } } @@ -1006,7 +992,7 @@ class OSUtil { try { // xfconf-query -c xfce4-panel -l - List commands = new ArrayList(); + List commands = new ArrayList<>(); commands.add("xfconf-query"); commands.add("-c " + channel);