Class: Embulk::FileOutput
- Inherits:
-
Object
- Object
- Embulk::FileOutput
- Defined in:
- lib/embulk/file_output.rb
Instance Method Summary collapse
- #add(buffer) ⇒ Object
- #close ⇒ Object
- #finish ⇒ Object
- #flush ⇒ Object
-
#initialize(java_file_output) ⇒ FileOutput
constructor
A new instance of FileOutput.
- #next_file ⇒ Object
- #to_java ⇒ Object
- #write(buffer) ⇒ Object
Constructor Details
#initialize(java_file_output) ⇒ FileOutput
Returns a new instance of FileOutput.
6 7 8 9 10 11 |
# 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 |
Instance Method Details
#add(buffer) ⇒ Object
28 29 30 31 32 |
# File 'lib/embulk/file_output.rb', line 28 def add(buffer) flush @java_file_output.add(Buffer.from_ruby_string(buffer)) nil end |
#close ⇒ Object
47 48 49 |
# File 'lib/embulk/file_output.rb', line 47 def close @java_file_output.close end |
#finish ⇒ Object
42 43 44 45 |
# File 'lib/embulk/file_output.rb', line 42 def finish flush @java_file_output.finish end |
#flush ⇒ Object
34 35 36 37 38 39 40 |
# 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 ⇒ Object
13 14 15 16 17 |
# File 'lib/embulk/file_output.rb', line 13 def next_file flush @java_file_output.nextFile self end |
#to_java ⇒ Object
51 52 53 |
# File 'lib/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 '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 |