Class: ChildProcess::JRuby::Redirector

Inherits:
Object
  • Object
show all
Defined in:
lib/childprocess/jruby/redirector.rb

Constant Summary collapse

BUFFER_SIZE =
2048

Instance Method Summary collapse

Constructor Details

#initialize(input, output) ⇒ Redirector

Returns a new instance of Redirector.



6
7
8
9
10
# File 'lib/childprocess/jruby/redirector.rb', line 6

def initialize(input, output)
  @input = input
  @output = output
  @buffer = Java.byte[BUFFER_SIZE].new
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/childprocess/jruby/redirector.rb', line 12

def run
  read, avail = 0, 0

  while(read != -1)
    avail = [@input.available, 1].max
    read  = @input.read(@buffer, 0, avail)

    if read > 0
      @output.write(@buffer, 0, read)
    end
  end
rescue java.io.IOException => ex
  $stderr.puts ex.message, ex.backtrace if $DEBUG
end