Class DefaultCommandProcess
- java.lang.Object
-
- com.thebuzzmedia.exiftool.process.executor.DefaultCommandProcess
-
- All Implemented Interfaces:
CommandProcess
,AutoCloseable
public class DefaultCommandProcess extends Object implements CommandProcess
Default implementation forCommandProcess
interface.
This implementation used instance ofInputStream
to handle read operation and instance ofOutputStream
to handle write operation. These streams may come from instance ofProcess
for instance.
Note: This implementation is not thread safe.
-
-
Constructor Summary
Constructors Constructor Description DefaultCommandProcess(InputStream is, OutputStream os, InputStream err)
Create process.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
flush()
Flush pending write operations.boolean
isClosed()
Check if current process has been closed.boolean
isRunning()
Check if current process is still opened.String
read()
Read output until a null line is read.String
read(OutputHandler handler)
Read output until: A null line is read. Handler returns false when line is read. Since command process will not be closed, a simple string is returned (an exit status cannot be computed).void
write(Iterable<String> inputs)
Write set of inputs to the current process.void
write(String input, String... others)
Write input string to the current process.
-
-
-
Constructor Detail
-
DefaultCommandProcess
public DefaultCommandProcess(InputStream is, OutputStream os, InputStream err)
Create process.- Parameters:
is
- Input stream.os
- Output stream.err
- Error stream.
-
-
Method Detail
-
read
public String read() throws IOException
Description copied from interface:CommandProcess
Read output until a null line is read.
Since command process will not be closed, a simple string is returned (an exit status cannot be computed).- Specified by:
read
in interfaceCommandProcess
- Returns:
- Command result.
- Throws:
IOException
- If an error occurred during operation.
-
read
public String read(OutputHandler handler) throws IOException
Description copied from interface:CommandProcess
Read output until:- A null line is read.
- Handler returns false when line is read.
- Specified by:
read
in interfaceCommandProcess
- Parameters:
handler
- Output handler.- Returns:
- Full output.
- Throws:
IOException
- If an error occurred during operation.
-
write
public void write(String input, String... others) throws IOException
Description copied from interface:CommandProcess
Write input string to the current process.- Specified by:
write
in interfaceCommandProcess
- Parameters:
input
- Input.others
- Other inputs.- Throws:
IOException
- If an error occurred during operation.
-
write
public void write(Iterable<String> inputs) throws IOException
Description copied from interface:CommandProcess
Write set of inputs to the current process.- Specified by:
write
in interfaceCommandProcess
- Parameters:
inputs
- Collection of inputs.- Throws:
IOException
- If an error occurred during operation.
-
flush
public void flush() throws IOException
Description copied from interface:CommandProcess
Flush pending write operations.- Specified by:
flush
in interfaceCommandProcess
- Throws:
IOException
- If an error occurred during operation.
-
isRunning
public boolean isRunning()
Description copied from interface:CommandProcess
Check if current process is still opened. If this method returnstrue
, thenCommandProcess.isClosed()
should returnfalse
.- Specified by:
isRunning
in interfaceCommandProcess
- Returns:
true
if process is open,false
otherwise.
-
isClosed
public boolean isClosed()
Description copied from interface:CommandProcess
Check if current process has been closed. If this method returnstrue
, thenCommandProcess.isRunning()
should returnfalse
.- Specified by:
isClosed
in interfaceCommandProcess
- Returns:
true
if process is closed,false
otherwise.
-
close
public void close() throws Exception
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
-