/** * 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; }
public static String getZipEntryMd5(File file, String entryName) { ZipFile zipFile = null; try { zipFile = new ZipFile(file); ZipEntry entry = zipFile.getEntry(entryName); if (entry == null) { return null; } return MD5.getMD5(zipFile.getInputStream(entry), 1024 * 100); } catch (IOException e) { e.printStackTrace(); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; }
public InputStream next() throws IOException { while (entries.hasMoreElements()) { current = entries.nextElement(); if (accept(current)) { return zipFile.getInputStream(current); } } // no more entries in this ZipFile, so close ZipFile try { // zipFile is never null here zipFile.close(); } catch (IOException ex) { // SUPPRESS CHECKSTYLE EmptyBlockCheck // suppress IOException, otherwise close() is called twice } return null; }
/** * Return the files' comment in ZIP file. * * @param zipFile The ZIP file. * @return the files' comment in ZIP file * @throws IOException if an I/O error has occurred */ public static List<String> getComments(final File zipFile) throws IOException { if (zipFile == null) return null; List<String> comments = new ArrayList<>(); ZipFile zip = new ZipFile(zipFile); Enumeration<?> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = ((ZipEntry) entries.nextElement()); comments.add(entry.getComment()); } zip.close(); return comments; }
public static LexicalizedParser loadModelFromZip(String zipFilename, String modelName) { LexicalizedParser parser = null; try { File file = new File(zipFilename); if (file.exists()) { ZipFile zin = new ZipFile(file); ZipEntry zentry = zin.getEntry(modelName); if (zentry != null) { InputStream in = zin.getInputStream(zentry); // gunzip it if necessary if (modelName.endsWith(".gz")) { in = new GZIPInputStream(in); } ObjectInputStream ois = new ObjectInputStream(in); parser = loadModel(ois); ois.close(); in.close(); } zin.close(); } else { throw new FileNotFoundException("Could not find " + modelName + " inside " + zipFilename); } } catch (IOException e) { throw new RuntimeIOException(e); } return parser; }
List<Object[]> media = new ArrayList<>(); JSONObject meta = new JSONObject(Utils.convertStreamToString(z.getInputStream(z.getEntry("_meta")))); for (ZipEntry i : Collections.list(z.entries())) { if (i.getName().equals("_meta")) { String name = meta.getString(i.getName()); Utils.writeToFile(z.getInputStream(i), destPath); String csum = Utils.fileChecksum(destPath); throw new RuntimeException(e); } finally { z.close();
checkDirectory(filePath); ZipFile zipFile = new ZipFile(fileName); Enumeration enumeration = zipFile.entries(); try { while (enumeration.hasMoreElements()) { ZipEntry entry = (ZipEntry) enumeration.nextElement(); if (entry.isDirectory()) { new File(filePath, entry.getName()).mkdirs(); continue; BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); File file = new File(filePath + File.separator + entry.getName()); zipFile.close();
ZipFile zipFile = null; try { zipFile = new ZipFile(file); ZipEntry entry = zipFile.getEntry(DexFormat.DEX_IN_JAR_NAME); if (entry != null) { InputStream inputStream = null; try { inputStream = zipFile.getInputStream(entry); loadFrom(inputStream, (int) entry.getSize()); } finally { if (zipFile != null) { try { zipFile.close(); } catch (Exception e) {
private List<RpcMethodDefinition> searchJar(String jarpath, String serviceName) throws IOException { List<RpcMethodDefinition> defs = new ArrayList<>(); File jarFile = new File(jarpath); if (!jarFile.exists() || jarFile.isDirectory()) { return defs; } ZipInputStream zip = new ZipInputStream(new FileInputStream(jarFile)); ZipEntry ze; while ((ze = zip.getNextEntry()) != null) { String entryName = ze.getName(); if (entryName.endsWith(".proto")) { ZipFile zipFile = new ZipFile(jarFile); try (InputStream in = zipFile.getInputStream(ze)) { defs.addAll(inspectProtoFile(entryName, in, serviceName)); } zipFile.close(); } } zip.close(); return defs; }
try{ ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), 0); ZipFile zf = new ZipFile(ai.sourceDir); ZipEntry ze = zf.getEntry("classes.dex"); long time = ze.getTime(); String s = SimpleDateFormat.getInstance().format(new java.util.Date(time)); zf.close(); }catch(Exception e){ }
java.util.zip.ZipFile zipFile = new ZipFile(file); try { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File entryDestination = new File(outputDir, entry.getName()); if (entry.isDirectory()) { entryDestination.mkdirs(); } else { entryDestination.getParentFile().mkdirs(); InputStream in = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream(entryDestination); IOUtils.copy(in, out); IOUtils.closeQuietly(in); out.close(); } } } finally { zipFile.close(); }
ZipOutputStream out = null; try { ZipFile zip = new ZipFile(frameFile); ZipEntry entry = zip.getEntry("resources.arsc"); in = zip.getInputStream(entry); byte[] data = IOUtils.toByteArray(in); in = zip.getInputStream(entry); byte[] manifest = IOUtils.toByteArray(in); CRC32 manifestCrc = new CRC32(); zip.close(); LOGGER.info("Framework installed to: " + outFile); } catch (IOException ex) {
public static String getZipEntryCrc(File file, String entryName) { ZipFile zipFile = null; try { zipFile = new ZipFile(file); ZipEntry entry = zipFile.getEntry(entryName); if (entry == null) { return null; } return String.valueOf(entry.getCrc()); } catch (IOException e) { e.printStackTrace(); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; }
@Override public Set<String> load(String archivePath) throws Exception { ZipFile archive = null; try { archive = new ZipFile(archivePath); Set<String> ret = new HashSet<String>(); Enumeration<? extends ZipEntry> it = archive.entries(); while (it.hasMoreElements()) { ret.add(it.nextElement().getName()); } return ret; } finally { if (archive != null) { archive.close(); } } } });
file.deleteOnExit(); ZipFile zipFile = new ZipFile(url.getFile()); ZipEntry entry = zipFile.getEntry(this.resourceName); if (entry == null) { InputStream stream = zipFile.getInputStream(entry); FileOutputStream outputStream = new FileOutputStream(file); byte[] array = new byte[1024]; zipFile.close();
private void getCompressMethodFromApk() { ZipFile zipFile = null; try { zipFile = new ZipFile(config.mNewApkFile); ArrayList<String> sets = new ArrayList<>(); sets.addAll(modifiedSet); sets.addAll(addedSet); ZipEntry zipEntry; for (String name : sets) { zipEntry = zipFile.getEntry(name); if (zipEntry != null && zipEntry.getMethod() == ZipEntry.STORED) { storedSet.add(name); } } } catch (Throwable throwable) { } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { } } } }
/** * Add entries to <code>packagedClasses</code> corresponding to class files * contained in <code>jar</code>. * @param jar The jar who's content to list. * @param packagedClasses map[class -> jar] */ private static void updateMap(String jar, Map<String, String> packagedClasses) throws IOException { if (null == jar || jar.isEmpty()) { return; } ZipFile zip = null; try { zip = new ZipFile(jar); for (Enumeration<? extends ZipEntry> iter = zip.entries(); iter.hasMoreElements();) { ZipEntry entry = iter.nextElement(); if (entry.getName().endsWith("class")) { packagedClasses.put(entry.getName(), jar); } } } finally { if (null != zip) zip.close(); } }