private static List<String> getZipFileList(File file) { List<String> filesList = new ArrayList<>(); try (ZipFile zipFile = new ZipFile(file)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); filesList.add(entry.getName()); } } catch (Exception e) { LOG.error("Error read zip file '{}'", file.getAbsolutePath(), e); } return filesList; }
@Override public Predicate<ZipEntry> filter(ZipEntry entry) { return zipEntry -> !zipEntry.isDirectory() && zipEntry.getName().contains(PROCESSES); }
public String getFileContentInsideZip(ZipInputStream zipInputStream, String file) throws IOException { ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { if (new File(zipEntry.getName()).getName().equals(file)) { return IOUtils.toString(zipInputStream, UTF_8); } zipEntry = zipInputStream.getNextEntry(); } return null; }
List<String> classNames = new ArrayList<String>(); ZipInputStream zip = new ZipInputStream(new FileInputStream("/path/to/jar/file.jar")); for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) { if (!entry.isDirectory() && entry.getName().endsWith(".class")) { // This ZipEntry represents a class. Now, what class does it represent? String className = entry.getName().replace('/', '.'); // including ".class" classNames.add(className.substring(0, className.length() - ".class".length())); } }
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException { if (entry.isDirectory()) { createDir(new File(outputDir, entry.getName())); return; } File outputFile = new File(outputDir, entry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); try { IOUtils.copy(inputStream, outputStream); } finally { outputStream.close(); inputStream.close(); } }
private void moveToNext() { next = null; while (entries.hasMoreElements()) { ZipEntry jarEntry = entries.nextElement(); String entryName = jarEntry.getName(); if (entryName.startsWith(path) && Helpers.hasSuffix(suffix, entryName)) { next = new ZipResource(jarFile, jarEntry); break; } } } }
CodeSource src = MyClass.class.getProtectionDomain().getCodeSource(); if (src != null) { URL jar = src.getLocation(); ZipInputStream zip = new ZipInputStream(jar.openStream()); while(true) { ZipEntry e = zip.getNextEntry(); if (e == null) break; String name = e.getName(); if (name.startsWith("path/to/your/dir/")) { /* Do something with this entry. */ ... } } } else { /* Fail... */ }
public static NutResource makeJarNutResource(String filePath) { JarEntryInfo jeInfo = new JarEntryInfo(filePath); try { ZipInputStream zis = makeZipInputStream(jeInfo.getJarPath()); ZipEntry ens = null; while (null != (ens = zis.getNextEntry())) { if (ens.isDirectory()) continue; if (jeInfo.getEntryName().equals(ens.getName())) { return makeJarNutResource(jeInfo.getJarPath(), ens.getName(), ""); } } } catch (IOException e) {} return null; }
@Override public Chunk read() throws IOException { ZipEntry entry = zipIn.getNextEntry(); if (entry == null) { return null; } int read; ByteArrayOutputStream contentByteArray = new ByteArrayOutputStream(); while (-1 != (read = zipIn.read())) { contentByteArray.write(read); } return new Chunk(StringUtil.fromHex(entry.getName()), contentByteArray.toByteArray(), contentByteArray.size(), null); }
public void handle(InputStream stream) throws IOException { ZipInputStream zipInputStream = new ZipInputStream(stream); LOG.info("[Agent Fetch Artifact] Downloading from '{}' to '{}'. Will read from Socket stream to compute MD5 and write to file", srcFile, destOnAgent.getAbsolutePath()); long before = System.currentTimeMillis(); new ZipUtil((entry, stream1) -> { LOG.info("[Agent Fetch Artifact] Downloading a directory from '{}' to '{}'. Handling the entry: '{}'", srcFile, destOnAgent.getAbsolutePath(), entry.getName()); new ChecksumValidator(artifactMd5Checksums).validate(getSrcFilePath(entry), md5Hex(stream1), checksumValidationPublisher); }).unzip(zipInputStream, destOnAgent); LOG.info("[Agent Fetch Artifact] Downloading a directory from '{}' to '{}'. Took: {}ms", srcFile, destOnAgent.getAbsolutePath(), System.currentTimeMillis() - before); }
/** * Return the files' path in ZIP file. * * @param zipFile The ZIP file. * @return the files' path in ZIP file * @throws IOException if an I/O error has occurred */ public static List<String> getFilesPath(final File zipFile) throws IOException { if (zipFile == null) return null; List<String> paths = new ArrayList<>(); ZipFile zip = new ZipFile(zipFile); Enumeration<?> entries = zip.entries(); while (entries.hasMoreElements()) { String entryName = ((ZipEntry) entries.nextElement()).getName(); if (entryName.contains("../")) { System.out.println("entryName: " + entryName + " is dangerous!"); paths.add(entryName); } else { paths.add(entryName); } } zip.close(); return paths; }
private InputStream getDataFromZip(InputStream is, String name) throws IOException { final ZipInputStream zis = new ZipInputStream(is); ZipEntry ze = zis.getNextEntry(); while (ze != null) { final String fileName = ze.getName(); if (ze.isDirectory()) { } else if (fileName.equals(name)) { return zis; } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); return null; }
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException { if (entry.isDirectory()) { createDir(new File(outputDir, entry.getName())); return; } File outputFile = new File(outputDir, entry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); try { IOUtils.copy(inputStream, outputStream); } finally { outputStream.close(); inputStream.close(); } }
public void load(File input) throws IOException, DecodeException { String name = input.getName(); try (InputStream inputStream = new FileInputStream(input)) { if (name.endsWith(CLST_EXTENSION)) { load(inputStream); } else if (name.endsWith(".jar")) { try (ZipInputStream in = new ZipInputStream(inputStream)) { ZipEntry entry = in.getNextEntry(); while (entry != null) { if (entry.getName().endsWith(CLST_EXTENSION) && ZipSecurity.isValidZipEntry(entry)) { load(in); } entry = in.getNextEntry(); } } } else { throw new JadxRuntimeException("Unknown file format: " + name); } } }
private boolean accept(final ZipEntry entry) { if (entry.isDirectory()) { return false; } if (entryNameFilter == null) { return true; } for (final String filter : entryNameFilter) { if (entry.getName().startsWith(filter)) { return true; } } return false; }
public DeploymentBuilder addZipInputStream(ZipInputStream zipInputStream) { try { ZipEntry entry = zipInputStream.getNextEntry(); while (entry != null) { if (!entry.isDirectory()) { String entryName = entry.getName(); byte[] bytes = IoUtil.readInputStream(zipInputStream, entryName); ResourceEntity resource = resourceEntityManager.create(); resource.setName(entryName); resource.setBytes(bytes); deployment.addResource(resource); } entry = zipInputStream.getNextEntry(); } } catch (Exception e) { throw new ActivitiException("problem reading zip input stream", e); } return this; }
public InputStream getInputStream() throws IOException { ZipInputStream zis = Scans.makeZipInputStream(jarPath); ZipEntry ens = null; while (null != (ens = zis.getNextEntry())) { if (ens.getName().equals(entryName)) return zis; } throw Lang.impossible(); }
@Override public boolean isValid() { for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) { ZipEntry testEntry = e.nextElement(); if (testEntry.getName().matches(".*\\.mcr$") || testEntry.getName().matches(".*\\.mca$")) { // TODO: does this need a separate class? return true; } } return false; } }
public InputStream open() throws IOException { final ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { final String fileName = ze.getName(); if (ze.isDirectory()) { } else if (fileName.trim().equalsIgnoreCase(entry.trim())) { return zis; } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); throw new IOException(); }
private void loadZipFile(File file) throws IOException { this.entries.clear(); final PrintWriter pw = new PrintWriter("tmp.txt"); final ZipInputStream zis = new ZipInputStream(new FileInputStream(file)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { final String fileName = ze.getName(); this.entries.add(fileName); if (fileName.endsWith("/") == false) { pw.println("<file name=\"" + fileName + "\" />"); } ze = zis.getNextEntry(); } pw.close(); zis.close(); }