I have a java application taking data from stdin and writing results to stdout. Like this:
app1 | java_app | app2
The amount of data moved through the pipe is large and takes a long time (hours and days is not uncommon or unexpected).
Its seems that if app1 dies, and closes its end of the pipe, I receive a pipe related exception. However is app2 dies, and closes its end of the pipe I do not receive an exception. This means that java_app continues on consuming input, which will never generate any useful output, running for hours or days.
The difference in pipe exception reporting seems to stem from System.in being an InputStream, while System.out is a PrintStream and PrintStreams swallow up any errors. I know you can get the error state from a PrintStream by using stream.checkError() - but using that everywhere is clunky (and forces a flush of your output stream.)
I 'm happy to forgo the bulk of functionality of PrintStream to get better error reporting.
Is there another way to get access to stdout that isn't wrapped in a PrintStream, but instead a nicer OutputStream?