Package org.im4java.process
Class ProcessStarter
- java.lang.Object
-
- org.im4java.process.ProcessStarter
-
- Direct Known Subclasses:
ImageCommand
public class ProcessStarter extends java.lang.ObjectThis class implements the processing of os-commands using Runtime.exec(). The class does not use the newer ProcessBuilder, since it has no knowledge about the valid os-arguments of the generated command.
-
-
Field Summary
Fields Modifier and Type Field Description static intBUFFER_SIZEBuffer size of process input-stream (used for reading the output (sic!) of the process).
-
Constructor Summary
Constructors Modifier Constructor Description protectedProcessStarter()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddProcessListener(ProcessListener pProcessListener)Add a ProcessListener to this ProcessStarter.InputProvidergetIInputProvider()java.util.LinkedList<ProcessListener>getIProcessListener()returniProcessListenerbooleanisAsyncMode()protected intrun(java.util.LinkedList<java.lang.String> pArgs)Execute the command.voidsetAsyncMode(boolean pAsyncMode)voidsetErrorConsumer(ErrorConsumer pErrorConsumer)Set the ErrorConsumer for the stderr of the ProcessStarter.voidsetInputProvider(InputProvider pInputProvider)Set the InputProvider for the ProcessStarter (if used as a pipe).voidsetOutputConsumer(OutputConsumer pOutputConsumer)Set the OutputConsumer for the ProcessStarter (if used as a pipe).java.lang.ProcessstartProcess(java.util.LinkedList<java.lang.String> pArgs)Execute the command.intwaitForProcess(java.lang.Process pProcess)Perform process input/output and wait for process to terminate.
-
-
-
Field Detail
-
BUFFER_SIZE
public static final int BUFFER_SIZE
Buffer size of process input-stream (used for reading the output (sic!) of the process). Currently 64KB.- See Also:
- Constant Field Values
-
-
Method Detail
-
setInputProvider
public void setInputProvider(InputProvider pInputProvider)
Set the InputProvider for the ProcessStarter (if used as a pipe).- Parameters:
pInputProvider- the InputProvider to be set
-
getIInputProvider
public InputProvider getIInputProvider()
- Returns:
- the iInputProvider
-
setOutputConsumer
public void setOutputConsumer(OutputConsumer pOutputConsumer)
Set the OutputConsumer for the ProcessStarter (if used as a pipe).- Parameters:
pOutputConsumer- the OutputConsumer to be set
-
setErrorConsumer
public void setErrorConsumer(ErrorConsumer pErrorConsumer)
Set the ErrorConsumer for the stderr of the ProcessStarter.- Parameters:
pErrorConsumer- the ErrorConsumer to be set
-
getIProcessListener
public java.util.LinkedList<ProcessListener> getIProcessListener()
returniProcessListener- Returns:
- ProcessListener linked list
-
addProcessListener
public void addProcessListener(ProcessListener pProcessListener)
Add a ProcessListener to this ProcessStarter.- Parameters:
pProcessListener- the ProcessListener to add
-
run
protected int run(java.util.LinkedList<java.lang.String> pArgs) throws java.io.IOException, java.lang.InterruptedExceptionExecute the command.- Parameters:
pArgs- arguments for command- Returns:
- process return value
- Throws:
java.io.IOException- IO problemsjava.lang.InterruptedException- Interruptions problems
-
startProcess
public java.lang.Process startProcess(java.util.LinkedList<java.lang.String> pArgs) throws java.io.IOException, java.lang.InterruptedExceptionExecute the command.- Parameters:
pArgs- list of arguments for the process- Returns:
- return value of
ProcessBuilder.start() - Throws:
java.io.IOException- IO problemsjava.lang.InterruptedException- Interruption problems
-
waitForProcess
public int waitForProcess(java.lang.Process pProcess) throws java.io.IOException, java.lang.InterruptedExceptionPerform process input/output and wait for process to terminate.- Parameters:
pProcess- the process- Returns:
- the process exit value
- Throws:
java.io.IOException- IO problemsjava.lang.InterruptedException- Interrupted Exception problems
-
setAsyncMode
public void setAsyncMode(boolean pAsyncMode)
- Parameters:
pAsyncMode- the iAsyncMode to set
-
isAsyncMode
public boolean isAsyncMode()
- Returns:
- the iAsyncMode
-
-