I have an input byte array which I would like to feed to the standard input of an external program (Process). Also, I would like to collect the output in a byte array.
What is the most elegant way to do this? PipedInputStream/PipedOutputStream? nio.channels.Pipe?
Sample code would be a plus because I can’t really figure out how to do this in a good way…
Combining
PipedInputStreamwithPipedOutputStreamand Peter’sMultiOutputStreamfrom another post here, you can get the following:Now, if you execute:
You feed your
PipedInputStream, optionally handing the reference over to another process, i.e. Java Thread. Simultaneoulsy, you write into a byte array, which can be queried by: