Exemplo n.º 1
0
  public synchronized SVDBFileSystemDataInput readFile(String path, int id) throws IOException {
    SVDBFileSystemDataInput ret = new SVDBFileSystemDataInput();
    byte tmp[] = new byte[BLK_SIZE];
    FileInfo info = null;

    // Read root block
    readBlock(path, id, tmp);
    ret.addPage(tmp);

    int length = ret.readInt(); // Total length of the file
    int nblocks = ret.readInt(); // Number of non-root blocks

    if (fTrackFiles) {
      info = findFileInfo(id);

      if (info == null) {
        System.out.println("readFile: failed to find id=" + id + " " + path);
        try {
          throw new Exception();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      if (info != null && nblocks != info.fBlockIdList.size()) {
        System.out.println(
            "readFile: block count wrong for "
                + id
                + " "
                + path
                + " nblocks="
                + nblocks
                + " actual="
                + info.fBlockIdList.size());
      }
    }

    // Read in the remaining root and storage blocks
    for (int i = 0; i < nblocks; i++) {
      int block_id = ret.readInt();

      if (fTrackFiles && info != null) {
        if (block_id != info.fBlockIdList.get(i)) {
          System.out.println(
              "readFile: block id "
                  + i
                  + " wrong for "
                  + id
                  + " "
                  + path
                  + " block_id="
                  + block_id
                  + " actual="
                  + info.fBlockIdList.get(i));
        }
      }
      tmp = new byte[BLK_SIZE];
      readBlock(path, block_id, tmp);
      ret.addPage(tmp);
    }
    int start_idx = ret.getOffset();
    ret.setStartIdx(start_idx);

    // Compute the initial page and page offset
    ret.finalize(length);

    return ret;
  }