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

/**
 * To check if the apk file is available to install.
 * /*  w ww.j  av a2s  .  c  om*/
 * @param apkFilePath the apk file path
 * @return            true if available, otherwise return false
 */
public static boolean isApkAvailable(String apkFilePath) {
    File apkFile = new File(apkFilePath);
    if (!apkFile.exists()) {
        return false;
    }

    try {
        ZipFile zipFile = new ZipFile(apkFile);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry zipEntry = entries.nextElement();
            if (APK_MANIFEST.equals(zipEntry.getName())) {
                zipFile.close();
                return true;
            }
        }

        zipFile.close();
    } catch (Exception e) {
        return false;
    }

    return false;
}

From source file:Utils.java

/**
 * Validate that an archive contains a named entry
 * /*from ww w  .j  a  v  a 2 s  .  co  m*/
 * @param theFile
 * @param name
 * @return true if the entry exists
 * @throws IOException
 */
public static boolean archiveContainsEntry(File theFile, String name) throws IOException {
    boolean result = false;
    ZipFile zipFile;
    zipFile = new ZipFile(theFile);
    for (Enumeration entries = zipFile.entries(); entries.hasMoreElements();) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        if (entry.getName().equals(name)) {
            result = true;
            break;
        }
    }
    zipFile.close();
    return result;
}

From source file:org.flowerplatform.core.CoreUtils.java

@SuppressWarnings("rawtypes")
public static void unzipArchive(File archive, File outputDir) throws IOException {
    ZipFile zipfile = new ZipFile(archive);
    for (Enumeration e = zipfile.entries(); e.hasMoreElements();) {
        ZipEntry entry = (ZipEntry) e.nextElement();
        unzipEntry(zipfile, entry, outputDir);
    }//from w  w  w  . j  a  v  a  2 s  .c  o  m
    zipfile.close();
}

From source file:com.google.gdt.eclipse.designer.webkit.WebKitSupportWin32.java

public static void deployIfNeededAndLoad() {
    if (!m_initialized) {
        try {//from   www .ja va2  s . c  o m
            // extract
            Bundle bundle = Platform.getBundle("com.google.gdt.eclipse.designer.hosted.2_0.webkit");
            URL resource = FileLocator.resolve(bundle.getResource("WebKit.zip"));
            ZipFile zipFile = new ZipFile(resource.getPath());
            try {
                if (deployNeeded(zipFile)) {
                    extract(zipFile);
                }
            } finally {
                zipFile.close();
            }
            load();
            m_available = true;
        } catch (Throwable e) {
            // ignore
        }
        m_initialized = true;
    }
}

From source file:rv.comm.rcssserver.TarBz2ZipUtil.java

public static Reader getZipStream(File file) {
    try {/*from  w  w w . j  ava  2s. co m*/
        ZipFile zipFile = new ZipFile(file);
        if (zipFile.size() != 1) {
            System.out.println("Only support single entry zip files");
            zipFile.close();
            return null;
        } else {
            ZipEntry zipEntry = zipFile.entries().nextElement();
            return new InputStreamReader(zipFile.getInputStream(zipEntry));
        }

    } catch (IOException e) {
        // not a zip file
        System.out.println("File has zip ending, but seems to be not zip");
        return null;
    }
}

From source file:org.openoffice.maven.packager.OxtMojoTest.java

private static String getManifestContent() throws ZipException, IOException {
    ZipFile zip = new ZipFile(OXT_FILE);
    try {//  www  . j a  va  2s. co  m
        ZipEntry entry = zip.getEntry("META-INF/manifest.xml");
        InputStream istream = zip.getInputStream(entry);
        return IOUtils.toString(istream);
    } finally {
        zip.close();
    }
}

From source file:org.nuxeo.ecm.platform.filemanager.service.extension.ExportedZipImporter.java

public static ZipFile getArchiveFileIfValid(File file) throws IOException {
    ZipFile zip;

    try {/*from   w w w  .j a  va  2s  .  c  o m*/
        zip = new ZipFile(file);
    } catch (ZipException e) {
        log.debug("file is not a zipfile ! ", e);
        return null;
    } catch (IOException e) {
        log.debug("can not open zipfile ! ", e);
        return null;
    }

    ZipEntry marker = zip.getEntry(".nuxeo-archive");

    if (marker == null) {
        zip.close();
        return null;
    } else {
        return zip;
    }
}

From source file:Main.java

public static byte[] readZipEntry(File zfile, ZipEntry entry) throws ZipException, IOException {
    Log.d("file3: ", zfile.toString());
    Log.d("zipEntry3: ", entry.toString());
    ZipFile zipFile = new ZipFile(zfile);
    if (entry != null && !entry.isDirectory()) {
        byte[] barr = new byte[(int) entry.getSize()];
        int read = 0;
        int len = 0;
        InputStream is = zipFile.getInputStream(entry);
        BufferedInputStream bis = new BufferedInputStream(is);
        int length = barr.length;
        while ((len = bis.read(barr, read, length - read)) != -1) {
            read += len;//from  w w w . j av  a  2 s . c o m
        }
        bis.close();
        is.close();
        zipFile.close();
        return barr;
    } else {
        zipFile.close();
        return new byte[0];
    }
}

From source file:nl.knaw.dans.common.lang.file.UnzipUtil.java

private static List<File> extract(final File zipFile, final String destPath, final UnzipListener unzipListener)
        throws FileNotFoundException, ZipException, IOException {
    final ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));

    // get total uncompressed size of zip file
    final ZipFile zf = new ZipFile(zipFile);
    final Enumeration<? extends ZipEntry> e = zf.entries();
    long totSize = 0;
    int totFiles = 0;
    while (e.hasMoreElements()) {
        final ZipEntry ze = (ZipEntry) e.nextElement();
        totSize += ze.getSize();//from  ww  w  .j  a v a  2 s.  c o  m
        totFiles++;
    }
    zf.close();

    return extract(zis, destPath, totFiles, unzipListener, totSize);
}

From source file:com.meltmedia.cadmium.deployer.JBossUtil.java

public static boolean isCadmiumWar(File file, Logger log) {
    if (file.isDirectory()) {
        return new File(file, "WEB-INF/cadmium.properties").exists();
    } else if (file.exists()) {
        ZipFile zip = null;
        try {//from   w ww  .j  a va  2  s .com
            zip = new ZipFile(file);
            ZipEntry cadmiumProps = zip.getEntry("WEB-INF/cadmium.properties");
            return cadmiumProps != null;
        } catch (Exception e) {
            log.warn("Failed to read war file " + file, e);
        } finally {
            if (zip != null) {
                try {
                    zip.close();
                } catch (IOException e) {
                    //Not much we can do about this.
                }
            }
        }
    }
    return false;
}