Sha256: 22ebbe80ba0cc18f272735ed575377c65784bc3a022d895c51f55c1a951d0861

Contents?: true

Size: 1019 Bytes

Versions: 49

Compression:

Stored size: 1019 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 && (@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
        $stderr.puts ex.message, ex.backtrace if $DEBUG
      end

    end # Pump
  end # JRuby
end # ChildProcess

Version data entries

49 entries across 47 versions & 13 rubygems

Version Path
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/childprocess-0.5.9/lib/childprocess/jruby/pump.rb
tdiary-5.0.2 vendor/bundle/gems/childprocess-0.5.9/lib/childprocess/jruby/pump.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/gems/childprocess-0.5.9/lib/childprocess/jruby/pump.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/gems/childprocess-0.5.9/lib/childprocess/jruby/pump.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/gems/childprocess-0.5.9/lib/childprocess/jruby/pump.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/gems/childprocess-0.5.9/lib/childprocess/jruby/pump.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/childprocess-0.5.9/lib/childprocess/jruby/pump.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/childprocess-0.5.9/lib/childprocess/jruby/pump.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/childprocess-0.5.9/lib/childprocess/jruby/pump.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/childprocess-0.5.9/lib/childprocess/jruby/pump.rb
tdiary-5.0.1 vendor/bundle/gems/childprocess-0.5.9/lib/childprocess/jruby/pump.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/childprocess-0.5.6/lib/childprocess/jruby/pump.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/childprocess-0.5.3/lib/childprocess/jruby/pump.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/childprocess-0.5.6/lib/childprocess/jruby/pump.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/childprocess-0.5.9/lib/childprocess/jruby/pump.rb
childprocess-0.5.9 lib/childprocess/jruby/pump.rb
childprocess-0.5.8 lib/childprocess/jruby/pump.rb
childprocess-0.5.7 lib/childprocess/jruby/pump.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/childprocess-0.5.6/lib/childprocess/jruby/pump.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/childprocess-0.5.6/lib/childprocess/jruby/pump.rb