Example usage for java.util.zip ZipFile entries

List of usage examples for java.util.zip ZipFile entries

Introduction

In this page you can find the example usage for java.util.zip ZipFile entries.

Prototype

public Enumeration<? extends ZipEntry> entries() 

Source Link

Document

Returns an enumeration of the ZIP file entries.

Usage

From source file:org.ado.minesync.commons.ZipArchiverTest.java

private List<? extends ZipEntry> getZipEntryList(ZipFile zipFile) {
    List<? extends ZipEntry> list = Collections.list(zipFile.entries());
    System.out.println(list);/*w  w w .  ja  va 2 s .co  m*/
    return list;
}

From source file:com.mgmtp.jfunk.data.source.ArchiveDataSource.java

private Map<String, DataSet> getDataSets() {
    if (dataSets == null) {
        String archiveFileName = configuration.get("dataSource." + getName() + ".archiveFileName");
        if (archiveFileName == null) {
            throw new IllegalStateException("No archive files configured.");
        }// w  ww.  ja  va2 s . com
        log.info("Using " + archiveFileName);

        dataSets = newHashMap();
        try {
            ZipFile zip = new ZipFile(archiveFileName);
            for (Enumeration<? extends ZipEntry> zipEntryEnum = zip.entries(); zipEntryEnum
                    .hasMoreElements();) {
                ZipEntry zipEntry = zipEntryEnum.nextElement();
                String name = zipEntry.getName();
                Matcher matcher = KEY_PATTERN.matcher(name);
                if (matcher.find()) {
                    InputStream is = null;
                    try {
                        is = zip.getInputStream(zipEntry);
                        String key = matcher.group(1);
                        ExtendedProperties props = new ExtendedProperties();
                        props.load(is);
                        log.debug("Adding data for key=" + key);
                        dataSets.put(key, new DefaultDataSet(props));
                    } finally {
                        closeQuietly(is);
                    }
                }
            }
        } catch (IOException ex) {
            throw new JFunkException("Error getting data sets.", ex);
        }
    }
    return dataSets;
}

From source file:asciidoc.maven.plugin.AbstractAsciiDocMojo.java

/**
 * No-arg constructor./*  w w w . ja  v a 2s .  co m*/
 */
public AbstractAsciiDocMojo() {
    try {
        File jarFile = new File(AbstractAsciiDocMojo.class.getProtectionDomain().getCodeSource().getLocation()
                .toURI().getPath());
        if (getLog().isDebugEnabled())
            getLog().debug("sourceJarFile: " + jarFile.getAbsolutePath());
        if (asciiDocHome == null) {
            ZipEntry zipEntry = null;
            String zipEntryName = null;
            ZipFile jarZipFile = new ZipFile(jarFile);
            Enumeration<? extends ZipEntry> e = jarZipFile.entries();
            while (e.hasMoreElements()) {
                zipEntry = (ZipEntry) e.nextElement();
                zipEntryName = zipEntry.getName();
                if (zipEntryName.startsWith("asciidoc") && zipEntryName.endsWith(".zip")) {
                    if (getLog().isInfoEnabled())
                        getLog().info("Found AsciiDoc in " + zipEntryName);
                    asciiDocHome = new File(jarFile.getParent(), FilenameUtils.removeExtension(zipEntryName));
                    break;
                }
            }
            if (asciiDocHome != null && !asciiDocHome.exists()) {
                unzipEntry(jarZipFile, zipEntry, jarFile.getParentFile());
                File asciiDocArchive = new File(jarFile.getParent(), zipEntryName);
                unzipArchive(asciiDocArchive, jarFile.getParentFile());
                asciiDocArchive.deleteOnExit();
            }
            if (getLog().isInfoEnabled())
                getLog().info("asciiDocHome: " + asciiDocHome);
        }
    } catch (URISyntaxException use) {
        getLog().error(use.getMessage(), use);
        // don't throw use;
    } catch (ZipException ze) {
        getLog().error(ze.getMessage(), ze);
        // don't throw ze;
    } catch (IOException ioe) {
        getLog().error(ioe.getMessage(), ioe);
        // don't throw ioe;
    }
}

From source file:ccm.pay2spawn.types.MusicType.java

@Override
public void printHelpList(File configFolder) {
    musicFolder = new File(configFolder, "music");
    if (musicFolder.mkdirs()) {
        new Thread(new Runnable() {
            @Override/*from  w  ww.j  a v  a  2s.c o  m*/
            public void run() {
                try {
                    File zip = new File(musicFolder, "music.zip");
                    FileUtils.copyURLToFile(new URL(Constants.MUSICURL), zip);
                    ZipFile zipFile = new ZipFile(zip);
                    Enumeration<? extends ZipEntry> entries = zipFile.entries();
                    while (entries.hasMoreElements()) {
                        ZipEntry entry = entries.nextElement();
                        File entryDestination = new File(musicFolder, entry.getName());
                        entryDestination.getParentFile().mkdirs();
                        InputStream in = zipFile.getInputStream(entry);
                        OutputStream out = new FileOutputStream(entryDestination);
                        IOUtils.copy(in, out);
                        IOUtils.closeQuietly(in);
                        IOUtils.closeQuietly(out);
                    }
                    zipFile.close();
                    zip.delete();
                } catch (IOException e) {
                    Pay2Spawn.getLogger()
                            .warn("Error downloading music file. Get from github and unpack yourself please.");
                    e.printStackTrace();
                }
            }
        }, "Pay2Spawn music download and unzip").start();
    }
}

From source file:com.heliosdecompiler.helios.transformers.disassemblers.KrakatauDisassembler.java

public boolean disassembleClassNode(ClassNode cn, byte[] b, StringBuilder output) {
    if (Helios.ensurePython2Set()) {
        File inputJar = null;//from  w  ww . ja v  a  2s.  c o m
        File outputZip = null;
        String processLog = null;

        try {
            inputJar = Files.createTempFile("kdisin", ".jar").toFile();
            outputZip = Files.createTempFile("kdisout", ".zip").toFile();

            Map<String, byte[]> data = Helios.getAllLoadedData();
            data.put(cn.name + ".class", b);

            Utils.saveClasses(inputJar, data);

            Process process = Helios.launchProcess(new ProcessBuilder(
                    com.heliosdecompiler.helios.Settings.PYTHON2_LOCATION.get().asString(), "-O",
                    "disassemble.py", "-path", inputJar.getAbsolutePath(), "-out", outputZip.getAbsolutePath(),
                    cn.name + ".class", Settings.ROUNDTRIP.isEnabled() ? "-roundtrip" : "")
                            .directory(Constants.KRAKATAU_DIR));

            processLog = Utils.readProcess(process);

            ZipFile zipFile = new ZipFile(outputZip);
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            byte[] disassembled = null;
            while (entries.hasMoreElements()) {
                ZipEntry next = entries.nextElement();
                if (next.getName().equals(cn.name + ".j")) {
                    disassembled = IOUtils.toByteArray(zipFile.getInputStream(next));
                }
            }
            zipFile.close();
            output.append(new String(disassembled, "UTF-8"));
            return true;
        } catch (Exception e) {
            output.append(parseException(e)).append(processLog);
            return false;
        } finally {
            FileUtils.deleteQuietly(inputJar);
            FileUtils.deleteQuietly(outputZip);
        }
    } else {
        output.append("You need to set the location of Python 2.x");
    }
    return false;
}

From source file:com.samczsun.helios.transformers.disassemblers.KrakatauDisassembler.java

public boolean disassembleClassNode(ClassNode cn, byte[] b, StringBuilder output) {
    if (Helios.ensurePython2Set()) {
        File inputJar = null;//from  w w w . j  a  v a  2s.  c o m
        File outputZip = null;
        String processLog = null;

        try {
            inputJar = Files.createTempFile("kdisin", ".jar").toFile();
            outputZip = Files.createTempFile("kdisout", ".zip").toFile();

            Map<String, byte[]> data = Helios.getAllLoadedData();
            data.put(cn.name + ".class", b);

            Utils.saveClasses(inputJar, data);

            Process process = Helios.launchProcess(new ProcessBuilder(
                    com.samczsun.helios.Settings.PYTHON2_LOCATION.get().asString(), "-O", "disassemble.py",
                    "-path", inputJar.getAbsolutePath(), "-out", outputZip.getAbsolutePath(),
                    cn.name + ".class", Settings.ROUNDTRIP.isEnabled() ? "-roundtrip" : "")
                            .directory(Constants.KRAKATAU_DIR));

            processLog = Utils.readProcess(process);

            ZipFile zipFile = new ZipFile(outputZip);
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            byte[] disassembled = null;
            while (entries.hasMoreElements()) {
                ZipEntry next = entries.nextElement();
                if (next.getName().equals(cn.name + ".j")) {
                    disassembled = IOUtils.toByteArray(zipFile.getInputStream(next));
                }
            }
            zipFile.close();
            output.append(new String(disassembled, "UTF-8"));
            return true;
        } catch (Exception e) {
            output.append(parseException(e)).append(processLog);
            return false;
        } finally {
            FileUtils.deleteQuietly(inputJar);
            FileUtils.deleteQuietly(outputZip);
        }
    } else {
        output.append("You need to set the location of Python 2.x");
    }
    return false;
}

From source file:com.gettingagile.tisugly.analyzer.ASMAnalyzer.java

private void loadClassesFromClasspathArchiveFile(File classpathElement) throws IOException {
    ZipFile f = new ZipFile(classpathElement.getAbsolutePath());
    Enumeration<? extends ZipEntry> en = f.entries();
    while (en.hasMoreElements()) {
        ZipEntry e = en.nextElement();
        String name = e.getName();
        if (name.endsWith(".class")) {
            new ClassReader(f.getInputStream(e)).accept(dependencyVisitor, 0);
        }/*w  w w. j  av a2  s  .com*/
    }
}

From source file:org.dbgl.util.FileUtils.java

public static long extractZipSizeInBytes(final File archive, final File dirToBeExtracted) throws IOException {
    long bytes = 0;
    ZipFile zf = new ZipFile(archive);
    for (Enumeration<? extends ZipEntry> entries = zf.entries(); entries.hasMoreElements();) {
        ZipEntry entry = entries.nextElement();
        if (areRelated(dirToBeExtracted, new File(entry.getName())))
            bytes += entry.getSize();//w  ww  .j a  v  a 2  s .  c  o m
    }
    zf.close();
    return bytes;
}

From source file:org.dbgl.util.FileUtils.java

public static void extractZip(final File archive, final File dirToBeExtracted, final File dstDir,
        final ProgressNotifyable prog) throws IOException {
    ZipFile zf = new ZipFile(archive);
    for (Enumeration<? extends ZipEntry> entries = zf.entries(); entries.hasMoreElements();) {
        ZipEntry entry = entries.nextElement();
        if (areRelated(dirToBeExtracted, new File(entry.getName()))) {
            File dstFile = new File(dstDir, strip(new File(entry.getName()), dirToBeExtracted).getPath());
            extractEntry(zf, entry, dstFile, prog);
        }//from w w  w .  j a va2  s . c  o  m
    }
    zf.close();
}

From source file:org.geoserver.wps.gs.download.DownloadAnimationProcessTest.java

BufferedImage grabImageFromZip(File file, String entryName) throws IOException {
    ZipFile zipFile = new ZipFile(file);

    Enumeration<? extends ZipEntry> entries = zipFile.entries();

    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (entry.getName().equalsIgnoreCase(entryName)) {
            try (InputStream stream = zipFile.getInputStream(entry)) {
                return ImageIO.read(stream);
            }/*from  w  w  w.  j  av a 2 s .c o  m*/
        }
    }

    return null;
}