Sha256: 9a743d04c2e286783fd27be2c0ed6a27baf5dca2cab96ecc36c0eb8ad8d0e7bb

Contents?: true

Size: 1.05 KB

Versions: 36

Compression:

Stored size: 1.05 KB

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

36 entries across 28 versions & 4 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.0.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.1.4.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/lib/childprocess/jruby/pump.rb