/**
 * The MIT License
 *
 * Copyright (C) 2015 Asterios Raptis
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package de.alpharogroup.crypto.factories;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;

/**
 * The factory class {@link KeyStoreFactory} holds methods for creating {@link KeyStore} objects.
 */
public class KeyStoreFactory
{

	/**
	 * Factory method for load the {@link KeyStore} object from the given file.
	 *
	 * @param type
	 *            the type of the keystore
	 * @param password
	 *            the password of the keystore
	 * @param keystoreFile
	 *            the keystore file
	 * @return the loaded {@link KeyStore} object
	 * @throws NoSuchAlgorithmException
	 *             the no such algorithm exception
	 * @throws CertificateException
	 *             the certificate exception
	 * @throws FileNotFoundException
	 *             the file not found exception
	 * @throws IOException
	 *             Signals that an I/O exception has occurred.
	 * @throws KeyStoreException
	 *             the key store exception
	 */
	public static KeyStore newKeyStore(final String type, final String password,
		final File keystoreFile) throws NoSuchAlgorithmException, CertificateException,
		FileNotFoundException, IOException, KeyStoreException
	{
		final KeyStore keyStore = KeyStore.getInstance(type);
		keyStore.load(new FileInputStream(keystoreFile), password.toCharArray());
		return keyStore;
	}
}

@@ -1288,27 +1288,89 @@
 java.io.
-IOException
+FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.OutputStream
 ;%0Aimport
@@ -2601,61 +2601,1551 @@
 %7B%0A%09%09
-final KeyStore keyStore = KeyStore.getInstance(type);
+return newKeyStore(type, password, keystoreFile, false);%0A%09%7D%0A%0A%09/**%0A%09 * Factory method for create a new empty %7B@link KeyStore%7D object and save it%0A%09 * to the given file with the given parameters or load an existing%0A%09 * %7B@link KeyStore%7D object from the given file.%0A%09 *%0A%09 * @param type%0A%09 *            the type of the keystore%0A%09 * @param password%0A%09 *            the password of the keystore%0A%09 * @param keystoreFile%0A%09 *            the keystore file%0A%09 * @param newEmpty%0A%09 *            if the %7B@linkplain KeyStore%7D should be new created.%0A%09 * @return the loaded %7B@link KeyStore%7D object%0A%09 * @throws NoSuchAlgorithmException%0A%09 *             the no such algorithm exception%0A%09 * @throws CertificateException%0A%09 *             the certificate exception%0A%09 * @throws FileNotFoundException%0A%09 *             the file not found exception%0A%09 * @throws IOException%0A%09 *             Signals that an I/O exception has occurred.%0A%09 * @throws KeyStoreException%0A%09 *             the key store exception%0A%09 */%0A%09public static KeyStore newKeyStore(final String type, final String password, final File keystoreFile,%0A%09%09%09final boolean newEmpty) throws NoSuchAlgorithmException, CertificateException, FileNotFoundException,%0A%09%09%09IOException, KeyStoreException %0A%09%7B%0A%09%09final KeyStore keyStore = KeyStore.getInstance(type);%0A%09%09if (newEmpty) %7B%0A%09%09%09keyStore.load(null, password.toCharArray());%0A%09%09%09if (!keystoreFile.exists()) %7B%0A%09%09%09%09keystoreFile.createNewFile();%0A%09%09%09%7D%0A%09%09%09OutputStream out = new FileOutputStream(keystoreFile);%0A%09%09%09keyStore.store(out, password.toCharArray());%0A%09%09%09return keyStore;%0A%09%09%7D
 %0A%09%09k
@@ -4239,10 +4239,11 @@
 ore;%0A%09%7D%0A
+%0A
 %7D%0A

Update KeyStoreFactory.java