class ExternalSortModule::ChunkReader

Chunk subclass that performs streaming reading of target with sliding window

Public Class Methods

new(target_file, target_offset, target_length, element_size, chunk_size = MAX_CHUNK_SIZE_) click to toggle source
Calls superclass method ExternalSortModule::Chunk::new
# File lib/geotree/externalsort.rb, line 98
def initialize(target_file, target_offset, target_length, element_size, chunk_size = MAX_CHUNK_SIZE_)
  super(target_file,target_offset,target_length,element_size, chunk_size)
end

Public Instance Methods

peek() click to toggle source

Get next element @return (array, offset) containing element, or nil if chunk is done

# File lib/geotree/externalsort.rb, line 112
def peek
  nil if done

  # If no more elements exist in the buffer, fill it from the target
  if @buffer_offset == @buffer.size
    max_size = @max_chunk_size

    chunk_size = [@target_end_offset - @target_offset, max_size].min

    f = @target_file
    f.pos = @target_offset
    @buffer = f.read(chunk_size)
    raise IOError if !@buffer || @buffer.size != chunk_size

    @target_offset += chunk_size
    @buffer_offset = 0
  end
  [@buffer, @buffer_offset]
end
peek_dump() click to toggle source

Display record being viewed using hex dump

# File lib/geotree/externalsort.rb, line 103
def peek_dump
  "(done)" if done

  buff, off = peek
  "Next element: "+hex_dump_to_string(buff,nil,off,@element_size)
end
read() click to toggle source

Read next element, advance pointers @return (array, offset) containing element @raise IllegalStateException if already done

# File lib/geotree/externalsort.rb, line 135
def read
  ret = peek
  raise IllegalStateException if !ret
  @buffer_offset += @element_size
  ret
end