Sha256: 65ca7361760024ed246603fbadbeabb5ffe32f7f937b65c6a140e65cdb61274f

Contents?: true

Size: 924 Bytes

Versions: 21

Compression:

Stored size: 924 Bytes

Contents

module Embulk
  require 'embulk/buffer'

  class FileOutput
    def initialize(java_file_output)
      @java_file_output = java_file_output
      @buffer = Buffer.new
      @buffer.force_encoding('ASCII-8BIT')
      @flush_size = 32*1024
    end

    def next_file
      flush
      @java_file_output.nextFile
      self
    end

    def write(buffer)
      buffer.force_encoding('ASCII-8BIT')  # TODO this is destructively change buffer
      @buffer << buffer
      if @buffer.size > @flush_size
        flush
      end
      nil
    end

    def add(buffer)
      flush
      @java_file_output.add(Buffer.from_ruby_string(buffer))
      nil
    end

    def flush
      unless @buffer.empty?
        @java_file_output.add(@buffer.to_java)
        @buffer.clear
      end
      nil
    end

    def finish
      flush
      @java_file_output.finish
    end

    def close
      @java_file_output.close
    end
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
embulk-0.6.16 lib/embulk/file_output.rb
embulk-0.6.15 lib/embulk/file_output.rb
embulk-0.6.14 lib/embulk/file_output.rb
embulk-0.6.13 lib/embulk/file_output.rb
embulk-0.6.12 lib/embulk/file_output.rb
embulk-0.6.11 lib/embulk/file_output.rb
embulk-0.6.10 lib/embulk/file_output.rb
embulk-0.6.9 lib/embulk/file_output.rb
embulk-0.6.8 lib/embulk/file_output.rb
embulk-0.6.7 lib/embulk/file_output.rb
embulk-0.6.6 lib/embulk/file_output.rb
embulk-0.6.5 lib/embulk/file_output.rb
embulk-0.6.4 lib/embulk/file_output.rb
embulk-0.6.3 lib/embulk/file_output.rb
embulk-0.6.2 lib/embulk/file_output.rb
embulk-0.6.1 lib/embulk/file_output.rb
embulk-0.6.0 lib/embulk/file_output.rb
embulk-0.5.5 lib/embulk/file_output.rb
embulk-0.5.4 lib/embulk/file_output.rb
embulk-0.5.3 lib/embulk/file_output.rb