Example usage for java.util.zip ZipInputStream close

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

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this input stream and releases any system resources associated with the stream.

Usage

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

public static void main(String[] args) {

    String hostname = null;//from  w w w  .ja  v  a2s.com
    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:com.wisemapping.util.ZipUtils.java

public static byte[] zipToBytes(byte[] zip) throws IOException {

    byte[] result = null;
    if (zip != null) {
        final ByteArrayInputStream in = new ByteArrayInputStream(zip);
        final ZipInputStream zipIn = new ZipInputStream(in);
        zipIn.getNextEntry();/*from  w  ww . j  a v  a2s  .  c om*/
        result = IOUtils.toByteArray(zipIn);

        zipIn.closeEntry();
        zipIn.close();
    }

    return result;
}

From source file:com.frostwire.util.ZipUtils.java

public static boolean unzip(File zipFile, File outputDir, ZipListener listener) {
    boolean result = false;

    try {//from w  w w.jav a2  s.c om

        FileUtils.deleteDirectory(outputDir);

        ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile));
        try {
            unzipEntries(outputDir, zis, getItemCount(zipFile), System.currentTimeMillis(), listener);
        } finally {
            zis.close();
        }

        result = true;

    } catch (IOException e) {
        LOG.error("Unable to uncompress " + zipFile + " to " + outputDir, e);
        result = false;
    }

    return result;
}

From source file:ZipHandler.java

/**
 * unzipps a zip file placed at <zipURL> to path <xmlURL>
 * @param zipURL//from   ww w .  j  a v  a 2  s.co  m
 * @param xmlURL
 */
public static void unStructZip(String zipURL, String xmlURL) throws IOException {
    FileInputStream fis = new FileInputStream(new File(zipURL));
    ZipInputStream zis = new ZipInputStream(fis);
    FileOutputStream fos = new FileOutputStream(xmlURL);
    ZipEntry ze = zis.getNextEntry();
    writeInOutputStream(zis, fos);
    fos.flush();
    fis.close();
    fos.close();
    zis.close();
}

From source file:org.exist.util.Compressor.java

public static void uncompress(byte[] whatToUncompress, OutputStream os) throws IOException {
    final ByteArrayInputStream bais = new ByteArrayInputStream(whatToUncompress);
    final ZipInputStream gzis = new ZipInputStream(bais);
    final ZipEntry zipentry = gzis.getNextEntry();
    Integer.parseInt(zipentry.getName());
    final byte[] buf = new byte[512];
    int bread;/*from   w  w w . java 2s .c  o  m*/
    while ((bread = gzis.read(buf)) != -1)
        os.write(buf, 0, bread);
    gzis.closeEntry();
    gzis.close();
}

From source file:com.github.stagirs.lingvo.build.Xml2Plain.java

private static List<String> extract(File file) throws IOException {
    ZipInputStream zis = new ZipInputStream(new FileInputStream(file));
    try {//from w w  w  . j a  v a  2  s .com
        ZipEntry ze = zis.getNextEntry();
        if (ze == null) {
            throw new RuntimeException("can't unzip file");
        }
        return IOUtils.readLines(zis, Charset.forName("utf-8"));
    } finally {
        zis.close();
    }
}

From source file:com.mobicage.rogerthat.mfr.dal.Streamable.java

protected static Object fromBase64(String base64String) {
    try {//from   w w w  . ja  v  a2  s  .  com
        ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decodeBase64(base64String));

        try {
            ZipInputStream zip = new ZipInputStream(bis);
            try {
                zip.getNextEntry();
                ObjectInput in = new ObjectInputStream(zip);
                try {
                    return in.readObject();
                } finally {
                    in.close();
                }
            } finally {
                zip.close();
            }
        } finally {
            bis.close();
        }
    } catch (ClassNotFoundException e) {
        log.log((Level.SEVERE), "ClassNotFoundException while deserializing member", e);
        return null;
    } catch (IOException e) {
        log.log((Level.SEVERE), "IOException while deserializing member", e);
        return null;
    }
}

From source file:ch.rgw.compress.CompEx.java

public static byte[] expand(InputStream in) {
    ByteArrayOutputStream baos;/*from ww w. j a v  a  2 s. c om*/
    byte[] siz = new byte[4];
    try {
        in.read(siz);
        long size = BinConverter.byteArrayToInt(siz, 0);
        long typ = size & ~0x1fffffff;
        size &= 0x1fffffff;
        byte[] ret = new byte[(int) size];

        switch ((int) typ) {
        case BZIP2:
            CBZip2InputStream bzi = new CBZip2InputStream(in);
            int off = 0;
            int l = 0;
            while ((l = bzi.read(ret, off, ret.length - off)) > 0) {
                off += l;
            }

            bzi.close();
            in.close();
            return ret;
        case GLZ:
            GLZ glz = new GLZ();
            baos = new ByteArrayOutputStream();
            glz.expand(in, baos);
            return baos.toByteArray();
        case HUFF:
            HuffmanInputStream hin = new HuffmanInputStream(in);
            off = 0;
            l = 0;
            while ((l = hin.read(ret, off, ret.length - off)) > 0) {
                off += l;
            }
            hin.close();
            return ret;
        case ZIP:
            ZipInputStream zi = new ZipInputStream(in);
            zi.getNextEntry();
            off = 0;
            l = 0;
            while ((l = zi.read(ret, off, ret.length - off)) > 0) {
                off += l;
            }

            zi.close();
            return ret;
        default:
            throw new Exception("Invalid compress format");
        }
    } catch (Exception ex) {
        ExHandler.handle(ex);
        return null;
    }

}

From source file:Main.java

public static byte[] unZip(byte[] bContent) {
    byte[] b = null;
    try {//from   w  ww .  ja  v a  2s  . c  om
        ByteArrayInputStream bis = new ByteArrayInputStream(bContent);
        ZipInputStream zip = new ZipInputStream(bis);
        while (zip.getNextEntry() != null) {
            byte[] buf = new byte[1024];
            int num = -1;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            while ((num = zip.read(buf, 0, buf.length)) != -1) {
                baos.write(buf, 0, num);
            }
            b = baos.toByteArray();
            baos.flush();
            baos.close();
        }
        zip.close();
        bis.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return b;
}

From source file:Main.java

public static byte[] unZip(byte[] data) {
    byte[] b = null;
    try {//from   www. j a  va 2  s.  c om
        ByteArrayInputStream bis = new ByteArrayInputStream(data);
        ZipInputStream zip = new ZipInputStream(bis);
        while (zip.getNextEntry() != null) {
            byte[] buf = new byte[1024];
            int num = -1;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            while ((num = zip.read(buf, 0, buf.length)) != -1) {
                baos.write(buf, 0, num);
            }
            b = baos.toByteArray();
            baos.flush();
            baos.close();
        }
        zip.close();
        bis.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return b;
}