本文整理汇总了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();
}
}
示例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);
}
}
}
}
示例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();
}