protected void writeKeyStore(KeyStore keyStore, OutputStream outputStream) throws AmbariException {
    if (masterKeyService == null) {
      throw new AmbariException("Master Key Service is not set for this Credential store.");
    }

    try {
      keyStore.store(outputStream, masterKeyService.getMasterSecret());
    } catch (CertificateException e) {
      throw new AmbariException(String.format("A credential within in the key store data could not be stored: %s", e.getLocalizedMessage()), e);
    } catch (NoSuchAlgorithmException e) {
      throw new AmbariException(String.format("The appropriate data integrity algorithm could not be found: %s", e.getLocalizedMessage()), e);
    } catch (KeyStoreException e) {
      throw new AmbariException(String.format("The key store has not been initialized: %s", e.getLocalizedMessage()), e);
    } catch (IOException e) {
      throw new AmbariException(String.format("Failed to write the key store: %s", e.getLocalizedMessage()), e);
    }
  }
Writes a KeyStore to an OutputStream
<p/>
Implementations are expected to call this to write the relevant KeyStore data to the
OutputStream of some storage facility.

@param keyStore     the KeyStore to write
@param outputStream the OutputStream to write the data into
@throws AmbariException if an error occurs while writing the key store data
ambari-server/src/main/java/org/apache/ambari/server/security/encryption/AbstractCredentialStore.java