FileDocCategorySizeDatePackage
JarEntry.javaAPI DocAndroid 1.5 API7080Wed May 06 22:41:02 BST 2009java.util.jar

JarEntry

public class JarEntry extends ZipEntry
Represents a single file in a JAR archive together with the manifest attributes and digital signatures associated with it.
since
Android 1.0

Fields Summary
private Attributes
attributes
JarFile
parentJar
CodeSigner[]
signers
private CertificateFactory
factory
private boolean
isFactoryChecked
Constructors Summary
public JarEntry(String name)
Creates a new {@code JarEntry} named name.

param
name The name of the new {@code JarEntry}.
since
Android 1.0

     

                                        
       
        super(name);
    
public JarEntry(ZipEntry entry)
Creates a new {@code JarEntry} using the values obtained from entry.

param
entry The ZipEntry to obtain values from.
since
Android 1.0

        super(entry);
    
public JarEntry(JarEntry je)
Create a new {@code JarEntry} using the values obtained from the argument.

param
je The {@code JarEntry} to obtain values from.
since
Android 1.0

        super(je);
        parentJar = je.parentJar;
        attributes = je.attributes;        
        signers = je.signers;
    
Methods Summary
private voidaddCodeSigner(java.util.ArrayList asigners, java.util.List list)

        CertPath certPath = null;
        if (!isFactoryChecked) {
            try {
                factory = CertificateFactory.getInstance("X.509"); //$NON-NLS-1$
            } catch (CertificateException ex) {
                // do nothing
            } finally {
                isFactoryChecked = true;
            }
        }
        if (null == factory) {
            return;
        }
        try {
            certPath = factory.generateCertPath(list);
        } catch (CertificateException ex) {
            // do nothing
        }
        if (null != certPath) {
            asigners.add(new CodeSigner(certPath, null));
        }
    
public java.util.jar.AttributesgetAttributes()
Returns the {@code Attributes} object associated with this entry or {@code null} if none exists.

return
the {@code Attributes} for this entry.
exception
IOException If an error occurs obtaining the {@code Attributes}.
see
Attributes
since
Android 1.0

        if (attributes != null || parentJar == null) {
            return attributes;
        }
        Manifest manifest = parentJar.getManifest();
        if (manifest == null) {
            return null;
        }
        return attributes = manifest.getAttributes(getName());
    
public java.security.cert.Certificate[]getCertificates()
Returns an array of {@code Certificate} Objects associated with this entry or {@code null} if none exists. Make sure that the everything is read from the input stream before calling this method, or else the method returns {@code null}.

return
the certificate for this entry.
see
java.security.cert.Certificate
since
Android 1.0

        if (null == parentJar) {
            return null;
        }
        JarVerifier jarVerifier = parentJar.verifier;
        if (null == jarVerifier) {
            return null;
        }
        return jarVerifier.getCertificates(getName());
    
public java.security.CodeSigner[]getCodeSigners()
Returns the code signers for the digital signatures associated with the JAR file. If there is no such code signer, it returns {@code null}. Make sure that the everything is read from the input stream before calling this method, or else the method returns {@code null}.

return
the code signers for the JAR entry.
see
CodeSigner
since
Android 1.0

        if (null == signers) {
            signers = getCodeSigners(getCertificates());
        }
        if (null == signers) {
            return null;
        }

        CodeSigner[] tmp = new CodeSigner[signers.length];
        System.arraycopy(signers, 0, tmp, 0, tmp.length);
        return tmp;
    
private java.security.CodeSigner[]getCodeSigners(java.security.cert.Certificate[] certs)

        if(null == certs) {
            return null;
        }

        X500Principal prevIssuer = null;
        ArrayList<Certificate> list = new ArrayList<Certificate>(certs.length);
        ArrayList<CodeSigner> asigners = new ArrayList<CodeSigner>();

        for (Certificate element : certs) {
            if (!(element instanceof X509Certificate)) {
                // Only X509Certificate-s are taken into account - see API spec.
                continue;
            }
            X509Certificate x509 = (X509Certificate) element;
            if (null != prevIssuer) {
                X500Principal subj = x509.getSubjectX500Principal();
                if (!prevIssuer.equals(subj)) {
                    // Ok, this ends the previous chain,
                    // so transform this one into CertPath ...
                    addCodeSigner(asigners, list);
                    // ... and start a new one
                    list.clear();
                }// else { it's still the same chain }

            }
            prevIssuer = x509.getIssuerX500Principal();
            list.add(x509);
        }
        if (!list.isEmpty()) {
            addCodeSigner(asigners, list);
        }
        if (asigners.isEmpty()) {
            // 'signers' is 'null' already
            return null;
        }

        CodeSigner[] tmp = new CodeSigner[asigners.size()];
        asigners.toArray(tmp);
        return tmp;

    
voidsetAttributes(java.util.jar.Attributes attrib)

        attributes = attrib;