From 85cd89e7f7bba864fba687fbf419512504b5f7c2 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 21 Apr 2017 17:12:12 +0200 Subject: [SystemCommandTask] try-with for stdout/err readers, close input after done --- .../java/org/openslx/taskmanager/api/SystemCommandTask.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'api/src') diff --git a/api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java b/api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java index 2f3cf57..3e480de 100644 --- a/api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java +++ b/api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java @@ -67,8 +67,7 @@ public abstract class SystemCommandTask extends AbstractTask @Override public void run() { - try { - BufferedReader reader = new BufferedReader( new InputStreamReader( p.getInputStream() ) ); + try ( BufferedReader reader = new BufferedReader( new InputStreamReader( p.getInputStream() ) ) ) { String line; while ( ( line = reader.readLine() ) != null ) { synchronized ( p ) { @@ -85,8 +84,7 @@ public abstract class SystemCommandTask extends AbstractTask @Override public void run() { - try { - BufferedReader reader = new BufferedReader( new InputStreamReader( p.getErrorStream() ) ); + try ( BufferedReader reader = new BufferedReader( new InputStreamReader( p.getErrorStream() ) ) ) { String line; while ( ( line = reader.readLine() ) != null ) { synchronized ( p ) { @@ -135,6 +133,10 @@ public abstract class SystemCommandTask extends AbstractTask process.getOutputStream().close(); } catch ( Throwable t ) { } + try { + process.getInputStream().close(); + } catch ( Throwable t ) { + } synchronized ( p ) { return processEnded( retval ); -- cgit v1.2.3-55-g7522