Sha256: a2bbf34d99d1d8775ab46adc8e27c6915b6608bbdf794aca9fb40b5851681de4

Contents?: true

Size: 992 Bytes

Versions: 20

Compression:

Stored size: 992 Bytes

Contents

module ChildProcess
  module JRuby
    class Pump
      BUFFER_SIZE = 2048

      def initialize(input, output)
        @input  = input
        @output = output
        @stop   = false
      end

      def stop
        @stop = true
        @thread && @thread.join
      end

      def run
        @thread = Thread.new { pump }

        self
      end

      private

      def pump
        buffer = Java.byte[BUFFER_SIZE].new

        until @stop
          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
        $stderr.puts ex.message, ex.backtrace if $DEBUG
      end

    end # Pump
  end # JRuby
end # ChildProcess

Version data entries

20 entries across 20 versions & 6 rubygems

Version Path
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/childprocess-0.3.5/lib/childprocess/jruby/pump.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/childprocess-0.3.5/lib/childprocess/jruby/pump.rb
childprocess-0.3.5 lib/childprocess/jruby/pump.rb
childprocess-0.3.4 lib/childprocess/jruby/pump.rb
childprocess-0.3.3 lib/childprocess/jruby/pump.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/childprocess-0.3.2/lib/childprocess/jruby/pump.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/childprocess-0.3.2/lib/childprocess/jruby/pump.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/childprocess-0.3.2/lib/childprocess/jruby/pump.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/childprocess-0.3.2/lib/childprocess/jruby/pump.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/childprocess-0.3.2/lib/childprocess/jruby/pump.rb
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/jruby/pump.rb
ftl-0.2.0 vendor/bundle/gems/childprocess-0.3.2/lib/childprocess/jruby/pump.rb
childprocess-0.3.2 lib/childprocess/jruby/pump.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/jruby/pump.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/jruby/pump.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/jruby/pump.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/jruby/pump.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/jruby/pump.rb
resque-pool-0.3.0.beta.2 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/jruby/pump.rb
childprocess-0.3.1 lib/childprocess/jruby/pump.rb