Class: Ferret::Store::FSDirectory::FSIndexInput

Inherits:
BufferedIndexInput show all
Defined in:
lib/ferret/store/fs_store.rb

Overview

A file system input stream extending InputStream to read from the file system

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BufferedIndexInput

#pos, #read_byte, #read_bytes, #read_chars, #read_int, #read_long, #read_string, #read_uint, #read_ulong, #read_vint, #read_vlong, #refill, #seek

Methods inherited from IndexInput

#pos, #read_byte, #read_bytes, #read_chars, #read_int, #read_long, #read_string, #read_uint, #read_ulong, #read_vint, #seek

Constructor Details

#initialize(path) ⇒ FSIndexInput

Returns a new instance of FSIndexInput.



277
278
279
280
281
282
283
284
285
286
287
# File 'lib/ferret/store/fs_store.rb', line 277

def initialize(path)
  @file = File.open(path, "rb")
  @file.extend(MonitorMixin)
  #class <<@file
  #  attr_accessor :ref_count
  #end
  #@file.ref_count = 1
  @length = File.size(path)
  @is_clone = false
  super()
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



275
276
277
# File 'lib/ferret/store/fs_store.rb', line 275

def file
  @file
end

#is_cloneObject

Returns the value of attribute is_clone.



274
275
276
# File 'lib/ferret/store/fs_store.rb', line 274

def is_clone
  @is_clone
end

#lengthObject (readonly)

Returns the value of attribute length.



275
276
277
# File 'lib/ferret/store/fs_store.rb', line 275

def length
  @length
end

Instance Method Details

#closeObject



289
290
291
292
293
# File 'lib/ferret/store/fs_store.rb', line 289

def close
  #@file.ref_count -= 1
  #@file.close if @file.ref_count == 0
  @file.close if not @is_clone
end

#initialize_copy(o) ⇒ Object

We need to record if this is a clone so we know when to close the file. The file should only be closed when the original FSIndexInput is closed.



297
298
299
300
# File 'lib/ferret/store/fs_store.rb', line 297

def initialize_copy(o)
  super
  @is_clone = true
end