Java Code Examples for org.zeroturnaround.zip.ZipUtil#iterate()
The following examples show how to use
org.zeroturnaround.zip.ZipUtil#iterate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadContentService.java From zest-writer with GNU General Public License v3.0 | 6 votes |
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; }
Example 2
Source File: PackageWriterTests.java From spring-cloud-skipper with Apache License 2.0 | 5 votes |
@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"); final AtomicInteger processedEntries = new AtomicInteger(3); ZipUtil.iterate(zipFile, new ZipEntryCallback() { @Override public void process(InputStream inputStream, ZipEntry zipEntry) throws IOException { if (zipEntry.getName().equals("myapp-1.0.0/package.yml")) { assertExpectedContents(inputStream, "package.yml"); processedEntries.decrementAndGet(); } if (zipEntry.getName().equals("myapp-1.0.0/values.yml")) { assertExpectedContents(inputStream, "values.yml"); processedEntries.decrementAndGet(); } if (zipEntry.getName().equals("myapp-1.0.0/templates/myapp.yml")) { assertExpectedContents(inputStream, "generic-template.yml"); processedEntries.decrementAndGet(); } } }); // make sure we asserted all fields assertThat(processedEntries.get()).isEqualTo(0); }
Example 3
Source File: VFSZipperZIPTest.java From scheduling with GNU Affero General Public License v3.0 | 5 votes |
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); }
Example 4
Source File: OptifineVersion.java From OptiFabric with Mozilla Public License 2.0 | 4 votes |
private static JarType getJarType(File file) throws IOException { ClassNode classNode; try (JarFile jarFile = new JarFile(file)) { JarEntry jarEntry = jarFile.getJarEntry("net/optifine/Config.class"); // New 1.14.3 location if (jarEntry == null) { return JarType.SOMETHINGELSE; } classNode = ASMUtils.asClassNode(jarEntry, jarFile); } for (FieldNode fieldNode : classNode.fields) { if (fieldNode.name.equals("VERSION")) { version = (String) fieldNode.value; } if (fieldNode.name.equals("MC_VERSION")) { minecraftVersion = (String) fieldNode.value; } } if (version == null || version.isEmpty() || minecraftVersion == null || minecraftVersion.isEmpty()) { return JarType.INCOMPATIBE; } String currentMcVersion = "unknown"; try { try(InputStream is = OptifineVersion.class.getResourceAsStream("/version.json")){ try(InputStreamReader isr = new InputStreamReader(is)){ JsonObject jsonObject = new Gson().fromJson(isr, JsonObject.class); currentMcVersion = jsonObject.get("name").getAsString(); } } } catch (Exception e){ OptifabricError.setError("Failed to find minecraft version"); e.printStackTrace(); return JarType.INCOMPATIBE; } if (!currentMcVersion.equals(minecraftVersion)) { OptifabricError.setError(String.format("This version of optifine is not compatible with the current minecraft version\n\n Optifine requires %s you have %s", minecraftVersion, currentMcVersion)); return JarType.INCOMPATIBE; } Holder<Boolean> isInstaller = new Holder<>(false); ZipUtil.iterate(file, (in, zipEntry) -> { if (zipEntry.getName().startsWith("patch/")) { isInstaller.setValue(true); } }); if (isInstaller.getValue()) { return JarType.OPTFINE_INSTALLER; } else { return JarType.OPIFINE_MOD; } }