I cannot figure out whether I am using piped streams improperly or whether my problem is elsewhere in the issue below.
I have an object (called 'adi') that I marshal into a file as shown below:
final PipedInputStream pipedInputStream = new PipedInputStream();
OutputStream pipedOutputStream = null;
pipedOutputStream = new PipedOutputStream(pipedInputStream);
log.info("marshalling away");
final OutputStream outputStream = new FileOutputStream(new File(
"target/test.xml"));
m.marshal(adi, outputStream);
outputStream.flush();
outputStream.close();
pipedOutputStream.write("test".getBytes());
// m.marshal(adi, pipedOutputStream);
pipedOutputStream.flush();
pipedOutputStream.close();
log.info("marshalling done");
return pipedInputStream;
- That code generates a file target/test.xml with the content that I expect (marshalled object), validating that the marshalling into the outputStream works properly.
- The code also generates a pipedInputStream. If I iterate through the bytes pulled from that stream and print them, it displays "test", validating the fact that my input/output pipe stream is properly setup and working.
Yet, when I uncomment
//m.marshal(adi, pipedOutputStream);
the code hangs forever (never displaying "marshalling done") while I would expect the code to return an input stream containing "test" followed by my marshalled object.
What am I missing?
Thanks