code: public static void saveProxyCredentials(OutputStream os, X509Credential uc,
      PrivateKeyEncoding encoding) throws IOException {
  
      X509Certificate[] chain = CertificateHelpers.sortChain(Arrays.asList(uc
        .getCertificateChain()));
  
      PrivateKey key = uc.getKey();
      X509Certificate cert = uc.getCertificate();
  
      CertificateUtils.saveCertificate(os, cert, Encoding.PEM);
  
      if (key != null)
        savePrivateKey(os, key, encoding);
  
      X509Certificate c = null;
      for (int index = 1; index < chain.length; index++) {
  
        c = chain[index];
  
        int basicConstraints = c.getBasicConstraints();
  
        // Only save non-CA certs to proxy file
        if (basicConstraints < 0){
          CertificateUtils.saveCertificate(os, c, Encoding.PEM);
        }
        
      }
  
      os.flush();
    }
docs: Saves user credentials as a plain text PEM data. <br>
  Writes the user certificate chain first, then the user key.
  
  @param os
  the output stream
  @param uc
  the user credential that must be serialized
  @param encoding
  the private key encoding
  
  
  @throws IOException
  in case of errors writing on the output stream