public static Collection getCertsFromPEM(InputStream certstream) throws IOException, CertificateException { log.debug(">getCertfromPEM:"); ArrayList ret = new ArrayList(); String beginKey = "-----BEGIN CERTIFICATE-----"; String endKey = "-----END CERTIFICATE-----"; BufferedReader bufRdr = null; ByteArrayOutputStream ostr = null; PrintStream opstr = null;
public static Collection getCertsFromPEM(String certFile) throws IOException, CertificateException { log.debug(">getCertfromPEM: certFile=" + certFile); InputStream inStrm = null; Collection certs;
    public static Collection getCertsFromPEM(InputStream certstream)    throws IOException, CertificateException {        log.debug(">getCertfromPEM:");        ArrayList ret = new ArrayList();        String beginKey = "-----BEGIN CERTIFICATE-----";        String endKey = "-----END CERTIFICATE-----";        BufferedReader bufRdr = null;        ByteArrayOutputStream ostr = null;        PrintStream opstr = null;		try {			bufRdr = new BufferedReader(new InputStreamReader(certstream));			while (bufRdr.ready()) {				ostr = new ByteArrayOutputStream();				opstr = new PrintStream(ostr);				String temp;				while ((temp = bufRdr.readLine()) != null						&& !temp.equals(beginKey))					continue;				if (temp == null)					throw new IOException("Error in " + certstream.toString()							+ ", missing " + beginKey + " boundary");				while ((temp = bufRdr.readLine()) != null						&& !temp.equals(endKey))					opstr.print(temp);				if (temp == null)					throw new IOException("Error in " + certstream.toString()							+ ", missing " + endKey + " boundary");				opstr.close();				byte[] certbuf = Base64.decode(ostr.toByteArray());				ostr.close();				// Phweeew, were done, now decode the cert from file back to X509Certificate object				CertificateFactory cf = CertTools.getCertificateFactory();				X509Certificate x509cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(certbuf));				ret.add(x509cert);			}		} finally {			if (bufRdr != null) bufRdr.close();			if (opstr != null) opstr.close();			if (ostr != null) ostr.close();		}        		log.debug("<getcertfromPEM:" + ret.size());        return ret;    } // getCertsFromPEM