From c3bba4fe1bc82144d27ee68636e0b84a079dd89e Mon Sep 17 00:00:00 2001 From: Soisik Froger Date: Tue, 5 Mar 2019 10:44:58 +0100 Subject: [PATCH] Fixed issue #10 : LSC process hangs indefinitely when ouput overflow the available buffer. --- .../AbstractExecutableLdifService.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/lsc/plugins/connectors/executable/AbstractExecutableLdifService.java b/src/main/java/org/lsc/plugins/connectors/executable/AbstractExecutableLdifService.java index 23e81b2..7616536 100755 --- a/src/main/java/org/lsc/plugins/connectors/executable/AbstractExecutableLdifService.java +++ b/src/main/java/org/lsc/plugins/connectors/executable/AbstractExecutableLdifService.java @@ -1,6 +1,8 @@ package org.lsc.plugins.connectors.executable; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; @@ -130,13 +132,19 @@ private int execute(String[] runtime, String[] env, String input, StringBuffer d outputStream.flush(); outputStream.close(); + BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + datas.append(line + System.getProperty("line.separator")); + } + //TODO: need to check for max time LOGGER.debug("Waiting for command to stop ... "); p.waitFor(); } catch (IOException e) { // Encountered an error while reading data from output - LOGGER.error("Encountered an I/O exception while writing data to script {}", runtime); + LOGGER.error("Encountered an I/O exception while writing/reading data to/from script {}", runtime); LOGGER.error(e.toString(), e); } catch (InterruptedException e) { // Encountered an interruption @@ -144,14 +152,6 @@ private int execute(String[] runtime, String[] env, String input, StringBuffer d LOGGER.debug(e.toString(), e); } - try { - datas.append(IOUtils.toString(p.getInputStream())); - } catch (IOException e) { - // Failing to read the complete string causes null return - LOGGER.error("Fail to read complete data from script output stream: {}", runtime); - LOGGER.debug(e.toString(), e); - } - try { messages.append(IOUtils.toString(p.getErrorStream())); } catch (IOException e) {