示例#1
0
  public void writeBucketToFile(String path, Long offset, String datatype) {

    //		this.writeData(); // For testing purposes.
    RandomAccessFile raf;
    Comparer comparer = new Comparer();

    try {
      raf = new RandomAccessFile(new File(path), "rw");
      raf.seek(offset);

      raf.write(Helper.toByta(this.maxSize));
      raf.write(Helper.toByta(this.currentSize));
      raf.write(Helper.toByta(this.numberOfOverflowBuckets));
      raf.write(Helper.toByta(this.overflowOffset));
      offset = raf.getFilePointer();

      for (int i = 0; i < this.maxSize; i++) {
        if (datatype.contains("c")) {
          comparer.compare_functions[6].writeAtOffset(
              raf, offset, this.data[i][0] + "", Integer.parseInt(datatype.substring(1)));
        }
        // Use appropriate write method based on the datatype that the index file holds.
        else
          comparer.compare_functions[comparer.mapper.indexOf(datatype)].writeAtOffset(
              raf, offset, this.data[i][0] + "", Integer.parseInt(datatype.substring(1)));
        offset += Integer.parseInt(datatype.substring(1));
        // Write the pointer , right after the
        comparer.compare_functions[3].writeAtOffset(raf, offset, this.data[i][1] + "", 8);
        offset += 8;
      }
      raf.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }