Class: Ferret::Store::IndexOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/ferret/store/index_io.rb,
ext/index_io.c

Overview

Ferret’s IO Output methods are defined here. The methods write_byte and write_bytes need to be defined before this class is of any use.

Direct Known Subclasses

BufferedIndexOutput

Instance Method Summary collapse

Instance Method Details

#closeObject

Closes this stream to further operations.

Raises:

  • (NotImplementedError)


239
240
241
# File 'lib/ferret/store/index_io.rb', line 239

def close
  raise NotImplementedError
end

#flushObject

Forces any buffered output to be written.

Raises:

  • (NotImplementedError)


234
235
236
# File 'lib/ferret/store/index_io.rb', line 234

def flush
  raise NotImplementedError
end

#lengthObject

The number of bytes in the file.

Raises:

  • (NotImplementedError)


255
256
257
# File 'lib/ferret/store/index_io.rb', line 255

def length
  raise NotImplementedError
end

#posObject

Returns the current position in this file, where the next write will occur.

Raises:

  • (NotImplementedError)


245
246
247
# File 'lib/ferret/store/index_io.rb', line 245

def pos
  raise NotImplementedError
end

#seek(pos) ⇒ Object

Sets current position in this file, where the next write will occur.

Raises:

  • (NotImplementedError)


250
251
252
# File 'lib/ferret/store/index_io.rb', line 250

def seek(pos)
  raise NotImplementedError
end

#write_byte(b) ⇒ Object

Writes a single byte.

Raises:

  • (NotImplementedError)


162
163
164
# File 'lib/ferret/store/index_io.rb', line 162

def write_byte(b)
  raise NotImplementedError
end

#write_bytes(buf, len) ⇒ Object

Writes an array of bytes.

buf

the bytes to write

len

the number of bytes to write

Raises:

  • (NotImplementedError)


169
170
171
# File 'lib/ferret/store/index_io.rb', line 169

def write_bytes(buf, len)
  raise NotImplementedError
end

#write_chars(buf, start, length) ⇒ Object

Writes a sequence of UTF-8 encoded characters from a string.

buf

the source of the characters

start

the first character in the sequence

length

the number of characters in the sequence



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/ferret/store/index_io.rb', line 212

def write_chars(buf, start, length)
  last = start + length
  (start ... last).each do |i|
    write_byte(buf[i])
#          code = buf[i]
#          if code >= 0x01 and code <= 0x7F
#            write_byte(code)
#          else
#            # We need to write unicode characters. ToDo: test that this works.
#            if code > 0x80 and code <= 0x7FF or code == 0
#              write_byte(0xC0 | code >> 6)
#              write_byte(0x80 | code & 0x3F)
#            else
#              write_byte(0xE0 | (code >> 12))
#              write_byte(0x80 | ((code >> 6) & 0x3F))
#              write_byte(0x80 | (code & 0x3F))
#            end
#          end
  end
end

#write_int(i) ⇒ Object Also known as: write_uint

Writes an int as four bytes.



174
175
176
177
178
179
# File 'lib/ferret/store/index_io.rb', line 174

def write_int(i)
  write_byte((i >> 24) & 0xFF)
  write_byte((i >> 16) & 0xFF)
  write_byte((i >>  8) & 0xFF)
  write_byte(i & 0xFF)
end

#write_long(i) ⇒ Object Also known as: write_ulong

Writes a long as eight bytes.



195
196
197
198
# File 'lib/ferret/store/index_io.rb', line 195

def write_long(i)
  write_int(i >> 32)
  write_int(i)
end

#write_string(s) ⇒ Object

Writes a string.



202
203
204
205
206
# File 'lib/ferret/store/index_io.rb', line 202

def write_string(s)
  length = s.length()
  write_vint(length)
  write_chars(s, 0, length)
end

#write_vint(i) ⇒ Object Also known as: write_vlong

Writes an int in a variable-length format. Writes between one and five bytes. Smaller values take fewer bytes. Negative numbers are not supported.



185
186
187
188
189
190
191
# File 'lib/ferret/store/index_io.rb', line 185

def write_vint(i)
  while i > 127
    write_byte((i & 0x7f) | 0x80)
    i >>= 7
  end
  write_byte(i)
end