本文整理汇总了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry.isUnixSymlink方法的典型用法代码示例。如果您正苦于以下问题:Java ZipArchiveEntry.isUnixSymlink方法的具体用法?Java ZipArchiveEntry.isUnixSymlink怎么用?Java ZipArchiveEntry.isUnixSymlink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.zip.ZipArchiveEntry
的用法示例。
在下文中一共展示了ZipArchiveEntry.isUnixSymlink方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extract
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private static void extract(ZipArchiveEntry zipArchiveEntry, ZipFile zipFile, File outputDir) throws IOException {
File extractedFile = new File(outputDir, zipArchiveEntry.getName());
FileUtils.forceMkdir(extractedFile.getParentFile());
if (zipArchiveEntry.isUnixSymlink()) {
if (PosixUtil.isPosixFileStore(outputDir)) {
logger.debug("Extracting [l] "+zipArchiveEntry.getName());
String symlinkTarget = zipFile.getUnixSymlink(zipArchiveEntry);
Files.createSymbolicLink(extractedFile.toPath(), new File(symlinkTarget).toPath());
} else {
logger.debug("Skipping ! [l] "+zipArchiveEntry.getName());
}
} else if (zipArchiveEntry.isDirectory()) {
logger.debug("Extracting [d] "+zipArchiveEntry.getName());
FileUtils.forceMkdir(extractedFile);
} else {
logger.debug("Extracting [f] "+zipArchiveEntry.getName());
try (
InputStream in = zipFile.getInputStream(zipArchiveEntry);
OutputStream out = new FileOutputStream(extractedFile)
) {
IOUtils.copy(in, out);
}
}
updatePermissions(extractedFile, zipArchiveEntry.getUnixMode());
}
示例2: getZipArchiveEntryNames
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
private static List<String> getZipArchiveEntryNames(File sourceZip) throws IOException {
List<String> content = new ArrayList<>();
try (ZipFile zipFile = new ZipFile(sourceZip);) {
List<ZipArchiveEntry> zipEntries = Collections.list(zipFile.getEntries());
for (ZipArchiveEntry zipEntry : zipEntries) {
if (zipEntry.isUnixSymlink()) {
content.add("[l]"+zipEntry.getName());
} else if (zipEntry.isDirectory()) {
content.add("[d]"+zipEntry.getName());
} else {
content.add("[f]"+zipEntry.getName());
}
}
}
Collections.sort(content);
return content;
}
示例3: extractAll
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
public static void extractAll(String zipFile, String extractDir) throws Exception {
ZipFile unzipFile = new ZipFile(zipFile);
try {
File root = new File(extractDir);
Enumeration<ZipArchiveEntry> fileHeaderList = unzipFile.getEntries();
while(fileHeaderList.hasMoreElements()) {
ZipArchiveEntry fileHeader = fileHeaderList.nextElement();
if (fileHeader.isDirectory()) {
//...
} else if (!fileHeader.isUnixSymlink()) {
File f = new File(root, fileHeader.getName());
File dir = f.getParentFile();
if (!dir.exists()) {
dir.mkdirs();
}
FileOutputStream fout = new FileOutputStream(f);
try {
IOUtils.copy(unzipFile.getInputStream(fileHeader), fout);
} finally {
try {
fout.close();
} catch (Throwable e) {
}
}
f.setLastModified(fileHeader.getLastModifiedDate().getTime());
}
}
} finally {
ZipFile.closeQuietly(unzipFile);
}
}
示例4: extract
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入方法依赖的package包/类
public void extract(IProgressMonitor monitor, IProject project) throws Exception {
HashSet<IContainer> newdir = new HashSet<IContainer>();
ArrayList<ZipArchiveEntry> fileHeaderList = new ArrayList<ZipArchiveEntry>();
for (Enumeration<ZipArchiveEntry> ez = zipFile.getEntries(); ez.hasMoreElements();) {
fileHeaderList.add(ez.nextElement());
}
monitor.beginTask("unzip file", fileHeaderList.size());
Iterator<ZipArchiveEntry> iter = fileHeaderList.iterator();
while(!monitor.isCanceled() && iter.hasNext()) {
ZipArchiveEntry fileHeader = iter.next();
if (fileHeader.isDirectory()) {
//need to handle?
} else if (!fileHeader.isUnixSymlink()){
IFile file = project.getFile(fileHeader.getName());
boolean refreshFile = file.exists();
InputStream is = zipFile.getInputStream(fileHeader);
try {
if (refreshFile) {
file.setContents(is, true, false, monitor);
file.refreshLocal(IFile.DEPTH_ZERO, monitor);
newdir.add(file.getParent());
} else {
if (!file.getParent().exists()) {
IPath path = file.getProjectRelativePath().removeLastSegments(1);
int len = path.segmentCount() - 1;
for (int i = len; i >= 0; i--) {
IFolder fd = project.getFolder(path.removeLastSegments(i));
if (!fd.exists()) {
fd.create(true, true, monitor);
}
}
}
file.create(is, true, monitor);
}
} finally {
//is.close();//file.setContents(...) already do it
}
}
monitor.worked(1);
}
//refresh dir...
for (Iterator iterator = newdir.iterator(); iterator.hasNext();) {
IContainer container = (IContainer) iterator.next();
container.refreshLocal(IFile.DEPTH_ONE, monitor);
}
}