Search in sources :

Example 26 with ZipFile

use of java.util.zip.ZipFile in project android_frameworks_base by ParanoidAndroid.

the class RecoverySystem method getTrustedCerts.

/** @return the set of certs that can be used to sign an OTA package. */
private static HashSet<Certificate> getTrustedCerts(File keystore) throws IOException, GeneralSecurityException {
    HashSet<Certificate> trusted = new HashSet<Certificate>();
    if (keystore == null) {
        keystore = DEFAULT_KEYSTORE;
    }
    ZipFile zip = new ZipFile(keystore);
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Enumeration<? extends ZipEntry> entries = zip.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            InputStream is = zip.getInputStream(entry);
            try {
                trusted.add(cf.generateCertificate(is));
            } finally {
                is.close();
            }
        }
    } finally {
        zip.close();
    }
    return trusted;
}
Also used : ZipFile(java.util.zip.ZipFile) BerInputStream(org.apache.harmony.security.asn1.BerInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) CertificateFactory(java.security.cert.CertificateFactory) HashSet(java.util.HashSet) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 27 with ZipFile

use of java.util.zip.ZipFile in project android_frameworks_base by ParanoidAndroid.

the class PackageHelper method extractPublicFiles.

public static int extractPublicFiles(String packagePath, File publicZipFile) throws IOException {
    final FileOutputStream fstr;
    final ZipOutputStream publicZipOutStream;
    if (publicZipFile == null) {
        fstr = null;
        publicZipOutStream = null;
    } else {
        fstr = new FileOutputStream(publicZipFile);
        publicZipOutStream = new ZipOutputStream(fstr);
    }
    int size = 0;
    try {
        final ZipFile privateZip = new ZipFile(packagePath);
        try {
            // Copy manifest, resources.arsc and res directory to public zip
            for (final ZipEntry zipEntry : Collections.list(privateZip.entries())) {
                final String zipEntryName = zipEntry.getName();
                if ("AndroidManifest.xml".equals(zipEntryName) || "resources.arsc".equals(zipEntryName) || zipEntryName.startsWith("res/")) {
                    size += zipEntry.getSize();
                    if (publicZipFile != null) {
                        copyZipEntry(zipEntry, privateZip, publicZipOutStream);
                    }
                }
            }
        } finally {
            try {
                privateZip.close();
            } catch (IOException e) {
            }
        }
        if (publicZipFile != null) {
            publicZipOutStream.finish();
            publicZipOutStream.flush();
            FileUtils.sync(fstr);
            publicZipOutStream.close();
            FileUtils.setPermissions(publicZipFile.getAbsolutePath(), FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IROTH, -1, -1);
        }
    } finally {
        IoUtils.closeQuietly(publicZipOutStream);
    }
    return size;
}
Also used : ZipFile(java.util.zip.ZipFile) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Example 28 with ZipFile

use of java.util.zip.ZipFile in project OpenRefine by OpenRefine.

the class FileHistoryEntryManager method loadChange.

protected void loadChange(HistoryEntry historyEntry, File file) throws Exception {
    ZipFile zipFile = new ZipFile(file);
    try {
        Pool pool = new Pool();
        ZipEntry poolEntry = zipFile.getEntry("pool.txt");
        if (poolEntry != null) {
            pool.load(new InputStreamReader(zipFile.getInputStream(poolEntry)));
        }
        // else, it's a legacy project file
        historyEntry.setChange(History.readOneChange(zipFile.getInputStream(zipFile.getEntry("change.txt")), pool));
    } finally {
        zipFile.close();
    }
}
Also used : ZipFile(java.util.zip.ZipFile) InputStreamReader(java.io.InputStreamReader) ZipEntry(java.util.zip.ZipEntry) Pool(com.google.refine.util.Pool)

Example 29 with ZipFile

use of java.util.zip.ZipFile in project android_frameworks_base by ParanoidAndroid.

the class ClassPathPackageInfoSource method getJarEntries.

/**
     * Gets the class and package entries from a Jar.
     */
private Set<String> getJarEntries(File jarFile) throws IOException {
    Set<String> entryNames = jarFiles.get(jarFile);
    if (entryNames == null) {
        entryNames = Sets.newHashSet();
        ZipFile zipFile = new ZipFile(jarFile);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            String entryName = entries.nextElement().getName();
            if (entryName.endsWith(CLASS_EXTENSION)) {
                // add the entry name of the class
                entryNames.add(entryName);
                // add the entry name of the classes package, i.e. the entry name of
                // the directory that the class is in. Used to quickly skip jar files
                // if they do not contain a certain package.
                //
                // Also add parent packages so that a JAR that contains
                // pkg1/pkg2/Foo.class will be marked as containing pkg1/ in addition
                // to pkg1/pkg2/ and pkg1/pkg2/Foo.class.  We're still interested in
                // JAR files that contains subpackages of a given package, even if
                // an intermediate package contains no direct classes.
                //
                // Classes in the default package will cause a single package named
                // "" to be added instead.
                int lastIndex = entryName.lastIndexOf('/');
                do {
                    String packageName = entryName.substring(0, lastIndex + 1);
                    entryNames.add(packageName);
                    lastIndex = entryName.lastIndexOf('/', lastIndex - 1);
                } while (lastIndex > 0);
            }
        }
        jarFiles.put(jarFile, entryNames);
    }
    return entryNames;
}
Also used : ZipFile(java.util.zip.ZipFile)

Example 30 with ZipFile

use of java.util.zip.ZipFile in project android_frameworks_base by ParanoidAndroid.

the class AsmAnalyzer method parseZip.

/**
     * Parses a JAR file and returns a list of all classes founds using a map
     * class name => ASM ClassReader. Class names are in the form "android.view.View".
     */
Map<String, ClassReader> parseZip(List<String> jarPathList) throws IOException {
    TreeMap<String, ClassReader> classes = new TreeMap<String, ClassReader>();
    for (String jarPath : jarPathList) {
        ZipFile zip = new ZipFile(jarPath);
        Enumeration<? extends ZipEntry> entries = zip.entries();
        ZipEntry entry;
        while (entries.hasMoreElements()) {
            entry = entries.nextElement();
            if (entry.getName().endsWith(".class")) {
                ClassReader cr = new ClassReader(zip.getInputStream(entry));
                String className = classReaderToClassName(cr);
                classes.put(className, cr);
            }
        }
    }
    return classes;
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ClassReader(org.objectweb.asm.ClassReader) TreeMap(java.util.TreeMap)

Aggregations

ZipFile (java.util.zip.ZipFile)580 ZipEntry (java.util.zip.ZipEntry)414 File (java.io.File)261 IOException (java.io.IOException)189 InputStream (java.io.InputStream)127 FileOutputStream (java.io.FileOutputStream)98 ZipOutputStream (java.util.zip.ZipOutputStream)89 Test (org.junit.Test)88 FileInputStream (java.io.FileInputStream)57 ArrayList (java.util.ArrayList)44 Enumeration (java.util.Enumeration)42 BufferedInputStream (java.io.BufferedInputStream)38 BufferedOutputStream (java.io.BufferedOutputStream)35 ZipException (java.util.zip.ZipException)32 ClassReader (org.objectweb.asm.ClassReader)29 OutputStream (java.io.OutputStream)27 JarFile (java.util.jar.JarFile)26 ZipInputStream (java.util.zip.ZipInputStream)26 FileNotFoundException (java.io.FileNotFoundException)23 Path (java.nio.file.Path)23