Esempio n. 1
0
  public FileTree visit(FileVisitor visitor) {
    if (!tarFile.exists()) {
      return this;
    }
    if (!tarFile.isFile()) {
      throw new InvalidUserDataException(
          String.format("Cannot expand %s as it is not a file.", this));
    }

    AtomicBoolean stopFlag = new AtomicBoolean();
    try {
      FileInputStream inputStream = new FileInputStream(tarFile);
      try {
        NoCloseTarInputStream tar = new NoCloseTarInputStream(inputStream);
        TarArchiveEntry entry;
        while (!stopFlag.get() && (entry = tar.getNextTarEntry()) != null) {
          if (entry.isDirectory()) {
            visitor.visitDir(new DetailsImpl(entry, tar, stopFlag));
          } else {
            visitor.visitFile(new DetailsImpl(entry, tar, stopFlag));
          }
        }
      } finally {
        inputStream.close();
      }
    } catch (Exception e) {
      throw new GradleException(String.format("Could not expand %s.", this), e);
    }

    return this;
  }
Esempio n. 2
0
 public InputStream open() {
   if (read && file != null) {
     return GFileUtils.openInputStream(file);
   }
   if (read || tar.getCurrent() != entry) {
     throw new UnsupportedOperationException(
         String.format("The contents of %s has already been read.", this));
   }
   read = true;
   return tar;
 }