Sha256: 36ab8367291c37127c83cb54f8b81a3d636ab88f3666632ad0d7a9ea7e52a9ea

Contents?: true

Size: 1.69 KB

Versions: 155

Compression:

Stored size: 1.69 KB

Contents

module Embulk
  require 'embulk/buffer'

  class FileInput
    def initialize(java_file_input)
      @java_file_input = java_file_input
      @buffer = nil
    end

    def next_file
      if @java_file_input.nextFile
        return self
      else
        return nil
      end
    end

    def each(&block)
      if @buffer
        yield @buffer
        @buffer = nil
      end

      while java_buffer = @java_file_input.poll
        buffer = Buffer.from_java(java_buffer)
        java_buffer.release
        yield buffer
      end
    end

    def read(count=nil, dest=nil)
      if count == nil
        @buffer ||= Buffer.new
        while java_buffer = @java_file_input.poll
          @buffer << Buffer.from_java(java_buffer)
          java_buffer.release
        end

        return nil if @buffer.empty? && count != 0

        if dest
          dest.replace(@buffer)
        else
          dest = @buffer
        end
        @buffer = nil

      else
        @buffer ||= Buffer.new
        until @buffer.size >= count
          java_buffer = @java_file_input.poll
          break unless java_buffer
          @buffer << Buffer.from_java(java_buffer)
          java_buffer.release
        end

        return nil if @buffer.empty? && count != 0

        if @buffer.size <= count
          if dest
            dest.replace(@buffer)
          else
            dest = @buffer
          end
          @buffer = nil
        else
          data = @buffer.slice!(0, count)
          if dest
            dest.replace(data)
          else
            dest = data
          end
        end
      end
      return dest
    end

    def close
      @java_file_input.close
    end

    def to_java
      @java_file_input
    end
  end
end

Version data entries

155 entries across 155 versions & 1 rubygems

Version Path
embulk-0.10.36-java lib/embulk/file_input.rb
embulk-0.10.32.3-java lib/embulk/file_input.rb
embulk-0.10.32.2-java lib/embulk/file_input.rb
embulk-0.10.32.1-java lib/embulk/file_input.rb
embulk-0.10.35-java lib/embulk/file_input.rb
embulk-0.10.31.2-java lib/embulk/file_input.rb
embulk-0.10.29.2-java lib/embulk/file_input.rb
embulk-0.10.31.1-java lib/embulk/file_input.rb
embulk-0.10.29.1-java lib/embulk/file_input.rb
embulk-0.10.34-java lib/embulk/file_input.rb
embulk-0.10.33-java lib/embulk/file_input.rb
embulk-0.10.32-java lib/embulk/file_input.rb
embulk-0.10.31-java lib/embulk/file_input.rb
embulk-0.10.30-java lib/embulk/file_input.rb
embulk-0.10.29-java lib/embulk/file_input.rb
embulk-0.10.28-java lib/embulk/file_input.rb
embulk-0.10.27-java lib/embulk/file_input.rb
embulk-0.10.26-java lib/embulk/file_input.rb
embulk-0.10.25-java lib/embulk/file_input.rb
embulk-0.10.24-java lib/embulk/file_input.rb