code: private static List<X509Certificate> parsePKCS7(InputStream is)
              throws CertificateException {
          List<X509Certificate> certList;
  
          if (is == null) {
              throw new CertificateException("input stream is null");
          }
  
          try {
              if (is.markSupported() == false) {
                  // Copy the entire input stream into an InputStream that does
                  // support mark
                  is = new ByteArrayInputStream(readAllBytes(is));
              }
              PKCS7 pkcs7 = new PKCS7(is);
  
              X509Certificate[] certArray = pkcs7.getCertificates();
              // certs are optional in PKCS #7
              if (certArray != null) {
                  certList = Arrays.asList(certArray);
              } else {
                  // no certs provided
                  certList = new ArrayList<X509Certificate>(0);
              }
          } catch (IOException ioe) {
              throw new CertificateException("IOException parsing PKCS7 data: " +
                                          ioe);
          }
          // Assumes that the resulting List is thread-safe. This is true
          // because we ensure that it cannot be modified after construction
          // and the methods in the Sun JDK 1.4 implementation of ArrayList that
          // allow read-only access are thread-safe.
          return Collections.unmodifiableList(certList);
      }
docs: Parse a PKCS#7 format CertPath from an InputStream. Return an
  unmodifiable List of the certificates.
  
  @param is the <code>InputStream</code> to read the data from
  @return an unmodifiable List of the certificates
  @exception CertificateException if an exception occurs