本文整理汇总了Java中org.zeroturnaround.zip.ZipUtil.iterate方法的典型用法代码示例。如果您正苦于以下问题:Java ZipUtil.iterate方法的具体用法?Java ZipUtil.iterate怎么用?Java ZipUtil.iterate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.zeroturnaround.zip.ZipUtil
的用法示例。
在下文中一共展示了ZipUtil.iterate方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.zeroturnaround.zip.ZipUtil; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
PackageWriter packageWriter = new DefaultPackageWriter();
Package pkgtoWrite = createSimplePackage();
Path tempPath = Files.createTempDirectory("tests");
File outputDirectory = tempPath.toFile();
File zipFile = packageWriter.write(pkgtoWrite, outputDirectory);
assertThat(zipFile).exists();
assertThat(zipFile.getName()).isEqualTo("myapp-1.0.0.zip");
ZipUtil.iterate(zipFile, new ZipEntryCallback() {
@Override
public void process(InputStream inputStream, ZipEntry zipEntry) throws IOException {
if (zipEntry.getName().equalsIgnoreCase("package.yml")) {
assertExpectedContents(inputStream, "package.yml");
}
if (zipEntry.getName().equalsIgnoreCase("values.yml")) {
assertExpectedContents(inputStream, "values.yml");
}
if (zipEntry.getName().equals("myapp.yml")) {
assertExpectedContents(inputStream, "generic-template.yml");
}
}
});
}
示例2: compareOfflineAndOnline
import org.zeroturnaround.zip.ZipUtil; //导入方法依赖的package包/类
public Map<String, List<Map<File, String>>> compareOfflineAndOnline(String onlineZipPath, String offlineDirPath) {
File existFolder = new File(offlineDirPath);
if (!existFolder.exists()) {
return null;
}
Map<String, List<Map<File,String>>> result = new HashMap<>();
result.put("update", new ArrayList<>());
result.put("add", new ArrayList<>());
ZipUtil.iterate(new File(onlineZipPath), new ZipEntryCallback() {
@Override
public void process(InputStream in, ZipEntry zipEntry) throws IOException {
File fileOffline = new File(existFolder,zipEntry.getName());
if(fileOffline.exists()) { // file for merge
if(zipEntry.getCrc() != getCrc(fileOffline.getAbsolutePath())) {
result.get("update").add(inputToMapping(in, fileOffline));
}
} else { // file for add
result.get("add").add(inputToMapping(in, fileOffline));
}
}
});
return result;
}
示例3: extractZIP
import org.zeroturnaround.zip.ZipUtil; //导入方法依赖的package包/类
/**
* Extract workflows from an archive
* @param byteArrayArchive the archive as byte array
* @return the list of Workflows byte arrays
*/
public List<byte[]> extractZIP(byte[] byteArrayArchive) {
List<byte[]> filesList = new ArrayList<>();
if (byteArrayArchive == null) {
return filesList;
}
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayArchive)) {
ZipUtil.iterate(byteArrayInputStream, (in, zipEntry) -> process(in, zipEntry, filesList));
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
return filesList;
}
示例4: testAllGamesFromArchive
import org.zeroturnaround.zip.ZipUtil; //导入方法依赖的package包/类
@Test
public void testAllGamesFromArchive() {
Path path = Paths.get("src/test/resources/games-aeb-cwi-nl.zip");
ZipUtil.iterate(path.toFile(), new ZipEntryCallback() {
@Override
public void process(InputStream in, ZipEntry zipEntry) throws IOException {
if (zipEntry.toString().endsWith("sgf")) {
try {
Sgf.createFromInputStream(in);
}
catch (SgfParseException e) {
System.out.println("Problem with " + zipEntry.getName());
e.printStackTrace();
Assert.fail();
}
}
}
});
Assert.assertTrue(true);
}
示例5: processZip
import org.zeroturnaround.zip.ZipUtil; //导入方法依赖的package包/类
private void processZip(final String zipName,
final Map<String, ClassInfo> foundClasses) {
final File zip = new File(zipName);
ZipUtil.iterate(zip, new ZipEntryCallback() {
public void process(InputStream in, ZipEntry zipEntry) throws IOException {
if ((!zipEntry.isDirectory()) && (zipEntry.getName().endsWith(".class"))) {
try {
log.trace("Loading " + zipName + "(" + zipEntry.getName() + ")");
loadClassData(in, new ClassInfoClassVisitor(foundClasses, zip));
} catch (ClassFinderException ex) {
log.error("Can't open \"" + zipEntry.getName() + "\" in file \"" + zipName + "\": ", ex);
}
}
}
});
}
示例6: extractFromZip
import org.zeroturnaround.zip.ZipUtil; //导入方法依赖的package包/类
/**
* Extract files from zip archive, not recursive.
*
* @param uploadedFile uploaded zip file
* @return collection of zip files.
*/
private Collection<UserFile> extractFromZip(UploadedFile uploadedFile) {
LOGGER.info("Start extraction from zip file with name=" + uploadedFile.getName());
final List<UserFile> userFiles = new ArrayList<UserFile>();
ZipUtil.iterate(new ByteArrayInputStream(uploadedFile.getContent().getFileContent()), new ZipEntryCallback() {
@Override
public void process(InputStream inputStream, ZipEntry zipEntry) throws IOException {
if (!zipEntry.isDirectory()) {
byte[] content = IOUtils.toByteArray(inputStream);
String xmlSchema = defaultString(xmlSchemaExtractor.extractXmlSchema(content), DUMMY_XML_SCHEMA);
userFiles.add(new UserFile(new UploadedFile(zipEntry.getName(), content), xmlSchema));
}
}
});
LOGGER.info("Extracted " + userFiles.size() + " from zip archive.");
return userFiles;
}
示例7: copySigarLibs
import org.zeroturnaround.zip.ZipUtil; //导入方法依赖的package包/类
private void copySigarLibs(final File libDirectory, File sigarDistributionFile)
throws MojoExecutionException {
try {
ZipUtil.iterate(sigarDistributionFile, new ZipEntryCallback() {
@Override
public void process(InputStream in, ZipEntry zipEntry) throws IOException {
String zipEntryName = zipEntry.getName();
if (zipEntryName.contains("sigar-bin/lib") && !zipEntryName.endsWith("/")) {
String compressedFileName = zipEntryName.substring(zipEntryName.lastIndexOf("/") + 1);
if (compressedFileName.endsWith(".so") || compressedFileName.endsWith(".dll") ||
compressedFileName.endsWith(".sl") || compressedFileName.endsWith(".dylib")
|| compressedFileName.equals("sigar.jar")) {
File destinationFile = new File(libDirectory, compressedFileName);
copyStreamToFile(new RawInputStreamFacade(in), destinationFile);
}
}
}
});
} catch (Exception e) {
throw new MojoExecutionException("Could not unpack Sigar file " + sigarDistributionFile
.getAbsolutePath(), e);
}
}
示例8: assertZipWithFileHierarchy
import org.zeroturnaround.zip.ZipUtil; //导入方法依赖的package包/类
private void assertZipWithFileHierarchy(Path archivePath) {
final int[] nbEntries = { 0 };
// Reads ZIP content using a third-party library
ZipUtil.iterate(archivePath.toFile(), new ZipEntryCallback() {
@Override
public void process(InputStream in, ZipEntry zipEntry) throws IOException {
nbEntries[0]++;
}
});
assertThat(nbEntries[0]).isEqualTo(HIERARCHY_DEPTH + 1);
}
示例9: getMinimizedEntries
import org.zeroturnaround.zip.ZipUtil; //导入方法依赖的package包/类
private ZipEntrySource[] getMinimizedEntries(File minimizedJarFile, String currentArtifactFileName) {
final Set<ZipEntrySource> resultEntriesSet = Sets.newHashSet();
ZipUtil.iterate(minimizedJarFile, new ZipEntryCallback() {
public void process(InputStream in, ZipEntry minimizedEntry) throws IOException {
final String minimizedEntryName = minimizedEntry.getName();
resultEntriesSet.add(new ByteSource(minimizedEntryName, readBytes(in)));
}
});
return resultEntriesSet.toArray(new ZipEntrySource[resultEntriesSet.size()]);
}
示例10: getCurrentArtifactNames
import org.zeroturnaround.zip.ZipUtil; //导入方法依赖的package包/类
private Set<String> getCurrentArtifactNames(File currentArtifactFile) {
final Set<String> result = Sets.newHashSet();
ZipUtil.iterate(currentArtifactFile, new ZipEntryCallback() {
public void process(InputStream in, ZipEntry currentEntry) throws IOException {
result.add(currentEntry.getName());
}
});
return result;
}