1919 ***************************************************************************/
2020package info .unterrainer .java .tools .scripting .bulkmakemkv .syscommandexecutor ;
2121
22+ import info .unterrainer .java .tools .utils .NullUtils ;
23+
2224import java .io .File ;
2325import java .io .IOException ;
2426import java .io .InputStream ;
2830
2931import javax .annotation .Nullable ;
3032
31- import org .apache .commons .lang .StringUtils ;
32-
33- import info .unterrainer .java .tools .utils .NullUtils ;
3433import lombok .experimental .ExtensionMethod ;
3534
35+ import org .apache .commons .lang .StringUtils ;
36+
3637/**
37- * Usage of following class can go as ... <br>
38+ * Usage of following class can go as ...
39+ * <P>
3840 *
3941 * <PRE>
4042 * <CODE>
4547 * </CODE>
4648 * </PRE>
4749 *
48- * OR <br>
50+ * </P>
51+ * OR
52+ * <P>
4953 *
5054 * <PRE>
5155 * <CODE>
5660 * String cmdOutput = cmdExecutor.getCommandOutput();
5761 * </CODE>
5862 * </PRE>
63+ *
64+ * </P>
5965 */
6066
6167@ ExtensionMethod ({ NullUtils .class })
@@ -78,44 +84,47 @@ public class SysCommandExecutor {
7884@ Nullable
7985private AsyncStreamReader fCmdErrorThread ;
8086
81- public SysCommandExecutor (@ Nullable final LogDevice fOuputLogDevice , @ Nullable final LogDevice fErrorLogDevice ) {
87+ public SysCommandExecutor (@ Nullable LogDevice fOuputLogDevice , @ Nullable LogDevice fErrorLogDevice ) {
8288super ();
8389this .fOuputLogDevice = fOuputLogDevice ;
8490this .fErrorLogDevice = fErrorLogDevice ;
8591}
8692
87- public void setOutputLogDevice (final LogDevice logDevice ) {
93+ public void setOutputLogDevice (LogDevice logDevice ) {
8894fOuputLogDevice = logDevice ;
8995}
9096
91- public void setErrorLogDevice (final LogDevice logDevice ) {
97+ public void setErrorLogDevice (LogDevice logDevice ) {
9298fErrorLogDevice = logDevice ;
9399}
94100
95- public void setWorkingDirectory (final String workingDirectory ) {
101+ public void setWorkingDirectory (String workingDirectory ) {
96102fWorkingDirectory = workingDirectory ;
97103}
98104
99- public void setEnvironmentVar (final String name , final String value ) {
100- if (fEnvironmentVarList == null )
101- fEnvironmentVarList = new ArrayList <>();
105+ public void setEnvironmentVar (String name , String value ) {
106+ if (fEnvironmentVarList == null ) {
107+ fEnvironmentVarList = new ArrayList <EnvironmentVar >();
108+ }
102109
103110fEnvironmentVarList .noNull ().add (new EnvironmentVar (name , value ));
104111}
105112
106113public String getCommandOutput () {
107- if (fCmdOutput == null )
114+ if (fCmdOutput == null ) {
108115return StringUtils .EMPTY ;
116+ }
109117return fCmdOutput .noNull ().toString ();
110118}
111119
112120public String getCommandError () {
113- if (fCmdError == null )
121+ if (fCmdError == null ) {
114122return StringUtils .EMPTY ;
123+ }
115124return fCmdError .noNull ().toString ();
116125}
117126
118- public int runCommand (final String commandLine ) throws Exception {
127+ public int runCommand (String commandLine ) throws Exception {
119128/* run command */
120129Process process = runCommandHelper (commandLine );
121130
@@ -138,17 +147,18 @@ public int runCommand(final String commandLine) throws Exception {
138147return exitStatus ;
139148}
140149
141- private Process runCommandHelper (final String commandLine ) throws IOException {
150+ private Process runCommandHelper (String commandLine ) throws IOException {
142151Process process = null ;
143- if (fWorkingDirectory == null )
152+ if (fWorkingDirectory == null ) {
144153process = Runtime .getRuntime ().exec (commandLine , getEnvTokens ());
145- else
154+ } else {
146155process = Runtime .getRuntime ().exec (commandLine , getEnvTokens (), new File (fWorkingDirectory ));
156+ }
147157
148158return process ;
149159}
150160
151- private void startOutputAndErrorReadThreads (final InputStream processOut , final InputStream processErr ) {
161+ private void startOutputAndErrorReadThreads (InputStream processOut , InputStream processErr ) {
152162fCmdOutput = new StringBuffer ();
153163fCmdOutputThread = new AsyncStreamReader (processOut , fCmdOutput .noNull (), fOuputLogDevice , "OUTPUT" );
154164fCmdOutputThread .start ();
@@ -165,8 +175,9 @@ private void notifyOutputAndErrorReadThreadsToStopReading() {
165175
166176@ Nullable
167177private String [] getEnvTokens () {
168- if (fEnvironmentVarList == null )
178+ if (fEnvironmentVarList == null ) {
169179return new String [0 ];
180+ }
170181
171182String [] envTokenArray = new String [fEnvironmentVarList .noNull ().size ()];
172183Iterator <EnvironmentVar > envVarIter = fEnvironmentVarList .noNull ().iterator ();
0 commit comments