604 lines · 21.4 KB · Java
RawDownload
    public PermissionCollection newPermissionCollection() {        return new UnresolvedPermissionCollection();    }     /**     * Writes this object out to a stream (i.e., serializes it).     *     * @serialData An initial <code>String</code> denoting the     * <code>type</code> is followed by a <code>String</code> denoting the     * <code>name</code> is followed by a <code>String</code> denoting the     * <code>actions</code> is followed by an <code>int</code> indicating the     * number of certificates to follow     * (a value of "zero" denotes that there are no certificates associated     * with this object).     * Each certificate is written out starting with a <code>String</code>     * denoting the certificate type, followed by an     * <code>int</code> specifying the length of the certificate encoding,     * followed by the certificate encoding itself which is written out as an     * array of bytes.     */    private void writeObject(java.io.ObjectOutputStream oos)        throws IOException    {        oos.defaultWriteObject();         if (certs==null || certs.length==0) {            oos.writeInt(0);        } else {            // write out the total number of certs            oos.writeInt(certs.length);            // write out each cert, including its type            for (int i=0; i < certs.length; i++) {                java.security.cert.Certificate cert = certs[i];                try {                    oos.writeUTF(cert.getType());                    byte[] encoded = cert.getEncoded();                    oos.writeInt(encoded.length);                    oos.write(encoded);                } catch (CertificateEncodingException cee) {                    throw new IOException(cee.getMessage());                }            }        }    }     /**     * Restores this object from a stream (i.e., deserializes it).     */    private void readObject(java.io.ObjectInputStream ois)        throws IOException, ClassNotFoundException    {        CertificateFactory cf;        Hashtable<String, CertificateFactory> cfs = null;         ois.defaultReadObject();         if (type == null)                throw new NullPointerException("type can't be null");         // process any new-style certs in the stream (if present)        int size = ois.readInt();        if (size > 0) {            // we know of 3 different cert types: X.509, PGP, SDSI, which            // could all be present in the stream at the same time            cfs = new Hashtable<String, CertificateFactory>(3);            this.certs = new java.security.cert.Certificate[size];        }         for (int i=0; i<size; i++) {            // read the certificate type, and instantiate a certificate            // factory of that type (reuse existing factory if possible)            String certType = ois.readUTF();            if (cfs.containsKey(certType)) {                // reuse certificate factory                cf = cfs.get(certType);            } else {                // create new certificate factory                try {                    cf = CertificateFactory.getInstance(certType);                } catch (CertificateException ce) {                    throw new ClassNotFoundException                        ("Certificate factory for "+certType+" not found");                }                // store the certificate factory so we can reuse it later                cfs.put(certType, cf);            }            // parse the certificate            byte[] encoded=null;            try {                encoded = new byte[ois.readInt()];            } catch (OutOfMemoryError oome) {                throw new IOException("Certificate too big");            }            ois.readFully(encoded);            ByteArrayInputStream bais = new ByteArrayInputStream(encoded);            try {                this.certs[i] = cf.generateCertificate(bais);            } catch (CertificateException ce) {                throw new IOException(ce.getMessage());            }            bais.close();        }    }}

Lines 501–604 of 604. Previous lines