Class: Ferret::Store::RAMDirectory::RAMIndexOutput
Instance Method Summary
collapse
#flush, #pos, #write_byte, #write_bytes, #write_chars, #write_int, #write_long, #write_string, #write_uint, #write_ulong, #write_vint, #write_vlong
Methods inherited from IndexOutput
#flush, #pos, #write_byte, #write_bytes, #write_chars, #write_int, #write_long, #write_string, #write_vint
Constructor Details
#initialize(ramfile) ⇒ Object
**************************************************************************
RAMIndexOutput Methods
**************************************************************************
73
74
75
76
77
|
# File 'ext/ram_directory.c', line 73
def initialize(f)
@file = f
@pointer = 0
super()
end
|
Instance Method Details
#close ⇒ Object
164
165
166
167
|
# File 'ext/ram_directory.c', line 164
def close
super()
@file.mtime = Time.new
end
|
#flush_buffer(rsrc, rlen) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'ext/ram_directory.c', line 98
def flush_buffer(src, len)
buffer_number = (@pointer / BUFFER_SIZE).to_i
buffer_offset = @pointer % BUFFER_SIZE
bytes_in_buffer = BUFFER_SIZE - buffer_offset
bytes_to_copy = [bytes_in_buffer, len].min
extend_buffer_if_necessary(buffer_number)
buffer = @file.buffers[buffer_number]
buffer[buffer_offset, bytes_to_copy] = src[0, bytes_to_copy]
if bytes_to_copy < len
src_offset = bytes_to_copy
bytes_to_copy = len - bytes_to_copy
buffer_number += 1
extend_buffer_if_necessary(buffer_number)
buffer = @file.buffers[buffer_number]
buffer[0, bytes_to_copy] = src[src_offset, bytes_to_copy]
end
@pointer += len
@file.length = @pointer unless @pointer < @file.length
@file.mtime = Time.now
end
|
#length ⇒ Object
81
82
83
|
# File 'ext/ram_directory.c', line 81
def length
return @file.length
end
|
#reset ⇒ Object
150
151
152
153
|
# File 'ext/ram_directory.c', line 150
def reset
seek(0)
@file.length = 0
end
|
#seek(rpos) ⇒ Object
140
141
142
143
|
# File 'ext/ram_directory.c', line 140
def seek(pos)
super(pos)
@pointer = pos
end
|
#write_to(routput) ⇒ Object
175
176
177
178
179
180
181
182
183
|
# File 'ext/ram_directory.c', line 175
def write_to(output)
flush()
last_buffer_number = (@file.length / BUFFER_SIZE).to_i
last_buffer_offset = @file.length % BUFFER_SIZE
@file.buffers.each_with_index do |buffer, i|
len = (i == last_buffer_number ? last_buffer_offset : BUFFER_SIZE)
output.write_bytes(buffer, len)
end
end
|