Package nl.knaw.dans.lib.util
Class ProcessInputStream
java.lang.Object
java.io.InputStream
nl.knaw.dans.lib.util.ProcessInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()Closes the input stream and ensures that the process exited successfully.voidmark(int readlimit) booleanintread()intread(byte[] b) intread(byte[] b, int off, int len) voidreset()longskip(long n) static ProcessInputStreamstart(org.apache.commons.exec.CommandLine commandLine) Starts the given command and returns an InputStream that: streams the process stdout; throws an IOException if the process exits non-zero or fails to start.static ProcessInputStreamstart(org.apache.commons.exec.CommandLine commandLine, int... successExitCodes) Starts the given command and returns an InputStream that: streams the process stdout; throws an IOException if the process exits non-zero or fails to start.static ProcessInputStreamstart(org.apache.commons.exec.CommandLine commandLine, File workingDirectory, Duration timeout, int... successExitCodes) Starts the given command with an optional working directory and timeout, returning an InputStream that: streams the process stdout; and treats the provided exit codes as success (all others trigger IOException).Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
MAX_BYTES_ERROR_SNIPPET
public static final int MAX_BYTES_ERROR_SNIPPET- See Also:
-
-
Method Details
-
start
public static ProcessInputStream start(org.apache.commons.exec.CommandLine commandLine) throws IOException Starts the given command and returns an InputStream that:- streams the process stdout;
- throws an IOException if the process exits non-zero or fails to start.
- Parameters:
commandLine- the command to start- Returns:
- an InputStream that reads from the process stdout
- Throws:
IOException- if the process fails to start or exits non-zero
-
start
public static ProcessInputStream start(org.apache.commons.exec.CommandLine commandLine, int... successExitCodes) throws IOException Starts the given command and returns an InputStream that:- streams the process stdout;
- throws an IOException if the process exits non-zero or fails to start.
- Parameters:
commandLine- the command to startsuccessExitCodes- exit codes considered successful (defaults to {0} if null or empty)- Returns:
- an InputStream that reads from the process stdout
- Throws:
IOException- if the process fails to start or exits non-zero
-
start
public static ProcessInputStream start(org.apache.commons.exec.CommandLine commandLine, File workingDirectory, Duration timeout, int... successExitCodes) throws IOException Starts the given command with an optional working directory and timeout, returning an InputStream that:- streams the process stdout; and
- treats the provided exit codes as success (all others trigger IOException).
- Parameters:
commandLine- the command to startworkingDirectory- optional working directory for the process (null to leave unset)timeout- optional timeout (null for no timeout)successExitCodes- exit codes considered successful (defaults to {0} if null or empty)- Throws:
IOException
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
close
Closes the input stream and ensures that the process exited successfully. Note that this method will block until the process completes.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException- if the process fails to start or exits with an error code.
-