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:Main.java

public static void main(String[] args) throws Exception {
    ZipFile zipFile = new ZipFile("testfile.zip", Charset.defaultCharset());

    Enumeration zipEntries = zipFile.entries();

    while (zipEntries.hasMoreElements()) {
        System.out.println(((ZipEntry) zipEntries.nextElement()).getName());
    }/*from  ww  w . j  a va 2 s.c o m*/
    zipFile.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ZipFile zf = new ZipFile("a.zip");
    Enumeration<? extends ZipEntry> files = zf.entries();

    while (files.hasMoreElements()) {
        ZipEntry ze = files.nextElement();

        System.out.println("Decompressing " + ze.getName());
        System.out.println(/*from ww w .j  a v a 2 s .  c  o  m*/
                "  Compressed Size: " + ze.getCompressedSize() + "  Expanded Size: " + ze.getSize() + "\n");

        BufferedInputStream fin = new BufferedInputStream(zf.getInputStream(ze));
        BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(ze.getName()));

        int i;
        do {
            i = fin.read();
            if (i != -1)
                fout.write(i);
        } while (i != -1);

        fout.close();
        fin.close();
    }
    zf.close();
}

From source file:com.adobe.aem.demomachine.communities.Loader.java

public static void main(String[] args) {

    String hostname = null;/*  ww w  .j ava 2  s.c om*/
    String port = null;
    String altport = null;
    String csvfile = null;
    String analytics = null;
    String adminPassword = "admin";
    boolean reset = false;
    boolean configure = false;
    boolean minimize = false;
    boolean noenablement = true;
    int maxretries = MAXRETRIES;

    // Command line options for this tool
    Options options = new Options();
    options.addOption("h", true, "Hostname");
    options.addOption("p", true, "Port");
    options.addOption("a", true, "Alternate Port");
    options.addOption("f", true, "CSV file");
    options.addOption("r", false, "Reset");
    options.addOption("u", true, "Admin Password");
    options.addOption("c", false, "Configure");
    options.addOption("m", false, "Minimize");
    options.addOption("e", false, "No Enablement");
    options.addOption("s", true, "Analytics Endpoint");
    options.addOption("t", false, "Analytics");
    options.addOption("w", false, "Retry");
    CommandLineParser parser = new BasicParser();
    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            hostname = cmd.getOptionValue("h");
        }

        if (cmd.hasOption("p")) {
            port = cmd.getOptionValue("p");
        }

        if (cmd.hasOption("a")) {
            altport = cmd.getOptionValue("a");
        }

        if (cmd.hasOption("f")) {
            csvfile = cmd.getOptionValue("f");
        }

        if (cmd.hasOption("u")) {
            adminPassword = cmd.getOptionValue("u");
        }

        if (cmd.hasOption("t")) {
            if (cmd.hasOption("s")) {
                analytics = cmd.getOptionValue("s");
            }
        }

        if (cmd.hasOption("r")) {
            reset = true;
        }

        if (cmd.hasOption("w")) {
            maxretries = Integer.parseInt(cmd.getOptionValue("w"));
        }

        if (cmd.hasOption("c")) {
            configure = true;
        }

        if (cmd.hasOption("m")) {
            minimize = true;
        }

        if (cmd.hasOption("e")) {
            noenablement = false;
        }

        if (csvfile == null || port == null || hostname == null) {
            System.out.println(
                    "Request parameters: -h hostname -p port -a alternateport -u adminPassword -f path_to_CSV_file -r (true|false, delete content before import) -c (true|false, post additional properties)");
            System.exit(-1);
        }

    } catch (ParseException ex) {

        logger.error(ex.getMessage());

    }

    logger.debug("AEM Demo Loader: Processing file " + csvfile);

    try {

        // Reading and processing the CSV file, stand alone or as part of a ZIP file
        if (csvfile != null && csvfile.toLowerCase().endsWith(".zip")) {

            ZipFile zipFile = new ZipFile(csvfile);
            ZipInputStream stream = new ZipInputStream(new FileInputStream(csvfile));
            ZipEntry zipEntry;
            while ((zipEntry = stream.getNextEntry()) != null) {
                if (!zipEntry.isDirectory() && zipEntry.getName().toLowerCase().endsWith(".csv")) {

                    InputStream is = zipFile.getInputStream(zipEntry);
                    BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                    processLoading(null, in, hostname, port, altport, adminPassword, analytics, reset,
                            configure, minimize, noenablement, csvfile, maxretries);

                }
            }

            try {
                stream.close();
                zipFile.close();
            } catch (IOException ioex) {
                //omitted.
            }

        } else if (csvfile.toLowerCase().endsWith(".csv")) {

            Reader in = new FileReader(csvfile);
            processLoading(null, in, hostname, port, altport, adminPassword, analytics, reset, configure,
                    minimize, noenablement, csvfile, maxretries);

        }

    } catch (IOException e) {

        logger.error(e.getMessage());

    }

}

From source file:Main.java

public static void closeQietly(ZipFile zipFile) {
    try {//  w w  w .ja v a 2 s  .  c o m
        zipFile.close();
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static Enumeration<?> getEntriesEnumeration(File zipFile) throws IOException {
    ZipFile zf = new ZipFile(zipFile);
    Enumeration<?> entry = zf.entries();
    zf.close();
    return entry;
}

From source file:Main.java

public static void close(ZipFile zip) {
    if (zip != null) {
        try {/*w w w  . j  a v a 2  s  . c  om*/
            zip.close();
        } catch (IOException var2) {
            var2.printStackTrace();
        }
    }
}

From source file:net.minecraftforge.common.util.Java6Utils.java

/**
 * {@link ZipFile} does not implement {@link Closeable} on Java 6.
 * This method is the same as {@link IOUtils#closeQuietly(Closeable)} but works on {@link ZipFile} on Java 6.
 *//*  ww w .ja v a  2  s. c  om*/
public static void closeZipQuietly(@Nullable ZipFile file) {
    try {
        if (file != null) {
            file.close();
        }
    } catch (IOException ioe) {
        // ignore
    }
}

From source file:Main.java

public static boolean searchJarFile(File file, String classFilePath) {

    try {/*from  www. j  av a 2 s .c o m*/
        if (!file.exists())
            return false;

        ZipFile jarFile = new ZipFile(file);
        if (jarFile.getEntry(classFilePath) != null) {
            jarFile.close();
            return true;
        } else {
            jarFile.close();
            return false;
        }
    } catch (IOException ex) {
        System.out.println(ex.toString());
        return false;
    }
}

From source file:Main.java

/**
 * Determine whether a file is a JAR File.
 *///from w w  w .j ava 2s.co  m
public static boolean isJarFile(File file) throws IOException {
    if (!isZipFile(file)) {
        return false;
    }
    ZipFile zip = new ZipFile(file);
    boolean manifest = zip.getEntry("META-INF/MANIFEST.MF") != null;
    zip.close();
    return manifest;
}

From source file:b2s.idea.mavenize.JarCombiner.java

private static void close(ZipFile zip) {
    if (zip != null) {
        try {/*from w  w w.j av a  2s  . c  om*/
            zip.close();
        } catch (IOException e) {

        }
    }
}