Example usage for java.util.zip ZipFile close

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

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes the ZIP file.

Usage

From source file:org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil.java

/**
 * 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]
 *//*from  www  .ja  v a2 s . c  o m*/
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();
    }
}

From source file:com.limegroup.gnutella.gui.LanguageUtils.java

/**
 * Returns the languages as found from the classpath in messages.jar
 *//*from   w w  w.j  av  a 2s.  c  o  m*/
static void addLocalesFromJar(List<Locale> locales, File jar) {
    ZipFile zip = null;
    try {
        zip = new ZipFile(jar);
        Enumeration<? extends ZipEntry> entries = zip.entries();
        while (entries.hasMoreElements()) {
            String name = entries.nextElement().getName();
            if (!name.startsWith(BUNDLE_PREFIX) || !name.endsWith(BUNDLE_POSTFIX) || name.indexOf("$") != -1) {
                continue;
            }

            String iso = name.substring(BUNDLE_PREFIX.length(), name.length() - BUNDLE_POSTFIX.length());
            List<String> tokens = new ArrayList<String>(Arrays.asList(iso.split("_", 3)));
            if (tokens.size() < 1) {
                continue;
            }
            while (tokens.size() < 3) {
                tokens.add("");
            }

            Locale locale = new Locale(tokens.get(0), tokens.get(1), tokens.get(2));
            locales.add(locale);
        }
    } catch (IOException e) {
        LOG.warn("Could not determine locales", e);
    } finally {
        if (zip != null) {
            try {
                zip.close();
            } catch (IOException ioe) {
            }
        }
    }
}

From source file:dk.deck.resolver.util.ZipUtils.java

public List<String> listArchive(File archive) {
    List<String> paths = new ArrayList<String>();
    try {//from  www.  j ava2s.co m
        ZipFile zipfile = new ZipFile(archive);
        for (Enumeration e = zipfile.entries(); e.hasMoreElements();) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            paths.add(entry.getName());
        }
        zipfile.close();
    } catch (Exception e) {
        log.error("Error while extracting file " + archive, e);
    }

    return paths;
}

From source file:dk.deck.resolver.util.ZipUtils.java

public void unzipArchive(File archive, File outputDir) {
    try {/*  www  . j  a v  a2s .  c o  m*/
        ZipFile zipfile = new ZipFile(archive);
        for (Enumeration e = zipfile.entries(); e.hasMoreElements();) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            unzipEntry(zipfile, entry, outputDir);
        }
        zipfile.close();
    } catch (Exception e) {
        log.error("Error while extracting file " + archive, e);
    }
}

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

public static void extractZip(final File archive, final String zipEntryToBeExtracted, final File dstFile,
        final ProgressNotifyable prog) throws IOException {
    ZipFile zf = new ZipFile(archive);
    ZipEntry entry = zf.getEntry(zipEntryToBeExtracted);
    if (entry != null)
        extractEntry(zf, entry, dstFile, prog);
    zf.close();
}

From source file:simpleserver.minecraft.MinecraftWrapper.java

private boolean verifyMinecraftJar() {
    if (getServerJar() != SERVER_JAR) {
        return true;
    }// www . j  a va  2 s . c  o  m

    boolean valid = false;
    try {
        ZipFile jar = new ZipFile(SERVER_JAR);
        valid = jar.size() > 200;
        jar.close();
    } catch (IOException e) {
    }

    return valid;
}

From source file:com.liferay.mobile.sdk.core.tests.MobileSDKCoreTests.java

private void checkJarPaths(File jar, String[] paths) throws Exception {
    assertTrue(jar.exists());//w w w  . ja  va  2s . c  o  m

    final ZipFile jarFile = new ZipFile(jar);

    for (String path : paths) {
        ZipEntry entry = jarFile.getEntry(path);

        assertNotNull(entry);
    }

    jarFile.close();
}

From source file:org.geoserver.data.util.IOUtils.java

public static void decompress(final File inputFile, final File destDir) throws IOException {
    ZipFile zipFile = new ZipFile(inputFile);

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

    while (entries.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        InputStream stream = zipFile.getInputStream(entry);

        if (entry.isDirectory()) {
            // Assume directories are stored parents first then children.
            (new File(destDir, entry.getName())).mkdir();
            continue;
        }//  w w w. j ava 2 s  .c o m

        File newFile = new File(destDir, entry.getName());
        FileOutputStream fos = new FileOutputStream(newFile);
        try {
            byte[] buf = new byte[1024];
            int len;

            while ((len = stream.read(buf)) >= 0)
                saveCompressedStream(buf, fos, len);

        } catch (IOException e) {
            zipFile.close();
            IOException ioe = new IOException("Not valid COAMPS archive file type.");
            ioe.initCause(e);
            throw ioe;
        } finally {
            fos.flush();
            fos.close();

            stream.close();
        }
    }
    zipFile.close();
}

From source file:Main.java

public static String readChannelString(String path, String prefixString) {
    String ret = null;//from  w  w w.j  a  v  a  2 s  . c  o  m
    ZipFile zipfile = null;
    try {
        zipfile = new ZipFile(path);
        Enumeration<?> entries = zipfile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            String entryName = entry.getName();
            if (debug) {
                System.out.println(entryName);
            }
            if (entryName.contains(prefixString)) {
                ret = entryName;

                break;
            }
        }

        if (ret != null) {
            String[] split = ret.split("_");
            if (split != null && split.length >= 2) {
                String substring = ret.substring(split[0].length() + 1);
                if (debug) {
                    System.out.println(String.format("find channel string:%s", substring));
                }
                return substring;

            }
        } else {
            if (debug) {
                System.out.println("not find channel");
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (zipfile != null) {
            try {
                zipfile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    return ret;

}

From source file:org.opensha.commons.util.FileUtils.java

public static void unzipFile(File zipFile, File directory) throws FileNotFoundException, IOException {
    ZipFile zip = new ZipFile(zipFile);

    Enumeration<? extends ZipEntry> entries = zip.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (entry.isDirectory()) {
            // Assume directories are stored parents first then children.
            //            System.err.println("Extracting directory: " + entry.getName());
            // This is not robust, just for demonstration purposes.
            (new File(directory, entry.getName())).mkdir();
            continue;
        }/* ww  w  .j a  v a  2  s  .c o m*/
        //         System.err.println("Extracting file: " + entry.getName());
        copyInputStream(zip.getInputStream(entry),
                new BufferedOutputStream(new FileOutputStream(new File(directory, entry.getName()))));
    }
    zip.close();
}