Class: Embulk::FileOutput

Inherits:
Object
  • Object
show all
Defined in:
embulk-core/src/main/ruby/embulk/file_output.rb

Instance Method Summary collapse

Constructor Details

#initialize(java_file_output) ⇒ FileOutput

Returns a new instance of FileOutput



6
7
8
9
10
11
# File 'embulk-core/src/main/ruby/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

Instance Method Details

#add(buffer) ⇒ Object



28
29
30
31
32
# File 'embulk-core/src/main/ruby/embulk/file_output.rb', line 28

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

#closeObject



47
48
49
# File 'embulk-core/src/main/ruby/embulk/file_output.rb', line 47

def close
  @java_file_output.close
end

#finishObject



42
43
44
45
# File 'embulk-core/src/main/ruby/embulk/file_output.rb', line 42

def finish
  flush
  @java_file_output.finish
end

#flushObject



34
35
36
37
38
39
40
# File 'embulk-core/src/main/ruby/embulk/file_output.rb', line 34

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

#next_fileObject



13
14
15
16
17
# File 'embulk-core/src/main/ruby/embulk/file_output.rb', line 13

def next_file
  flush
  @java_file_output.nextFile
  self
end

#to_javaObject



51
52
53
# File 'embulk-core/src/main/ruby/embulk/file_output.rb', line 51

def to_java
  @java_file_output
end

#write(buffer) ⇒ Object



19
20
21
22
23
24
25
26
# File 'embulk-core/src/main/ruby/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