Browse Source

Use try with resources when handling FileStreams

CommentSectionScientist 5 năm trước cách đây
mục cha
commit
5ba4d9c26e

+ 3 - 3
RISE-V2G-Shared/src/main/java/com/v2gclarity/risev2g/shared/utils/SecurityUtils.java

@@ -1008,9 +1008,9 @@ public final class SecurityUtils {
 						getCertificateChain(contractCertChain)); 
 				
 				// Save the keystore persistently
-				FileOutputStream fos = new FileOutputStream("evccKeystore.jks");
-				keyStore.store(fos, GlobalValues.PASSPHRASE_FOR_CERTIFICATES_AND_KEYS.toString().toCharArray());
-				fos.close();
+				try(FileOutputStream fos = new FileOutputStream("evccKeystore.jks")){
+					keyStore.store(fos, GlobalValues.PASSPHRASE_FOR_CERTIFICATES_AND_KEYS.toString().toCharArray());
+				}
 				
 				X509Certificate contractCert = getCertificate(contractCertChain.getCertificate());