Skip to content

Commit 24048b9

Browse files
committed
Apply pull request suggestions
Signed-off-by: Matheus Cruz <[email protected]>
1 parent da245ee commit 24048b9

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

impl/core/src/main/java/io/serverlessworkflow/impl/executors/RunShellExecutor.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
import java.io.InputStream;
3434
import java.io.InputStreamReader;
3535
import java.io.StringWriter;
36+
import java.io.UncheckedIOException;
3637
import java.nio.charset.StandardCharsets;
3738
import java.util.Map;
3839
import java.util.concurrent.CompletableFuture;
40+
import java.util.function.Supplier;
3941

4042
public class RunShellExecutor implements RunnableTask<RunShell> {
4143

@@ -148,7 +150,7 @@ public void init(RunShell taskConfiguration, WorkflowDefinition definition) {
148150
return input;
149151
}
150152

151-
} catch (IOException | InterruptedException e) {
153+
} catch (IOException | InterruptedException | UncheckedIOException e) {
152154
throw new WorkflowException(WorkflowError.runtime(taskContext, e).build(), e);
153155
}
154156
};
@@ -159,9 +161,9 @@ private WorkflowModel waitForResult(
159161
throws IOException, InterruptedException {
160162

161163
CompletableFuture<String> futureStdout =
162-
CompletableFuture.supplyAsync(() -> readInputStream(process.getInputStream()));
164+
CompletableFuture.supplyAsync(inputStreamStringSupplier(process.getInputStream()));
163165
CompletableFuture<String> futureStderr =
164-
CompletableFuture.supplyAsync(() -> readInputStream(process.getErrorStream()));
166+
CompletableFuture.supplyAsync(inputStreamStringSupplier(process.getErrorStream()));
165167

166168
int exitCode = process.waitFor();
167169

@@ -185,7 +187,17 @@ private WorkflowModel waitForResult(
185187
};
186188
}
187189

188-
@Override
190+
private static Supplier<String> inputStreamStringSupplier(InputStream process) {
191+
return () -> {
192+
try {
193+
return readInputStream(process);
194+
} catch (IOException e) {
195+
throw new UncheckedIOException(e);
196+
}
197+
};
198+
}
199+
200+
@Override
189201
public boolean accept(Class<? extends RunTaskConfiguration> clazz) {
190202
return RunShell.class.equals(clazz);
191203
}
@@ -197,7 +209,7 @@ public boolean accept(Class<? extends RunTaskConfiguration> clazz) {
197209
* @param inputStream {@link InputStream} to be read
198210
* @return {@link String} with the content of the InputStream
199211
*/
200-
public static String readInputStream(InputStream inputStream) {
212+
private static String readInputStream(InputStream inputStream) throws IOException {
201213
StringWriter writer = new StringWriter();
202214
try (BufferedReader reader =
203215
new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
@@ -206,8 +218,6 @@ public static String readInputStream(InputStream inputStream) {
206218
while ((charsRead = reader.read(buffer)) != -1) {
207219
writer.write(buffer, 0, charsRead);
208220
}
209-
} catch (IOException e) {
210-
throw new RuntimeException(e);
211221
}
212222
return writer.toString();
213223
}

0 commit comments

Comments
 (0)