code: public static void savePrivateKey(OutputStream os, PrivateKey key,
      PrivateKeyEncoding encoding) throws IOException {
  
      switch (encoding) {
      case PKCS_1:
        savePrivateKeyPKCS1(os, key);
        break;
      case PKCS_8:
        savePrivateKeyPKCS8(os, key);
        break;
      default:
        throw new IllegalArgumentException("Unsupported private key encoding: "
          + encoding.name());
      }
    }
docs: Serializes a private key to an output stream according to an encoding.
  
  @param os
  the target output stream
  @param key
  the key to be serialized
  @param encoding
  the encoding
  
  @throws IllegalArgumentException
  for unsupported private key encodings
  @throws IOException
  if write fails for any reason on the output stream