示例#1
0
  /**
   * Combine the status stored in the index and the underlying status.
   *
   * @param h status stored in the index
   * @param cache caching the underlying file statuses
   * @return the combined file status
   * @throws IOException
   */
  private FileStatus toFileStatus(HarStatus h, Map<String, FileStatus> cache) throws IOException {
    FileStatus underlying = null;
    if (cache != null) {
      underlying = cache.get(h.partName);
    }
    if (underlying == null) {
      final Path p = h.isDir ? archivePath : new Path(archivePath, h.partName);
      underlying = fs.getFileStatus(p);
      if (cache != null) {
        cache.put(h.partName, underlying);
      }
    }

    long modTime = 0;
    int version = metadata.getVersion();
    if (version < 3) {
      modTime = underlying.getModificationTime();
    } else if (version == 3) {
      modTime = h.getModificationTime();
    }

    return new FileStatus(
        h.isDir() ? 0L : h.getLength(),
        h.isDir(),
        underlying.getReplication(),
        underlying.getBlockSize(),
        modTime,
        underlying.getAccessTime(),
        underlying.getPermission(),
        underlying.getOwner(),
        underlying.getGroup(),
        makeRelative(this.uri.getPath(), new Path(h.name)));
  }
示例#2
0
 /**
  * Returns a har input stream which fakes end of file. It reads the index files to get the part
  * file name and the size and start of the file.
  */
 @Override
 public FSDataInputStream open(Path f, int bufferSize) throws IOException {
   // get the fs DataInputStream for the underlying file
   HarStatus hstatus = getFileHarStatus(f);
   if (hstatus.isDir()) {
     throw new FileNotFoundException(f + " : not a file in " + archivePath);
   }
   return new HarFSDataInputStream(
       fs,
       new Path(archivePath, hstatus.getPartName()),
       hstatus.getStartIndex(),
       hstatus.getLength(),
       bufferSize);
 }