code: private Collection<? extends java.security.cert.Certificate>
          parseX509orPKCS7Cert(InputStream is)
          throws CertificateException, IOException
      {
          Collection<X509CertImpl> coll = new ArrayList<>();
          byte[] data = readOneBlock(is);
          if (data == null) {
              return new ArrayList<>(0);
          }
          try {
              PKCS7 pkcs7 = new PKCS7(data);
              X509Certificate[] certs = pkcs7.getCertificates();
              // certs are optional in PKCS #7
              if (certs != null) {
                  return Arrays.asList(certs);
              } else {
                  // no crls provided
                  return new ArrayList<>(0);
              }
          } catch (ParsingException e) {
              while (data != null) {
                  coll.add(new X509CertImpl(data));
                  data = readOneBlock(is);
              }
          }
          return coll;
      }
docs: /*
  Parses the data in the given input stream as a sequence of DER
  encoded X.509 certificates (in binary or base 64 encoded format) OR
  as a single PKCS#7 encoded blob (in binary or base64 encoded format).