Search in sources :

Example 91 with ZipEntry

use of java.util.zip.ZipEntry in project OpenMEAP by OpenMEAP.

the class ZipUtils method getUncompressedSize.

/**
	 * Determines the uncompressed size of a zip file, without deflating it.
	 * 
	 * @param zipFile
	 * @return The size in bytes.
	 */
public static Long getUncompressedSize(ZipFile zipFile) {
    Enumeration e = zipFile.entries();
    long uncompressedSize = 0L;
    while (e.hasMoreElements()) {
        ZipEntry zipEntry = (ZipEntry) e.nextElement();
        uncompressedSize = uncompressedSize + zipEntry.getSize();
    }
    return Long.valueOf(uncompressedSize);
}
Also used : Enumeration(java.util.Enumeration) ZipEntry(java.util.zip.ZipEntry)

Example 92 with ZipEntry

use of java.util.zip.ZipEntry in project screenbird by adamhub.

the class IOUtils method isZip.

/** Return true if this file is a zip file. */
public static boolean isZip(File file) throws IOException {
    if (file.exists() == false)
        return false;
    InputStream in = null;
    try {
        in = new FileInputStream(file);
        ZipInputStream zipIn = new ZipInputStream(in);
        ZipEntry e = zipIn.getNextEntry();
        if (e == null)
            return false;
        int ctr = 0;
        while (e != null && ctr < 4) {
            e = zipIn.getNextEntry();
            ctr++;
        }
        return true;
    } catch (Throwable t) {
        return false;
    } finally {
        try {
            in.close();
        } catch (Throwable t) {
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) FileInputStream(java.io.FileInputStream)

Example 93 with ZipEntry

use of java.util.zip.ZipEntry in project screenbird by adamhub.

the class IOUtils method getZipEntry.

/** Returns an InputStream that will read a specific entry
	 * from a zip file.
	 * @param file the zip file.
	 * @param entryName the name of the entry.
	 * @return an InputStream that reads that entry.
	 * @throws IOException
	 */
public static InputStream getZipEntry(File file, String entryName) throws IOException {
    FileInputStream in = new FileInputStream(file);
    ZipInputStream zipIn = new ZipInputStream(in);
    ZipEntry e = zipIn.getNextEntry();
    while (e != null) {
        if (e.getName().equals(entryName))
            return zipIn;
        e = zipIn.getNextEntry();
    }
    return null;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) FileInputStream(java.io.FileInputStream)

Example 94 with ZipEntry

use of java.util.zip.ZipEntry in project atlas by alibaba.

the class BundleArchiveRevision method installSoLib.

/**
     * 安装so库
     * @throws IOException
     */
public void installSoLib(File bundle) throws IOException {
    ZipFile zip = null;
    try {
        zip = new ZipFile(bundle);
        String extractTag = "lib/armeabi";
        if (Build.CPU_ABI.contains("x86")) {
            if (zip.getEntry("lib/x86/") != null) {
                extractTag = "lib/x86";
            }
        }
        for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
            ZipEntry zipEntry = (ZipEntry) entries.nextElement();
            String entryName = zipEntry.getName();
            if (entryName.equalsIgnoreCase("../")) {
                continue;
            }
            if (entryName.indexOf(extractTag) != -1) {
                extractEntry(zip, zipEntry);
            }
        }
    } catch (final Exception e) {
        e.printStackTrace();
    } finally {
        if (null != zip) {
            zip.close();
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) MalformedURLException(java.net.MalformedURLException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 95 with ZipEntry

use of java.util.zip.ZipEntry in project atlas by alibaba.

the class DexReleaser method releaseDexes.

public static boolean releaseDexes(File bundleFile, File reversionDir) throws IOException {
    ZipFile zipFile = new ZipFile(bundleFile);
    boolean hasDexFile = hasDexFile(zipFile);
    if (!hasDexFile) {
        return true;
    }
    if (!isArt()) {
        Enumeration entryEnumeration = zipFile.entries();
        while (entryEnumeration.hasMoreElements()) {
            ZipEntry zipEntry = (ZipEntry) entryEnumeration.nextElement();
            if (zipEntry.getName().endsWith(DEX_SUFFIX)) {
                File dexFile = new File(reversionDir, zipEntry.getName());
                FileOutputStream fileOutputStream = new FileOutputStream(dexFile);
                copy(zipFile.getInputStream(zipEntry), fileOutputStream);
                fileOutputStream.close();
            }
        }
        return true;
    } else {
        File mergedFile = preProcessPatch(zipFile, bundleFile);
        if (mergedFile != null && mergedFile.exists()) {
            bundleFile.delete();
            boolean success = mergedFile.renameTo(bundleFile);
            if (!success || !isNewBundleFileValid(bundleFile)) {
                return false;
            }
        } else {
            return false;
        }
        try {
            zipFile.close();
        } catch (Throwable e) {
        }
    }
    return true;
}
Also used : Enumeration(java.util.Enumeration) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ZipFile(java.util.zip.ZipFile)

Aggregations

ZipEntry (java.util.zip.ZipEntry)1367 ZipFile (java.util.zip.ZipFile)479 File (java.io.File)469 IOException (java.io.IOException)361 ZipOutputStream (java.util.zip.ZipOutputStream)321 ZipInputStream (java.util.zip.ZipInputStream)300 InputStream (java.io.InputStream)282 FileOutputStream (java.io.FileOutputStream)278 FileInputStream (java.io.FileInputStream)270 Test (org.junit.Test)124 BufferedInputStream (java.io.BufferedInputStream)122 JarFile (java.util.jar.JarFile)122 BufferedOutputStream (java.io.BufferedOutputStream)99 ByteArrayOutputStream (java.io.ByteArrayOutputStream)97 ArrayList (java.util.ArrayList)84 ByteArrayInputStream (java.io.ByteArrayInputStream)78 OutputStream (java.io.OutputStream)67 JarOutputStream (java.util.jar.JarOutputStream)59 Path (java.nio.file.Path)56 Enumeration (java.util.Enumeration)56