Sha256: fa0d35a8a2a61181cfac8e1018c8c7183cf3cad792fc60773c7f9f0a4c964e14

Contents?: true

Size: 1.03 KB

Versions: 43

Compression:

Stored size: 1.03 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
        ChildProcess.logger.debug ex.message
        ChildProcess.logger.debug ex.backtrace
      end

    end # Pump
  end # JRuby
end # ChildProcess

Version data entries

43 entries across 31 versions & 7 rubygems

Version Path
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/childprocess-4.1.0/lib/childprocess/jruby/pump.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/childprocess-4.1.0/lib/childprocess/jruby/pump.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/childprocess-4.1.0/lib/childprocess/jruby/pump.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/childprocess-4.1.0/lib/childprocess/jruby/pump.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/childprocess-4.1.0/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/childprocess-4.1.0/lib/childprocess/jruby/pump.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/childprocess-4.1.0/lib/childprocess/jruby/pump.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/jruby/pump.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/childprocess-4.1.0/lib/childprocess/jruby/pump.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/childprocess-4.1.0/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/childprocess-4.1.0/lib/childprocess/jruby/pump.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/childprocess-3.0.0/lib/childprocess/jruby/pump.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/jruby/pump.rb
childprocess-4.1.0 lib/childprocess/jruby/pump.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/childprocess-3.0.0/lib/childprocess/jruby/pump.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/childprocess-3.0.0/lib/childprocess/jruby/pump.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/jruby/pump.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/jruby/pump.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/childprocess-3.0.0/lib/childprocess/jruby/pump.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/childprocess-4.0.0/lib/childprocess/jruby/pump.rb