示例#1
0
  // TODO Implementation pending
  public Bucket readBucketFromFile(String path, Long offset, String datatype) {

    // If offset is -1 , return null
    // Since the bucket cannot be read.
    if (offset == -1) return null;

    RandomAccessFile raf;
    Bucket temp = new Bucket(this.maxSize, (long) -1);
    byte[] tempData = new byte[4];
    byte[] tempOffsetAddress = new byte[8];
    long tempOffset = 0;
    Comparer comparer = new Comparer();
    try {
      raf = new RandomAccessFile(new File(path), "rw");
      raf.seek(offset);

      raf.read(tempData);
      temp.maxSize = Helper.toInt(tempData);
      raf.read(tempData);
      temp.currentSize = Helper.toInt(tempData);
      raf.read(tempData);
      temp.numberOfOverflowBuckets = Helper.toInt(tempData);

      raf.read(tempOffsetAddress);
      temp.overflowOffset = Helper.toLong(tempOffsetAddress);
      tempOffset = raf.getFilePointer();
      raf.close();

      for (int i = 0; i < this.maxSize; i++) {
        if (datatype.contains("c")) {
          temp.data[i][0] =
              comparer.compare_functions[6].readString(
                  path, (int) tempOffset, Integer.parseInt(datatype.substring(1)));
        } else
          temp.data[i][0] =
              comparer.compare_functions[comparer.mapper.indexOf(datatype)].readString(
                  path, (int) tempOffset, Integer.parseInt(datatype.substring(1)));
        tempOffset += Integer.parseInt(datatype.substring(1));

        temp.data[i][1] = comparer.compare_functions[3].readString(path, (int) tempOffset, 8);
        tempOffset += 8;
      }

      return temp;
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return null;
  }