From 075c802fada1793e28f4180ebe30eab56618c7d5 Mon Sep 17 00:00:00 2001 From: hecy7 Date: Fri, 8 Sep 2023 14:05:03 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=BC=BA=E5=A4=B1=E6=B3=A8=E8=A7=A3@Overri?= =?UTF-8?q?de=E8=A1=A5=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hecy7 --- .../com/taobao/arthas/core/command/monitor200/ThreadSampler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/ThreadSampler.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/ThreadSampler.java index 91fade566d3..ee75954a7a2 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/ThreadSampler.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/ThreadSampler.java @@ -124,6 +124,7 @@ public int compare(ThreadVO o1, ThreadVO o2) { // Sort by CPU time : should be a rendering hint... Collections.sort(threads, new Comparator() { + @Override public int compare(ThreadVO o1, ThreadVO o2) { long l1 = deltas.get(o1); long l2 = deltas.get(o2); From bd2bb36205cc6f231ca5367d5362296611c48e29 Mon Sep 17 00:00:00 2001 From: hecy7 Date: Mon, 11 Dec 2023 11:28:01 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=99=A8=E4=BC=9A?= =?UTF-8?q?=E5=81=9A=E7=B1=BB=E5=9E=8B=E6=8E=A8=E6=96=AD=EF=BC=8C=E6=97=A0?= =?UTF-8?q?=E9=9C=80=E6=98=BE=E7=A4=BA=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hecy7 --- core/src/main/java/com/taobao/arthas/core/util/FileUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java b/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java index ec046468cf2..c118a68b66f 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java +++ b/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java @@ -140,7 +140,7 @@ public static void saveCommandHistory(List history, File file) { public static List loadCommandHistory(File file) { BufferedReader br = null; - List history = new ArrayList(); + List history = new ArrayList<>(); try { br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); String line; @@ -194,7 +194,7 @@ public static void saveCommandHistoryString(List history, File file) { public static List loadCommandHistoryString(File file) { BufferedReader br = null; - List history = new ArrayList(); + List history = new ArrayList<>(); try { br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8")); String line; From a8f4900d08968df50ba63cab63e39731b53a1dc5 Mon Sep 17 00:00:00 2001 From: hecy7 Date: Mon, 11 Dec 2023 11:33:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?try=E5=9D=97=E9=87=87=E7=94=A8try-with-reso?= =?UTF-8?q?urce=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hecy7 --- .../taobao/arthas/core/util/FileUtils.java | 49 ++++--------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java b/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java index c118a68b66f..ac66a1cd49a 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java +++ b/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java @@ -42,20 +42,10 @@ public static void writeByteArrayToFile(File file, byte[] data) throws IOExcepti * @since IO 2.1 */ public static void writeByteArrayToFile(File file, byte[] data, boolean append) throws IOException { - OutputStream out = null; - try { - out = openOutputStream(file, append); + try (OutputStream out = openOutputStream(file, append)) { out.write(data); - out.close(); // don't swallow close Exception if copy completes normally - } finally { - try { - if (out != null) { - out.close(); - } - } catch (IOException ioe) { - // ignore - } } + // ignore } /** @@ -111,10 +101,8 @@ private static boolean isAuthCommand(String command) { * @param file the file to save the history */ public static void saveCommandHistory(List history, File file) { - OutputStream out = null; - try { - out = new BufferedOutputStream(openOutputStream(file, false)); - for (int[] command: history) { + try (OutputStream out = new BufferedOutputStream(openOutputStream(file, false))) { + for (int[] command : history) { String commandStr = Helper.fromCodePoints(command); if (isAuthCommand(commandStr)) { command = AUTH_CODEPOINTS; @@ -127,15 +115,8 @@ public static void saveCommandHistory(List history, File file) { } } catch (IOException e) { // ignore - } finally { - try { - if (out != null) { - out.close(); - } - } catch (IOException ioe) { - // ignore - } } + // ignore } public static List loadCommandHistory(File file) { @@ -167,10 +148,8 @@ public static List loadCommandHistory(File file) { * @param file the file to save the history */ public static void saveCommandHistoryString(List history, File file) { - OutputStream out = null; - try { - out = new BufferedOutputStream(openOutputStream(file, false)); - for (String command: history) { + try (OutputStream out = new BufferedOutputStream(openOutputStream(file, false))) { + for (String command : history) { if (!StringUtils.isBlank(command)) { if (isAuthCommand(command)) { command = ArthasConstants.AUTH; @@ -181,15 +160,8 @@ public static void saveCommandHistoryString(List history, File file) { } } catch (IOException e) { // ignore - } finally { - try { - if (out != null) { - out.close(); - } - } catch (IOException ioe) { - // ignore - } } + // ignore } public static List loadCommandHistoryString(File file) { @@ -218,8 +190,7 @@ public static List loadCommandHistoryString(File file) { } public static String readFileToString(File file, Charset encoding) throws IOException { - FileInputStream stream = new FileInputStream(file); - try { + try (FileInputStream stream = new FileInputStream(file)) { Reader reader = new BufferedReader(new InputStreamReader(stream, encoding)); StringBuilder builder = new StringBuilder(); char[] buffer = new char[8192]; @@ -228,8 +199,6 @@ public static String readFileToString(File file, Charset encoding) throws IOExce builder.append(buffer, 0, read); } return builder.toString(); - } finally { - stream.close(); } }