code: private Certificate[] loadCertChain(File certFile)
  	throws Exception
      {
          DataInputStream dis = null;
          try
          {
              FileInputStream fis = new FileInputStream(certFile);
              dis = new DataInputStream(fis);
              byte[] bytes = new byte[dis.available()];
              dis.readFully(bytes);
              ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
  	
              CertificateFactory certificateFactory
                  = CertificateFactory.getInstance("X.509");
  
              ArrayList chain = new ArrayList();
              while (bais.available() > 0) {
                  Certificate cert
                      = certificateFactory.generateCertificate(bais);
                  // System.out.println(cert.toString());
                  chain.add(cert);
              }
  
              Certificate[] certChain
                  = (Certificate[])chain.toArray(new Certificate[chain.size()]);
  
              System.out.println("Loaded the cert chain. Depth = "
                                 + certChain.length);
              return certChain;
          }
          finally
          {
              IO.close(dis);
          }
      }
docs: Load the chain of certificates from the given File.
  <p> Note that the certificates must be in the correct order to
  form a valid chain starting with the cert corresponding to the
  private key and ending with the cert just before the top level
  cert.
  @param certFile String name of file to load the key from
  @return PrivateKey loaded from the file
  @throws Exception if there are problems with loading the key.