Class: Fairy::PInputLocalFile

Inherits:
PSingleExportInput show all
Defined in:
lib/fairy/node/p-input-local-file.rb

Constant Summary

Constants included from PSingleExportable

Fairy::PSingleExportable::END_OF_STREAM, Fairy::PSingleExportable::ST_EXPORT_FINISH, Fairy::PSingleExportable::ST_WAIT_EXPORT_FINISH

Constants inherited from PIOFilter

Fairy::PIOFilter::ST_WAIT_IMPORT

Constants inherited from PFilter

Fairy::PFilter::END_OF_STREAM, Fairy::PFilter::ST_ACTIVATE, Fairy::PFilter::ST_FINISH, Fairy::PFilter::ST_INIT

Instance Attribute Summary

Attributes included from PSingleExportable

#export

Attributes inherited from PFilter

#IGNORE_EXCEPTION, #id, #log_id, #ntask

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PSingleExportable

#start, #start_export, #terminate, #wait_export_finish

Methods inherited from PIOFilter

#input=

Methods inherited from PFilter

#abort_running, #basic_start, #break_running, #each, #global_break, #global_break_from_other, #handle_exception, #key, #key=, #next, #no, #no=, #notice_status, #processor, #start, #start_export, #start_watch_status, #status=, #terminate, #terminate_proc

Constructor Details

#initialize(id, ntask, bjob, opts = nil) ⇒ PInputLocalFile

Returns a new instance of PInputLocalFile.



18
19
20
# File 'lib/fairy/node/p-input-local-file.rb', line 18

def initialize(id, ntask, bjob, opts=nil)
  super
end

Class Method Details

.open(id, ntask, bjob, io, opts = nil) ⇒ Object



13
14
15
16
# File 'lib/fairy/node/p-input-local-file.rb', line 13

def self.open(id, ntask, bjob, io, opts=nil)
  nlfileinput = self.new(id, processor, bjob, opts)
  nlfileinput.open(job)
end

Instance Method Details

#basic_each(&block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fairy/node/p-input-local-file.rb', line 31

def basic_each(&block)
  rest = nil
  while (buf = @io.read(@buffer_size))
	lines = buf.scan(/.*\n?/)
	lines.pop # scan で末尾にゴミが出るため
	if rest
	  begin
 lines[0] = rest+lines[0]
	  rescue
 Log::debug(self, @io.inspect)
 Log::debug(self, buf.inspect)
 Log::debug(self, lines.inspect)
 Log::debug(self, rest.inspect)
 raise
	  end
	end
	rest = lines.pop
	lines.each{|l| 
	  l.force_encoding(@io_external_encoding)
	  block.call(l)}
  end
  if rest
	rest.force_encoding(@io_external_encoding)
	block.call rest
  end
  @io.close
  @io = nil # FileオブジェクトをGCの対象にするため
end

#open(nioplace) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/fairy/node/p-input-local-file.rb', line 22

def open(nioplace)
  @io = nioplace.io
  self.no = nioplace.no
  @io_external_encoding = @io.external_encoding.dc_deep_copy

  @buffer_size = @opts[:buffer_size]
  @buffer_size = CONF.INPUT_LOCAL_FILE_BUFFER_SIZE unless @buffer_size
end