diff --git a/src/intellij_plugin/cmake2gn/gn_IntelliJ_plugin/src/com/sk/gn/dialog/GenDialogPane.java b/src/intellij_plugin/cmake2gn/gn_IntelliJ_plugin/src/com/sk/gn/dialog/GenDialogPane.java index 7d9a65c0c51abc4244640dd33c214fb81449f459..c526013649d3a01058a673d3657146721d369a47 100644 --- a/src/intellij_plugin/cmake2gn/gn_IntelliJ_plugin/src/com/sk/gn/dialog/GenDialogPane.java +++ b/src/intellij_plugin/cmake2gn/gn_IntelliJ_plugin/src/com/sk/gn/dialog/GenDialogPane.java @@ -422,20 +422,41 @@ public class GenDialogPane extends JDialog implements SelectOutDirAction.SelectP * @param process 进程ID */ private void genResultLog(Process process) { - BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); - BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream())); - String sErr = ''; - String sOut; - sErr = getErrorResult(stdError); - if (TextUtils.isEmpty(sErr)) { - sOut = genInputLog(stdInput); - if (!generateIsSuccess(sOut)) { - sErrorMessage = sOut; + BufferedReader stdInput = null; + BufferedReader stdError = null; + try { + stdInput = new BufferedReader(new InputStreamReader(process.getInputStream(), + StandardCharsets.UTF_8)); + stdError = new BufferedReader(new InputStreamReader(process.getErrorStream(), + StandardCharsets.UTF_8)); + String sErr = ''; + String sOut; + sErr = getErrorResult(stdError); + if (TextUtils.isEmpty(sErr)) { + sOut = genInputLog(stdInput); + if (!generateIsSuccess(sOut)) { + sErrorMessage = sOut; + } + } else { + generateSuccess = false; + sErrorMessage = sErr; + } + } catch (IOException e) { + // Handle exception + LOG.error(e); + } finally { + // Close resources in finally block to ensure they are closed even if an exception occurs + try { + stdInput.close(); + } catch (IOException e) { + LOG.error(e); + } + try { + stdError.close(); + } catch (IOException e) { + LOG.error(e); } - return; } - generateSuccess = false; - sErrorMessage = sErr; } /** @@ -505,15 +526,29 @@ public class GenDialogPane extends JDialog implements SelectOutDirAction.SelectP @Override public void run() { + InputStreamReader isr1 = null; + BufferedReader br1 = null; try { - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); + isr1 = new InputStreamReader(is, StandardCharsets.UTF_8); + br1 = new BufferedReader(isr1); String line; - while ((line = br.readLine()) != null) { + while ((line = br1.readLine()) != null) { LOG.error("StreamConsumer" + line); } } catch (IOException ioException) { LOG.error("StreamConsumer io error" + ioException); + } finally { + // 确保BufferedReader br1和InputStreamReader isr1被关闭 + try { + br1.close(); + } catch (IOException e) { + LOG.error(e); + } + try { + isr1.close(); + } catch (IOException e) { + LOG.error(e); + } } } } @@ -532,14 +567,24 @@ public class GenDialogPane extends JDialog implements SelectOutDirAction.SelectP @Override public void run() { - BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); - genResultLog(process); + BufferedReader br1 = null; try { - while (br.readLine() != null) { + br1 = new BufferedReader(new InputStreamReader(process.getInputStream(), + StandardCharsets.UTF_8)); + genResultLog(process); + while (br1.readLine() != null) { LOG.info(" callExtProcess "); } } catch (IOException ioException) { LOG.error(" callExtProcess error" + ioException); + } finally { + // 确保BufferedReader br1被关闭 + try { + br1.close(); + } catch (IOException e) { + // 处理关闭BufferedReader时的异常 + LOG.error(e); + } } } } diff --git a/src/intellij_plugin/cmake2gn/gn_IntelliJ_plugin/src/com/sk/gn/utils/FileUtil.java b/src/intellij_plugin/cmake2gn/gn_IntelliJ_plugin/src/com/sk/gn/utils/FileUtil.java index 66c86d115fbb6db09acb713c79e0f21fe5f9eb16..17165ed9069c9be5d89f6731b4b313433f36640c 100644 --- a/src/intellij_plugin/cmake2gn/gn_IntelliJ_plugin/src/com/sk/gn/utils/FileUtil.java +++ b/src/intellij_plugin/cmake2gn/gn_IntelliJ_plugin/src/com/sk/gn/utils/FileUtil.java @@ -152,6 +152,7 @@ public class FileUtil { */ public static void writeTmpFile(String path, String oldPath, Project project) { File file = new File(path); + FileOutputStream fw = null ; try (InputStream inputStream = FileUtil.class.getClassLoader().getResourceAsStream(oldPath)) { if (inputStream == null) { throw new IOException("exec File InputStream is Null"); @@ -162,13 +163,18 @@ public class FileUtil { if (!isNewFile) { LOG.info("writeTmpFile createNewFile error"); } - FileOutputStream fw = new FileOutputStream(file); + fw = new FileOutputStream(file); fw.write(bs, 0, bs.length); - fw.close(); } catch (IOException e) { GenNotification.notifyMessage(project, e.getMessage(), "Can not Find File:" + oldPath, NotificationType.ERROR); LOG.error(e); + } finally { + try { + fw.close(); + } catch (IOException e) { + LOG.error("Error closing FileOutputStream", e); + } } } } diff --git a/src/intellij_plugin/dts2cpp/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialogPane.java b/src/intellij_plugin/dts2cpp/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialogPane.java index d3c781bfbe71cf77cf7593739bf3e54033c17327..8064446926712e8475463b6c864357a82dd9e9be 100644 --- a/src/intellij_plugin/dts2cpp/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialogPane.java +++ b/src/intellij_plugin/dts2cpp/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialogPane.java @@ -568,15 +568,26 @@ public class GenerateDialogPane extends JDialog { */ private void writeTmpFile(String path, byte[] bs) throws IOException { File file = new File(path); + FileOutputStream fw = null; if (!file.exists()) { boolean isNewFile = file.createNewFile(); if (!isNewFile) { LOG.info("writeTmpFile createNewFile error"); } } - FileOutputStream fw = new FileOutputStream(file); - fw.write(bs, 0, bs.length); - fw.close(); + try { + fw = new FileOutputStream(file); + fw.write(bs, 0, bs.length); + } catch (IOException e) { + // 处理可能发生的IOException + LOG.error("Error reading from process streams", e); + } finally { + try { + fw.close(); + } catch (IOException e) { + LOG.error("Error closing stdInput", e); + } + } } /** @@ -585,20 +596,41 @@ public class GenerateDialogPane extends JDialog { * @param process 进程ID */ private void genResultLog(Process process) { - BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); - BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream())); - String sErr; - String sOut; - sErr = getErrorResult(stdError); - if (TextUtils.isEmpty(sErr)) { - sOut = genInputLog(stdInput); - if (!generateIsSuccess(sOut)) { - sErrorMessage = sOut; + BufferedReader stdInput = null; + BufferedReader stdError = null; + try { + stdInput = new BufferedReader(new InputStreamReader(process.getInputStream(), + StandardCharsets.UTF_8)); + stdError = new BufferedReader(new InputStreamReader(process.getErrorStream(), + StandardCharsets.UTF_8)); + String sErr; + String sOut; + sErr = getErrorResult(stdError); + if (TextUtils.isEmpty(sErr)) { + sOut = genInputLog(stdInput); + if (!generateIsSuccess(sOut)) { + sErrorMessage = sOut; + } + } else { + generateSuccess = false; + sErrorMessage = sErr; + } + } catch (IOException e) { + // 处理可能发生的IOException + LOG.error("Error reading from process streams", e); + } finally { + // 确保BufferedReader对象被关闭 + try { + stdInput.close(); + } catch (IOException e) { + LOG.error("Error closing stdInput", e); + } + try { + stdError.close(); + } catch (IOException e) { + LOG.error("Error closing stdError", e); } - return; } - generateSuccess = false; - sErrorMessage = sErr; } /** @@ -660,15 +692,29 @@ public class GenerateDialogPane extends JDialog { @Override public void run() { + InputStreamReader isr2 = null; + BufferedReader br2 = null; try { - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); + isr2 = new InputStreamReader(is, StandardCharsets.UTF_8); + br2 = new BufferedReader(isr2); String line; - while ((line = br.readLine()) != null) { + while ((line = br2.readLine()) != null) { LOG.error("StreamConsumer" + line); } } catch (IOException ioException) { LOG.error("StreamConsumer io error" + ioException); + } finally { + // 确保BufferedReader和InputStreamReader被关闭 + try { + br2.close(); + } catch (IOException e) { + LOG.error(e); + } + try { + isr2.close(); + } catch (IOException e) { + LOG.error(e); + } } } } diff --git a/src/intellij_plugin/h2dts/ts_IntelliJ_plugin/src/com/sk/ts/dialog/GenerateDialogPane.java b/src/intellij_plugin/h2dts/ts_IntelliJ_plugin/src/com/sk/ts/dialog/GenerateDialogPane.java index 676c9d6798f496e04db25cacf4f4966f091be96b..af527b76f1e86963939491277882208755bcf997 100644 --- a/src/intellij_plugin/h2dts/ts_IntelliJ_plugin/src/com/sk/ts/dialog/GenerateDialogPane.java +++ b/src/intellij_plugin/h2dts/ts_IntelliJ_plugin/src/com/sk/ts/dialog/GenerateDialogPane.java @@ -314,15 +314,26 @@ public class GenerateDialogPane extends JDialog { */ private void writeTmpFile(String path, byte[] bs) throws IOException { File file = new File(path); + FileOutputStream fw = null; if (!file.exists()) { boolean isNewFile = file.createNewFile(); if (!isNewFile) { LOG.info("writeTmpFile createNewFile error"); } } - FileOutputStream fw = new FileOutputStream(file); - fw.write(bs, 0, bs.length); - fw.close(); + try { + fw = new FileOutputStream(file); + fw.write(bs, 0, bs.length); + } catch (IOException e) { + // 处理可能发生的IOException + LOG.error("Error reading from process streams", e); + } finally { + try { + fw.close(); + } catch (IOException e) { + LOG.error("Error closing stdInput", e); + } + } } /** @@ -331,20 +342,41 @@ public class GenerateDialogPane extends JDialog { * @param process 进程ID */ private void genResultLog(Process process) { - BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); - BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream())); - String sErr; - String sOut; - sErr = getErrorResult(stdError); - if (TextUtils.isEmpty(sErr)) { - sOut = genInputLog(stdInput); - if (!generateIsSuccess(sOut)) { - sErrorMessage = sOut; + BufferedReader stdInput = null; + BufferedReader stdError = null; + try { + stdInput = new BufferedReader(new InputStreamReader(process.getInputStream(), + StandardCharsets.UTF_8)); + stdError = new BufferedReader(new InputStreamReader(process.getErrorStream(), + StandardCharsets.UTF_8)); + String sErr; + String sOut; + sErr = getErrorResult(stdError); + if (TextUtils.isEmpty(sErr)) { + sOut = genInputLog(stdInput); + if (!generateIsSuccess(sOut)) { + sErrorMessage = sOut; + } + } else { + generateSuccess = false; + sErrorMessage = sErr; + } + } catch (IOException e) { + // 处理可能发生的IOException + LOG.error("Error in genResultLog", e); + } finally { + // 确保BufferedReader对象被关闭 + try { + stdInput.close(); + } catch (IOException e) { + LOG.error("Error closing stdInput", e); // 记录关闭stdInput时的错误 + } + try { + stdError.close(); + } catch (IOException e) { + LOG.error("Error closing stdError", e); // 记录关闭stdError时的错误 } - return; } - generateSuccess = false; - sErrorMessage = sErr; } /** @@ -406,15 +438,29 @@ public class GenerateDialogPane extends JDialog { @Override public void run() { + InputStreamReader inputStreamReader = null; + BufferedReader bufferedReader = null; try { - InputStreamReader inputStreamReader = new InputStreamReader(is); - BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + inputStreamReader = new InputStreamReader(is, StandardCharsets.UTF_8); + bufferedReader = new BufferedReader(inputStreamReader); String readLine; while ((readLine = bufferedReader.readLine()) != null) { LOG.error("StreamConsumer" + readLine); } } catch (IOException ioException) { LOG.error("StreamConsumer io error" + ioException); + } finally { + // 确保BufferedReader和InputStreamReader被关闭 + try { + bufferedReader.close(); + } catch (IOException e) { + LOG.error("Error closing BufferedReader", e); + } + try { + inputStreamReader.close(); + } catch (IOException e) { + LOG.error("Error closing inputStreamReader", e); + } } } } diff --git a/src/intellij_plugin/h2dtscpp/native_IntelliJ_plugin/src/com/sk/na/ng/GenDTS.java b/src/intellij_plugin/h2dtscpp/native_IntelliJ_plugin/src/com/sk/na/ng/GenDTS.java index 52384d934c4efd39cab0e48b512c122dcff9f276..e06b136a407c46d4ff9cec0273584305c29bc884 100644 --- a/src/intellij_plugin/h2dtscpp/native_IntelliJ_plugin/src/com/sk/na/ng/GenDTS.java +++ b/src/intellij_plugin/h2dtscpp/native_IntelliJ_plugin/src/com/sk/na/ng/GenDTS.java @@ -92,21 +92,40 @@ public class GenDts extends AnAction { * @param process 进程ID */ private void genResultLog(Process process) { - BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getErrorStream(), + BufferedReader stdInput = null; + BufferedReader stdError = null; + try { + stdInput = new BufferedReader(new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8)); - BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream(), + stdError = new BufferedReader(new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8)); - String sErr = getErrorResult(stdError); - String sOut; - if (TextUtils.isEmpty(sErr)) { - sOut = genInputLog(stdInput); - if (!generateIsSuccess(sOut)) { - sErrorMessage = sOut; + String sErr = getErrorResult(stdError); + String sOut; + if (TextUtils.isEmpty(sErr)) { + sOut = genInputLog(stdInput); + if (!generateIsSuccess(sOut)) { + sErrorMessage = sOut; + } + } else { + generateSuccess = false; + sErrorMessage = sErr; + } + } catch (IOException e) { + // Handle exception + LOG.error(e); + } finally { + // Close resources in finally block to ensure they are closed even if an exception occurs + try { + stdInput.close(); + } catch (IOException e) { + LOG.error(e); + } + try { + stdError.close(); + } catch (IOException e) { + LOG.error(e); } - return; } - generateSuccess = false; - sErrorMessage = sErr; } /** @@ -177,15 +196,29 @@ public class GenDts extends AnAction { @Override public void run() { + InputStreamReader isr3 = null; + BufferedReader br3 = null; try { - InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); - BufferedReader br = new BufferedReader(isr); + isr3 = new InputStreamReader(is, StandardCharsets.UTF_8); + br3 = new BufferedReader(isr3); String line; - while ((line = br.readLine()) != null) { + while ((line = br3.readLine()) != null) { LOG.error("StreamConsumer" + line); } } catch (IOException ioException) { LOG.error("StreamConsumer io error" + ioException); + } finally { + // 确保BufferedReader br3和InputStreamReader isr3被关闭 + try { + br3.close(); + } catch (IOException e) { + LOG.error(e); + } + try { + isr3.close(); + } catch (IOException e) { + LOG.error(e); + } } } } @@ -234,15 +267,26 @@ public class GenDts extends AnAction { */ private void writeTmpFile(String path, byte[] bs) throws IOException { File file = new File(path); + FileOutputStream fw = null; if (!file.exists()) { boolean isNewFile = file.createNewFile(); if (!isNewFile) { LOG.info("writeTmpFile createNewFile error"); } } - FileOutputStream fw = new FileOutputStream(file); - fw.write(bs, 0, bs.length); - fw.close(); + try { + fw = new FileOutputStream(file); + fw.write(bs, 0, bs.length); + } catch (IOException e) { + // 处理可能发生的IOException + LOG.error("Error reading from process streams", e); + } finally { + try { + fw.close(); + } catch (IOException e) { + LOG.error("Error closing stdInput", e); + } + } } /** diff --git a/src/intellij_plugin/h2sa/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialogPane.java b/src/intellij_plugin/h2sa/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialogPane.java index 39b0931ceb7bcf639df7559a0f4d5205dbdd5b45..9a6047230634bf01144ff3dbfe42a22f7ac33c08 100644 --- a/src/intellij_plugin/h2sa/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialogPane.java +++ b/src/intellij_plugin/h2sa/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialogPane.java @@ -278,15 +278,26 @@ public class ServiceGenerateDialogPane extends JDialog { */ private void writeTmpFile(String path, byte[] bs) throws IOException { File file = new File(path); + FileOutputStream fw = null; if (!file.exists()) { boolean isNewFile = file.createNewFile(); if (!isNewFile) { LOG.info("writeTmpFile createNewFile error"); } } - FileOutputStream fw = new FileOutputStream(file); - fw.write(bs, 0, bs.length); - fw.close(); + try { + fw = new FileOutputStream(file); + fw.write(bs, 0, bs.length); + } catch (IOException e) { + // 处理可能发生的IOException + LOG.error("Error reading from process streams", e); + } finally { + try { + fw.close(); + } catch (IOException e) { + LOG.error("Error closing stdInput", e); + } + } } /** @@ -295,20 +306,41 @@ public class ServiceGenerateDialogPane extends JDialog { * @param process 进程ID */ private void genResultLog(Process process) { - BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); - BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream())); - String sErr; - String sOut; - sErr = getErrorResult(stdError); - if (TextUtils.isEmpty(sErr)) { - sOut = genInputLog(stdInput); - if (!generateIsSuccess(sOut)) { - sErrorMessage = sOut; + BufferedReader stdInput = null; + BufferedReader stdError = null; + try { + stdInput = new BufferedReader(new InputStreamReader(process.getInputStream(), + StandardCharsets.UTF_8)); + stdError = new BufferedReader(new InputStreamReader(process.getErrorStream(), + StandardCharsets.UTF_8)); + String sErr; + String sOut; + sErr = getErrorResult(stdError); + if (TextUtils.isEmpty(sErr)) { + sOut = genInputLog(stdInput); + if (!generateIsSuccess(sOut)) { + sErrorMessage = sOut; + } + } else { + generateSuccess = false; + sErrorMessage = sErr; + } + } catch (IOException e) { + // Handle exception + LOG.error(e); + } finally { + // Close resources in finally block to ensure they are closed even if an exception occurs + try { + stdInput.close(); + } catch (IOException e) { + LOG.error(e); + } + try { + stdError.close(); + } catch (IOException e) { + LOG.error(e); } - return; } - generateSuccess = false; - sErrorMessage = sErr; } /** @@ -370,15 +402,29 @@ public class ServiceGenerateDialogPane extends JDialog { @Override public void run() { + InputStreamReader isr4 = null; + BufferedReader br4 = null; try { - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); + isr4 = new InputStreamReader(is, StandardCharsets.UTF_8); + br4 = new BufferedReader(isr4); String line; - while ((line = br.readLine()) != null) { + while ((line = br4.readLine()) != null) { LOG.error("StreamConsumer" + line); } } catch (IOException ioException) { LOG.error("StreamConsumer io error" + ioException); + } finally { + // 确保BufferedReader br4和InputStreamReader isr4被关闭 + try { + br4.close(); + } catch (IOException e) { + LOG.error(e); + } + try { + isr4.close(); + } catch (IOException e) { + LOG.error(e); + } } } } diff --git a/src/tool/api/api_scan_IntelliJ_plugin/src/com/kh/scan/dialog/ApiScanDialogPane.java b/src/tool/api/api_scan_IntelliJ_plugin/src/com/kh/scan/dialog/ApiScanDialogPane.java index 796f03238f3531be7170d7e2ff44a073d75ffcab..a6fe6a0402dad171b803c2dfa6c6c8e560db2b35 100644 --- a/src/tool/api/api_scan_IntelliJ_plugin/src/com/kh/scan/dialog/ApiScanDialogPane.java +++ b/src/tool/api/api_scan_IntelliJ_plugin/src/com/kh/scan/dialog/ApiScanDialogPane.java @@ -272,15 +272,26 @@ public class ApiScanDialogPane extends JDialog { */ private void writeTmpFile(String path, byte[] bs) throws IOException { File file = new File(path); + FileOutputStream fw = null; if (!file.exists()) { boolean isNewFile = file.createNewFile(); if (!isNewFile) { LOG.info("writeTmpFile createNewFile error"); } } - FileOutputStream fw = new FileOutputStream(file); - fw.write(bs, 0, bs.length); - fw.close(); + try { + fw = new FileOutputStream(file); + fw.write(bs, 0, bs.length); + } catch (IOException e) { + // 处理可能发生的IOException + LOG.error("Error reading from process streams", e); + } finally { + try { + fw.close(); + } catch (IOException e) { + LOG.error("Error closing stdInput", e); + } + } } /** @@ -289,20 +300,41 @@ public class ApiScanDialogPane extends JDialog { * @param process 进程ID */ private void genResultLog(Process process) { - BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream())); - BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream())); - String sErr; - String sOut; - sErr = getErrorResult(stdError); - if (TextUtils.isEmpty(sErr)) { - sOut = genInputLog(stdInput); - if (!generateIsSuccess(sOut)) { - sErrorMessage = sOut; + BufferedReader stdInput = null; + BufferedReader stdError = null; + try { + stdInput = new BufferedReader(new InputStreamReader(process.getInputStream(), + StandardCharsets.UTF_8)); + stdError = new BufferedReader(new InputStreamReader(process.getErrorStream(), + StandardCharsets.UTF_8)); + String sErr; + String sOut; + sErr = getErrorResult(stdError); + if (TextUtils.isEmpty(sErr)) { + sOut = genInputLog(stdInput); + if (!generateIsSuccess(sOut)) { + sErrorMessage = sOut; + } + } else { + generateSuccess = false; + sErrorMessage = sErr; + } + } catch (IOException e) { + // Handle exception + LOG.error(e); + } finally { + // Close resources in finally block to ensure they are closed even if an exception occurs + try { + stdInput.close(); + } catch (IOException e) { + LOG.error(e); + } + try { + stdError.close(); + } catch (IOException e) { + LOG.error(e); } - return; } - generateSuccess = false; - sErrorMessage = sErr; } /** @@ -364,15 +396,29 @@ public class ApiScanDialogPane extends JDialog { @Override public void run() { + InputStreamReader isr5 = null; + BufferedReader br5 = null; try { - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); + isr5 = new InputStreamReader(is, StandardCharsets.UTF_8); + br5 = new BufferedReader(isr5); String line; - while ((line = br.readLine()) != null) { + while ((line = br5.readLine()) != null) { LOG.info(line); } } catch (IOException ioException) { LOG.error("StreamConsumer io error" + ioException); + } finally { + // 确保BufferedReader5 br和InputStreamReader isr5被关闭 + try { + br5.close(); + } catch (IOException e) { + LOG.error(e); + } + try { + isr5.close(); + } catch (IOException e) { + LOG.error(e); + } } } } @@ -391,14 +437,24 @@ public class ApiScanDialogPane extends JDialog { @Override public void run() { - BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); - genResultLog(process); + BufferedReader br2 = null; try { - while (br.readLine() != null) { + br2 = new BufferedReader(new InputStreamReader(process.getInputStream(), + StandardCharsets.UTF_8)); + genResultLog(process); + while (br2.readLine() != null) { LOG.info(" callExtProcess "); } } catch (IOException ioException) { LOG.error(" callExtProcess error" + ioException); + } finally { + // 确保BufferedReader br2被关闭 + try { + br2.close(); + } catch (IOException e) { + // 处理关闭BufferedReader时的异常 + LOG.error(e); + } } } }