Sha256: b88ed2f075892c6eb47cbeae2427fb79a63d1e0339b43b077d3ae2b0d57b6942

Contents?: true

Size: 903 Bytes

Versions: 8

Compression:

Stored size: 903 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)
      end
      nil
    end

    def finish
      flush
      @java_file_output.finish
    end

    def close
      @java_file_output.finish
    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
embulk-0.5.1 lib/embulk/file_output.rb
embulk-0.5.0 lib/embulk/file_output.rb
embulk-0.4.10 lib/embulk/file_output.rb
embulk-0.4.9 lib/embulk/file_output.rb
embulk-0.4.8 lib/embulk/file_output.rb
embulk-0.4.7 lib/embulk/file_output.rb
embulk-0.4.6 lib/embulk/file_output.rb
embulk-0.4.5 lib/embulk/file_output.rb