diff --git a/java/org/slub/rosetta/dps/repository/plugin/SLUBMatroskaFFV1FormatValidationPlugin.java b/java/org/slub/rosetta/dps/repository/plugin/SLUBMatroskaFFV1FormatValidationPlugin.java index 27f60236c38557a1ec3ab133b6316a4ff6d392ab..f2b826c67b1e96a736967d542dc83765587b2970 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(); - } } }