本文整理汇总了Java中org.apache.commons.compress.archivers.tar.TarArchiveEntry.getLinkName方法的典型用法代码示例。如果您正苦于以下问题:Java TarArchiveEntry.getLinkName方法的具体用法?Java TarArchiveEntry.getLinkName怎么用?Java TarArchiveEntry.getLinkName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.tar.TarArchiveEntry
的用法示例。
在下文中一共展示了TarArchiveEntry.getLinkName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TarDriverEntry
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
protected TarDriverEntry(
final String name,
final TarArchiveEntry template) {
super(name, true);
//this.init = SIZE | MODTIME;
super.setMode(template.getMode());
this.setModTime0(template.getModTime().getTime());
this.setSize0(template.getSize());
super.setUserId(template.getLongUserId());
super.setUserName(template.getUserName());
super.setGroupId(template.getLongGroupId());
super.setGroupName(template.getGroupName());
super.setLinkName(template.getLinkName());
super.setDevMajor(template.getDevMajor());
super.setDevMinor(template.getDevMinor());
}
示例2: 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();
}
}
示例3: extractArchive
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private static void extractArchive(Path destDir, TarArchiveInputStream archive, ExtractListener listener)
throws IOException
{
String prefix = destDir.toString();
TarArchiveEntry entry;
while (true) {
entry = archive.getNextTarEntry();
if (entry == null) {
break;
}
Path path = destDir.resolve(entry.getName()).normalize();
if (!path.toString().startsWith(prefix)) {
throw new RuntimeException("Archive includes an invalid entry: " + entry.getName());
}
if (entry.isDirectory()) {
Files.createDirectories(path);
}
else if (entry.isSymbolicLink()) {
Files.createDirectories(path.getParent());
String dest = entry.getLinkName();
Path destAbsPath = path.getParent().resolve(dest).normalize();
if (!destAbsPath.normalize().toString().startsWith(prefix)) {
throw new RuntimeException("Archive includes an invalid symlink: " + entry.getName() + " -> " + dest);
}
if (listener != null) {
listener.symlink(destDir.relativize(path), dest);
}
Files.createSymbolicLink(path, Paths.get(dest));
}
else {
Files.createDirectories(path.getParent());
if (listener != null) {
listener.file(destDir.relativize(path));
}
try (OutputStream out = Files.newOutputStream(path)) {
ByteStreams.copy(archive, out);
}
}
if (!Files.isSymbolicLink(path)) {
Files.setPosixFilePermissions(path, getPosixFilePermissions(entry));
}
}
}