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


Java ZipArchiveEntry.isUnixSymlink方法代碼示例

本文整理匯總了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());
}
 
開發者ID:ctco,項目名稱:gradle-mobile-plugin,代碼行數:26,代碼來源:ZipUtil.java

示例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;
}
 
開發者ID:ctco,項目名稱:gradle-mobile-plugin,代碼行數:18,代碼來源:ZipUtilTest.java

示例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);
	}
}
 
開發者ID:BeckYang,項目名稱:TeamFileList,代碼行數:32,代碼來源:ZipUtil.java

示例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);
	}
}
 
開發者ID:BeckYang,項目名稱:TeamFileList,代碼行數:48,代碼來源:ZipUtil.java


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