Is there a way to redirect java.lang.System.out to a RubySocket’s
I was trying this with a simple tcp server, where I first had a
$stdout = socket
After which a plain puts() worked and dumped stuff on the other side of
Then, tried to do the same with some java code, calling
java.lang.System.setOut() with these:
a) new_java_out = java.io.PrintStream.new($stdout.to_outputstream,
b) new_java_out = JRuby.runtime.getOutputStream()
so that this would work:
The problem was I didn’t see anything on the other side, debugging into
this a bit, I see some IOException “not opened for writing”, with the
ChannelStream.bufferedWrite(ByteBuffer) line: 1112
ChannelStream.access$700(ChannelStream, ByteBuffer) line: 62
ChannelStream$OutputStreamAdapter.write(byte, int, int) line: 1640
PrintStream.write(byte, int, int) line: 480
Note that a doing the above with a file in place of socket worked fine.
Here’s the full source: http://pastie.org/private/rnqqahjb9qeobkcl4ax6a.
Ideas are welcome. Is this a bug in my code or jruby? I was surprised to
see an output stream “not opened for writing”.