public static void write(final X509Certificate certificate,
		final @NonNull OutputStream outputStream, KeyFileFormat fileFormat)
		throws IOException, CertificateEncodingException
	{
		final byte[] certificateBytes = certificate.getEncoded();
		switch (fileFormat)
		{
			case PEM :
				outputStream.write(
					CertificateReader.BEGIN_CERTIFICATE_PREFIX.getBytes(StandardCharsets.US_ASCII));
				outputStream.write(Base64.encodeBase64(certificateBytes, true));
				outputStream.write(
					CertificateReader.END_CERTIFICATE_SUFFIX.getBytes(StandardCharsets.US_ASCII));
				break;
			default :
				outputStream.write(certificateBytes);
				break;
		}
		outputStream.close();
	}
public static void write ( final X509Certificate certificate , final @ NonNull OutputStream outputStream , KeyFileFormat fileFormat ) throws IOException , CertificateEncodingException { final byte [ ] certificateBytes = certificate . getEncoded ( ) ; switch ( fileFormat ) { case PEM : outputStream . write ( CertificateReader . BEGIN_CERTIFICATE_PREFIX . getBytes ( StandardCharsets . US_ASCII ) ) ; outputStream . write ( Base64 . encodeBase64 ( certificateBytes , true ) ) ; outputStream . write ( CertificateReader . END_CERTIFICATE_SUFFIX . getBytes ( StandardCharsets . US_ASCII ) ) ; break ; default : outputStream . write ( certificateBytes ) ; break ; } outputStream . close ( ) ; }
Write the given {@link X509Certificate} into the given {@link OutputStream} in the given
{@link KeyFileFormat} format.

@param certificate
the certificate
@param outputStream
the output stream
@param fileFormat
the file format to write
@throws IOException
Signals that an I/O exception has occurred.
@throws CertificateEncodingException
is thrown if an encoding error occurs.