bOut.reset();
    public CertStore getCertificatesAndCRLs(        String  type,        String  provider)        throws NoSuchAlgorithmException, NoSuchProviderException, CMSException    {        if (certStore == null)        {            List                    certsAndcrls = new ArrayList();            ByteArrayOutputStream   bOut = new ByteArrayOutputStream();            ASN1OutputStream        aOut = new ASN1OutputStream(bOut);            CertificateFactory      cf;            try            {                cf = CertificateFactory.getInstance("X.509", provider);            }            catch (CertificateException ex)            {                throw new CMSException("can't get certificate factory.", ex);            }            //            // load the certificates and revocation lists if we have any            //            ASN1Set s = signedData.getCertificates();            if (s != null)            {                Enumeration e = s.getObjects();                while (e.hasMoreElements())                {                    try                    {                        DERObject obj = (DERObject)e.nextElement();                        if (obj instanceof ASN1Sequence)                        {                            certsAndcrls.add(cf.generateCertificate(                                new ByteArrayInputStream(obj.getEncoded())));                        }                    }                    catch (IOException ex)                    {                        throw new CMSException(                                "can't re-encode certificate!", ex);                    }                    catch (CertificateException ex)                    {                        throw new CMSException(                                "can't re-encode certificate!", ex);                    }                    bOut.reset();                }            }            s = signedData.getCRLs();            if (s != null)            {                Enumeration e = s.getObjects();                while (e.hasMoreElements())                {                    try                    {                        aOut.writeObject(e.nextElement());                        certsAndcrls.add(cf.generateCRL(                            new ByteArrayInputStream(bOut.toByteArray())));                    }                    catch (IOException ex)                    {                        throw new CMSException("can't re-encode CRL!", ex);                    }                    catch (CRLException ex)                    {                        throw new CMSException("can't re-encode CRL!", ex);                    }                    bOut.reset();                }            }            try            {                certStore = CertStore.getInstance(type,                     new CollectionCertStoreParameters(certsAndcrls), provider);            }            catch (InvalidAlgorithmParameterException e)            {                throw new CMSException("can't setup the CertStore", e);            }        }        return certStore;    }