in modules/jdktools/src/main/java/org/apache/harmony/tools/toolutils/KeyStoreLoaderSaver.java [64:132]
public static KeyStore loadStore(String path, String storeType, char[] storePass,
String providerName) throws FileNotFoundException,
KeyStoreException, NoSuchAlgorithmException, CertificateException,
IOException, NoSuchProviderException{
BufferedInputStream bis;
// if the path is given, make a FileInputStream on it
if (path != null) {
File ksFile = null;
URI uri = null;
try {
uri = new URI(path);
ksFile = new File(uri);
} catch (URISyntaxException e) {
ksFile = new File(path);
} catch (IllegalArgumentException e){
ksFile = new File(path);
}
if (!ksFile.exists()) {
throw new IOException("Keystore file does not exist");
}
if (ksFile.length() == 0) {
throw new IOException("Keystore file exists but is empty");
}
bis = new BufferedInputStream(new FileInputStream(ksFile));
} else { // if the path is not given, a new keystore will be created
bis = null;
}
// Set the store type to default if it is not given.
// The default value is set up in java.security file.
String checkedStoreType = (storeType != null) ? storeType : KeyStore
.getDefaultType();
KeyStore keyStore;
// if the provider name is not set
if (providerName == null) {
keyStore = KeyStore.getInstance(checkedStoreType);
} else {
try {
keyStore = KeyStore.getInstance(storeType, providerName);
} catch (NoSuchProviderException e) {
throw (NoSuchProviderException) new NoSuchProviderException(
"The provider " + providerName
+ " is not found in the environment.")
.initCause(e);
}
}
try {
// try to load the keystore
keyStore.load(bis, storePass);
} catch (NoSuchAlgorithmException e) {
throw new NoSuchAlgorithmException(
"Failed to find the algorithm to check the keystore integrity",
e);
} catch (CertificateException e) {
throw new CertificateException(
"Failed to load a certificate from the keystore. ", e);
} catch (IOException e) {
throw (IOException) new IOException("Failed to load the keystore. ")
.initCause(e);
} finally {
if (bis != null) {
bis.close();
}
}
return keyStore;
}