Example usage for android.util.jar StrictJarFile getInputStream

List of usage examples for android.util.jar StrictJarFile getInputStream

Introduction

In this page you can find the example usage for android.util.jar StrictJarFile getInputStream.

Prototype

public InputStream getInputStream(ZipEntry ze) 

Source Link

Usage

From source file:android.content.pm.PackageParser.java

private static Certificate[][] loadCertificates(StrictJarFile jarFile, ZipEntry entry)
        throws PackageParserException {
    InputStream is = null;/*from  w ww.  ja v  a2 s .c  o m*/
    try {
        // We must read the stream for the JarEntry to retrieve
        // its certificates.
        is = jarFile.getInputStream(entry);
        readFullyIgnoringContents(is);
        return jarFile.getCertificateChains(entry);
    } catch (IOException | RuntimeException e) {
        throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION,
                "Failed reading " + entry.getName() + " in " + jarFile, e);
    } finally {
        IoUtils.closeQuietly(is);
    }
}

From source file:android.content.pm.PackageParser.java

/**
 * Gathers the {@link ManifestDigest} for {@code pkg} if it exists in the
 * APK. If it successfully scanned the package and found the
 * {@code AndroidManifest.xml}, {@code true} is returned.
 *//*from ww  w  . j  a v a2 s.  c o m*/
public void collectManifestDigest(Package pkg) throws PackageParserException {
    pkg.manifestDigest = null;

    // TODO: extend to gather digest for split APKs
    try {
        final StrictJarFile jarFile = new StrictJarFile(pkg.baseCodePath);
        try {
            final ZipEntry je = jarFile.findEntry(ANDROID_MANIFEST_FILENAME);
            if (je != null) {
                pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
            }
        } finally {
            jarFile.close();
        }
    } catch (IOException | RuntimeException e) {
        throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
                "Failed to collect manifest digest");
    }
}