Exemple #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)));
  }
Exemple #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);
 }
Exemple #3
0
  /** liststatus returns the children of a directory after looking up the index files. */
  @Override
  public FileStatus[] listStatus(Path f) throws IOException {
    // need to see if the file is an index in file
    // get the filestatus of the archive directory
    // we will create fake filestatuses to return
    // to the client
    List<FileStatus> statuses = new ArrayList<FileStatus>();
    Path tmpPath = makeQualified(f);
    Path harPath = getPathInHar(tmpPath);
    HarStatus hstatus = metadata.archive.get(harPath);
    if (hstatus == null) {
      throw new FileNotFoundException("File " + f + " not found in " + archivePath);
    }
    if (hstatus.isDir()) {
      fileStatusesInIndex(hstatus, statuses);
    } else {
      statuses.add(toFileStatus(hstatus, null));
    }

    return statuses.toArray(new FileStatus[statuses.size()]);
  }