public class ExternalProcessInputStream
extends java.io.InputStream
IOException
.
Note that this is a single-thread workaround. A multi-thread processing would be a better solution.
Constructor and Description |
---|
ExternalProcessInputStream(java.lang.Process process)
Creates a new process input stream.
|
ExternalProcessInputStream(java.lang.Process process,
int... successExitCodes)
Creates a new process input stream.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close() |
protected boolean |
hasExited(boolean waitForExit)
Returns whether the encapsulated process has exited (true) or
it is still running (false).
|
protected boolean |
isSuccessExitCode(int processExitCode)
Returns whether the given exit code is considered successful.
|
protected void |
onExit(int processExitCode)
Method called when the encapsulated process terminates.
|
int |
read() |
int |
read(byte[] b,
int off,
int len) |
long |
skip(long n) |
public ExternalProcessInputStream(java.lang.Process process, int... successExitCodes)
process
- the process the input stream of which to encapsulatesuccessExitCodes
- the list of exit codes that represent a successful exit of the processpublic ExternalProcessInputStream(java.lang.Process process)
process
- the process the input stream of which to encapsulateprotected boolean isSuccessExitCode(int processExitCode)
processExitCode
- the exit code to checkprotected void onExit(int processExitCode)
processExitCode
- the exit code returned by the processprotected boolean hasExited(boolean waitForExit) throws java.io.IOException
waitForExit
- flag whether to wait for the process to exit (used when input streams are finished)java.io.IOException
- if the process has exited with non-success exit code,
the text passed on std-err is returned as the exception messagepublic int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public long skip(long n) throws java.io.IOException
skip
in class java.io.InputStream
java.io.IOException
public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException