Class CommandInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
ecmwf.common.technical.CommandInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable
A stream that connects an InputStream to the input of an external process, and allows reading the output produced by
the process.
This class manages the lifecycle of the associated process and its input/output streams, and handles stderr
asynchronously to avoid potential deadlocks.
-
Field Summary
Fields inherited from class FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionCommandInputStream(InputStream in, Process process) Creates a CommandInputStream that connects the given InputStream to the standard input of a process, and allows reading the standard output of that process.CommandInputStream(InputStream in, String[] command) Creates a CommandInputStream by executing the given command. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of bytes that can be read without blocking.voidclose()Closes this stream and performs all associated cleanup.intread()Reads a byte of data from the process's output.intread(byte[] b) Reads bytes into a buffer from the process's output.intread(byte[] b, int off, int len) Reads up to len bytes of data from the process's output.longskip(long n) Skips over and discards n bytes of data from the process's output.Methods inherited from class FilterInputStream
mark, markSupported, resetMethods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
CommandInputStream
Creates a CommandInputStream that connects the given InputStream to the standard input of a process, and allows reading the standard output of that process.- Parameters:
in- The InputStream from which to send data to the process's input.process- The process to execute and communicate with.- Throws:
IOException- If any I/O error occurs during setup.
-
CommandInputStream
Creates a CommandInputStream by executing the given command.- Parameters:
in- The InputStream to send to the process's stdin.command- The command to run.- Throws:
IOException- If an error occurs while launching the process.
-
-
Method Details
-
close
Closes this stream and performs all associated cleanup.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterInputStream- Throws:
IOException- If an error occurs during closing.
-
read
Reads a byte of data from the process's output.- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
Reads bytes into a buffer from the process's output.- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
Reads up to len bytes of data from the process's output.- Overrides:
readin classFilterInputStream- Throws:
IOException
-
skip
Skips over and discards n bytes of data from the process's output.- Overrides:
skipin classFilterInputStream- Throws:
IOException
-
available
Returns the number of bytes that can be read without blocking.- Overrides:
availablein classFilterInputStream- Throws:
IOException
-