Close FileInputStream after consuming it in SelfSignedCertificate
Motivation: FileInputStream opened by SelfSignedCertificate wasn't closed. Modifications: Use a try-finally to close the opened FileInputStream. Result: FileInputStream will be closed properly.
This commit is contained in:
parent
80f45d6ae5
commit
507feb5602
@ -162,11 +162,20 @@ public final class SelfSignedCertificate {
|
|||||||
certificate = new File(paths[0]);
|
certificate = new File(paths[0]);
|
||||||
privateKey = new File(paths[1]);
|
privateKey = new File(paths[1]);
|
||||||
key = keypair.getPrivate();
|
key = keypair.getPrivate();
|
||||||
|
FileInputStream certificateInput = null;
|
||||||
try {
|
try {
|
||||||
cert = (X509Certificate) CertificateFactory.getInstance("X509").generateCertificate(
|
certificateInput = new FileInputStream(certificate);
|
||||||
new FileInputStream(certificate));
|
cert = (X509Certificate) CertificateFactory.getInstance("X509").generateCertificate(certificateInput);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CertificateEncodingException(e);
|
throw new CertificateEncodingException(e);
|
||||||
|
} finally {
|
||||||
|
if (certificateInput != null) {
|
||||||
|
try {
|
||||||
|
certificateInput.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.warn("Failed to close a file: " + certificate, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user