I'm building a shape processing system with PipedInputStream and PipedOutputStream. To be able to deal with object, I decorate the pipe with an ObjectStream. The problem is that when I try to add the ObjectInputStream on the input pipe, this step is never done. The application wait forever for something to happen. In other words, when i try to debug the application, the breakpoint never go further than the instantiation of the ObjectInputStream.
The application is build with gradle. Eclipse is only used as a remote debugging tool. If you have any clue, let me know (:
Thanks
SplitShapesFilter.java
// [...]
private ObjectInputStream shapeInputStream;
private ObjectOutputStream convexOutputStream;
public SplitShapesFilter(InputStream shapeInput, OutputStream convexOutput) {
try {
this.convexOutputStream = new ObjectOutputStream(new BufferedOutputStream(convexOutput));
this.shapeInputStream = new ObjectInputStream(new BufferedInputStream(shapeInput)); // block at this line
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
// [...]
Orchestrator.java
// [...]
public void startPipes() {
float[] data = {/*some datas*/};
final PipedOutputStream shapeOutput = new PipedOutputStream();
PipedInputStream shapeInput = new PipedInputStream();
shapeOutput.connect(shapeInput);
final PipedOutputStream convexOutput new PipedOutputStream();
Thread findShapesFilter = new FindShapesFilter(data, shapeOutput);
Thread splitShapesFilter = new SplitShapesFilter(shapeInput, convexOutput);
// [...]
findShapesFilter.start();
splitShapesFilter.start();
// an other thread will join the others lather
}
This is because the constructor for ObjectInputStream
will itself read the stream header. While perhaps unexpected, the JavaDoc does say so.
Since you haven't yet started your threads, it is perfectly natural that it will keep blocking for that header than never arrives.
What you would need to do, then, is to only save the backing InputStream
in your constructor and only construct the ObjectInputStream
in the context of your new thread.