class Embulk::FileOutput

Public Class Methods

new(java_file_output) click to toggle source
# File lib/embulk/file_output.rb, line 6
def initialize(java_file_output)
  @java_file_output = java_file_output
  @buffer = Buffer.new
  @buffer.force_encoding('ASCII-8BIT')
  @flush_size = 32*1024
end

Public Instance Methods

add(buffer) click to toggle source
# File lib/embulk/file_output.rb, line 28
def add(buffer)
  flush
  @java_file_output.add(Buffer.from_ruby_string(buffer))
  nil
end
close() click to toggle source
# File lib/embulk/file_output.rb, line 47
def close
  @java_file_output.close
end
finish() click to toggle source
# File lib/embulk/file_output.rb, line 42
def finish
  flush
  @java_file_output.finish
end
flush() click to toggle source
# File lib/embulk/file_output.rb, line 34
def flush
  unless @buffer.empty?
    @java_file_output.add(@buffer.to_java)
    @buffer.clear
  end
  nil
end
next_file() click to toggle source
# File lib/embulk/file_output.rb, line 13
def next_file
  flush
  @java_file_output.nextFile
  self
end
to_java() click to toggle source
# File lib/embulk/file_output.rb, line 51
def to_java
  @java_file_output
end
write(buffer) click to toggle source
# File lib/embulk/file_output.rb, line 19
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