Allow java classes to close stdout/stderr

When the client calls a class, where either stdout or stderr is closed
the socket connection to the client is closed and no further data is
sent. This includes data transmitted over the other stream and exit
codes.