class ChildProcess::JRuby::Pump
Constants
- BUFFER_SIZE
Public Class Methods
Source
# File lib/childprocess/jruby/pump.rb, line 6 def initialize(input, output) @input = input @output = output @stop = false end
Public Instance Methods
Source
# File lib/childprocess/jruby/pump.rb, line 17 def run @thread = Thread.new { pump } self end
Source
# File lib/childprocess/jruby/pump.rb, line 12 def stop @stop = true @thread && @thread.join end
Private Instance Methods
Source
# File lib/childprocess/jruby/pump.rb, line 25 def pump buffer = Java.byte[BUFFER_SIZE].new until @stop && (@input.available == 0) read, avail = 0, 0 while read != -1 avail = [@input.available, 1].max avail = BUFFER_SIZE if avail > BUFFER_SIZE read = @input.read(buffer, 0, avail) if read > 0 @output.write(buffer, 0, read) @output.flush end end sleep 0.1 end @output.flush rescue java.io.IOException => ex ChildProcess.logger.debug ex.message ChildProcess.logger.debug ex.backtrace end