optimize SecurityUtility code flow
@@ -422,12 +422,12 @@ public class SecurityUtility {
}
public static PrivateKey loadPrivateKeyFromPemFile(String keyFilePath) throws KeyManagementException {
- PrivateKey privateKey = null;
-
if (keyFilePath == null || keyFilePath.isEmpty()) {
- return privateKey;
+ return null;
}
+ PrivateKey privateKey;
+
try (FileInputStream input = new FileInputStream(keyFilePath)) {
privateKey = loadPrivateKeyFromPemStream(input);
} catch (IOException e) {
@@ -438,12 +438,12 @@ public class SecurityUtility {
}
public static PrivateKey loadPrivateKeyFromPemStream(InputStream inStream) throws KeyManagementException {
- PrivateKey privateKey = null;
-
if (inStream == null) {
- return privateKey;
+ return null;
}
+ PrivateKey privateKey;
+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, StandardCharsets.UTF_8))) {
if (inStream.markSupported()) {
inStream.reset();
