當前位置: 首頁>>代碼示例>>Java>>正文


Java TarArchiveEntry.isLink方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.archivers.tar.TarArchiveEntry.isLink方法的典型用法代碼示例。如果您正苦於以下問題:Java TarArchiveEntry.isLink方法的具體用法?Java TarArchiveEntry.isLink怎麽用?Java TarArchiveEntry.isLink使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.archivers.tar.TarArchiveEntry的用法示例。


在下文中一共展示了TarArchiveEntry.isLink方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: unpackEntries

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //導入方法依賴的package包/類
private static void unpackEntries(TarArchiveInputStream tis,
    TarArchiveEntry entry, File outputDir) throws IOException {
  if (entry.isDirectory()) {
    File subDir = new File(outputDir, entry.getName());
    if (!subDir.mkdirs() && !subDir.isDirectory()) {
      throw new IOException("Mkdirs failed to create tar internal dir "
          + outputDir);
    }

    for (TarArchiveEntry e : entry.getDirectoryEntries()) {
      unpackEntries(tis, e, subDir);
    }

    return;
  }

  File outputFile = new File(outputDir, entry.getName());
  if (!outputFile.getParentFile().exists()) {
    if (!outputFile.getParentFile().mkdirs()) {
      throw new IOException("Mkdirs failed to create tar internal dir "
          + outputDir);
    }
  }

  if (entry.isLink()) {
    File src = new File(outputDir, entry.getLinkName());
    HardLink.createHardLink(src, outputFile);
    return;
  }

  int count;
  byte data[] = new byte[2048];
  try (BufferedOutputStream outputStream = new BufferedOutputStream(
      new FileOutputStream(outputFile));) {

    while ((count = tis.read(data)) != -1) {
      outputStream.write(data, 0, count);
    }

    outputStream.flush();
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:43,代碼來源:FileUtil.java

示例2: extractTxz

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //導入方法依賴的package包/類
/**
 * Unpack archive compressed by tar with xz compression. By default system tar is used (faster). If not found, then the
 * java implementation takes place.
 *
 * @param tbzPath The archive path.
 * @param targetDir The directory to extract the content to.
 */
private static void extractTxz(String tbzPath, String targetDir) throws IOException
{
    try (
            InputStream in = Files.newInputStream(Paths.get(tbzPath));
            XZInputStream xzIn = new XZInputStream(in);
            TarArchiveInputStream tarIn = new TarArchiveInputStream(xzIn)
    ) {
        TarArchiveEntry entry;

        while ((entry = tarIn.getNextTarEntry()) != null) {
            final String individualFile = entry.getName();
            final File fsObject = new File(targetDir + "/" + individualFile);

            if (entry.isSymbolicLink() || entry.isLink()) {
                Path target = FileSystems.getDefault().getPath(entry.getLinkName());
                Files.createSymbolicLink(fsObject.toPath(), target);
            } else if (entry.isFile()) {
                byte[] content = new byte[(int) entry.getSize()];
                int read = tarIn.read(content, 0, content.length);
                if (read == -1) {
                    throw new IllegalStateException("could not read " + individualFile);
                }
                mkdirs(fsObject.getParentFile());
                try (OutputStream outputFile = new FileOutputStream(fsObject)) {
                    IOUtils.write(content, outputFile);
                }
            } else if (entry.isDirectory()) {
                mkdirs(fsObject);
            } else {
                throw new UnsupportedOperationException(
                        String.format("Unsupported entry found: %s", individualFile)
                );
            }

            if (individualFile.startsWith("bin/") || individualFile.startsWith("./bin/")) {
                fsObject.setExecutable(true);
            }
        }
    }
}
 
開發者ID:opentable,項目名稱:otj-pg-embedded,代碼行數:48,代碼來源:EmbeddedPostgres.java

示例3: decompress

import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //導入方法依賴的package包/類
@Override
public Path decompress(DecompressorDescriptor descriptor) throws RepositoryFunctionException {
  Optional<String> prefix = descriptor.prefix();
  boolean foundPrefix = false;

  try (InputStream decompressorStream = getDecompressorStream(descriptor)) {
    TarArchiveInputStream tarStream = new TarArchiveInputStream(decompressorStream);
    TarArchiveEntry entry;
    while ((entry = tarStream.getNextTarEntry()) != null) {
      StripPrefixedPath entryPath = StripPrefixedPath.maybeDeprefix(entry.getName(), prefix);
      foundPrefix = foundPrefix || entryPath.foundPrefix();
      if (entryPath.skip()) {
        continue;
      }

      Path filename = descriptor.repositoryPath().getRelative(entryPath.getPathFragment());
      FileSystemUtils.createDirectoryAndParents(filename.getParentDirectory());
      if (entry.isDirectory()) {
        FileSystemUtils.createDirectoryAndParents(filename);
      } else {
        if (entry.isSymbolicLink() || entry.isLink()) {
          PathFragment linkName = PathFragment.create(entry.getLinkName());
          boolean wasAbsolute = linkName.isAbsolute();
          // Strip the prefix from the link path if set.
          linkName =
              StripPrefixedPath.maybeDeprefix(linkName.getPathString(), prefix).getPathFragment();
          if (wasAbsolute) {
            // Recover the path to an absolute path as maybeDeprefix() relativize the path
            // even if the prefix is not set
            linkName = descriptor.repositoryPath().getRelative(linkName).asFragment();
          }
          if (filename.exists()) {
            filename.delete();
          }
          if (entry.isSymbolicLink()) {
            FileSystemUtils.ensureSymbolicLink(filename, linkName);
          } else {
            FileSystemUtils.createHardLink(
                filename, descriptor.repositoryPath().getRelative(linkName));
          }
        } else {
          Files.copy(
              tarStream, filename.getPathFile().toPath(), StandardCopyOption.REPLACE_EXISTING);
          filename.chmod(entry.getMode());

          // This can only be done on real files, not links, or it will skip the reader to
          // the next "real" file to try to find the mod time info.
          Date lastModified = entry.getLastModifiedDate();
          filename.setLastModifiedTime(lastModified.getTime());
        }
      }
    }
  } catch (IOException e) {
    throw new RepositoryFunctionException(e, Transience.TRANSIENT);
  }

  if (prefix.isPresent() && !foundPrefix) {
    throw new RepositoryFunctionException(
        new IOException("Prefix " + prefix.get() + " was given, but not found in the archive"),
        Transience.PERSISTENT);
  }

  return descriptor.repositoryPath();
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:65,代碼來源:CompressedTarFunction.java


注:本文中的org.apache.commons.compress.archivers.tar.TarArchiveEntry.isLink方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。