From ee44d0387b1fbc76290f2ae883b273676161aa6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerald=20H=C3=BCbsch?= <gerald.huebsch@slub-dresden.de> Date: Fri, 7 Feb 2025 16:56:29 +0100 Subject: [PATCH] Fix assignment to final variable and buffered reader scope. --- ...LUBMatroskaFFV1FormatValidationPlugin.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/java/org/slub/rosetta/dps/repository/plugin/SLUBMatroskaFFV1FormatValidationPlugin.java b/java/org/slub/rosetta/dps/repository/plugin/SLUBMatroskaFFV1FormatValidationPlugin.java index 27f6023..f2b826c 100644 --- a/java/org/slub/rosetta/dps/repository/plugin/SLUBMatroskaFFV1FormatValidationPlugin.java +++ b/java/org/slub/rosetta/dps/repository/plugin/SLUBMatroskaFFV1FormatValidationPlugin.java @@ -109,17 +109,19 @@ public class SLUBMatroskaFFV1FormatValidationPlugin implements FormatValidationP String execstring = this.mediaconch_binary_path + " " + filePath + " -p " + profilePath; log.info("executing: " + execstring); final AtomicBoolean fuse = new AtomicBoolean(true); - final BufferedReader procOutputReader = null; + try { - Process p = Runtime.getRuntime().exec(execstring); - procOutputReader = new BufferedReader(new InputStreamReader(p.getInputStream())); + final Process p = Runtime.getRuntime().exec(execstring); final ArrayList<String> procOutputLineList = new ArrayList<String>(); // prepare thread that reads the bulky output (>> 100kByte in some cases) to prevent the buffered reader from reaching its capacity limit Thread procOutputReaderThread = new Thread() { public void run() { + BufferedReader procOutputReader = null; + try { + procOutputReader = new BufferedReader(new InputStreamReader(p.getInputStream())); String nextLine = ""; while (fuse.get() && (nextLine = procOutputReader.readLine()) != null) { procOutputLineList.add(nextLine); @@ -130,6 +132,16 @@ public class SLUBMatroskaFFV1FormatValidationPlugin implements FormatValidationP } finally { // ensure this thread terminates under all circumstances fuse.set(false); + + // cleanup all resources + if (procOutputReader != null) { + try { + procOutputReader.close(); + } catch (IOException e) { + log.error("ERROR: closing the reader stream failed, " + e.getMessage()); + } + + } } if (isDumpValidationResultToStdOut()) { @@ -181,11 +193,6 @@ public class SLUBMatroskaFFV1FormatValidationPlugin implements FormatValidationP } finally { // ensure the while loop of procOutputReaderThread terminates under all circumstances fuse.set(false); - - // cleanup all resources - if (procOutputReader != null) { - procOutputReader.close(); - } } } -- GitLab