I have an OutputStream with which I needed to read, and therefore I used the following (Groovy) code to get the InputStream link for the data:
PipedInputStream inputStream = new PipedInputStream() PipedOutputStream outputStream = new PipedOutputStream(inputStream) new Thread( new Runnable() { public void run() {
In this case, the handler is some class that implements the interface that this method has:
public void process(InputStream stream);
The problem that arose in our new requirements was that there was some preprocessing in the stream, so I need to read the stream at least twice in the handler.process () method. Here is a sample code from one implementation:
public void process(InputStream stream) { def bufferedStream = new BufferedInputStream(stream, 30 * 1048576)
I know that for some input I am not pushing the limit of 30 MB or the size of Integer.MAX_VALUE . However, I always get the following exception:
java.io.IOException: Stream closed
Is it possible? I think the problem is closing the stream in PipedOutputStream, but I donโt know how to prevent this, or maybe I am creating more problems, being new to Java Stream IO.
source share