Skip to content
Browse files

Extract method for creating stdin on JRuby.

  • Loading branch information...
1 parent ec712b1 commit a650ecd070dbc2ba8e6eaabbd91e9d3e034bc704 @jarib committed Oct 17, 2012
Showing with 26 additions and 18 deletions.
  1. +26 −18 lib/childprocess/jruby/process.rb
View
44 lib/childprocess/jruby/process.rb
@@ -88,24 +88,7 @@ def setup_io
end
if duplex?
- stdin = @process.getOutputStream.to_io
- stdin.sync = true
- stdin.instance_variable_set(:@java_stream, @process.getOutputStream)
- class << stdin
- #The stream provided is a BufferedeOutputStream, so we
- #have to flush it to make the bytes flow to the process
- def __flushit
- @java_stream.flush
- end
- [:flush, :print, :printf, :putc, :puts, :write, :write_nonblock].each do |m|
- define_method(m) do |*args|
- super(*args)
- self.__flushit
- end
- end
- end
-
- io._stdin = stdin
+ io._stdin = create_stdin
else
@process.getOutputStream.close
end
@@ -130,6 +113,31 @@ def set_env(env)
end
end
+ def create_stdin
+ output_stream = @process.getOutputStream
+
+ stdin = output_stream.to_io
+ stdin.sync = true
+ stdin.instance_variable_set(:@childprocess_java_stream, output_stream)
+
+ class << stdin
+ # The stream provided is a BufferedeOutputStream, so we
+ # have to flush it to make the bytes flow to the process
+ def __childprocess_flush__
+ @childprocess_java_stream.flush
+ end
+
+ [:flush, :print, :printf, :putc, :puts, :write, :write_nonblock].each do |m|
+ define_method(m) do |*args|
+ super(*args)
+ self.__childprocess_flush__
+ end
+ end
+ end
+
+ stdin
+ end
+
end # Process
end # JRuby
end # ChildProcess

0 comments on commit a650ecd

Please sign in to comment.
Something went wrong with that request. Please try again.