🎨 及时关闭打开的InputStream对象

This commit is contained in:
Binary Wang 2024-10-31 16:20:24 +08:00
parent 5a811fff9d
commit f6e300b10a

View File

@ -279,15 +279,18 @@ public class WxPayConfig {
if (StringUtils.isNotBlank(this.getPrivateKeyString())) {
this.setPrivateKeyString(Base64.getEncoder().encodeToString(this.getPrivateKeyString().getBytes()));
}
InputStream keyInputStream = this.loadConfigInputStream(this.getPrivateKeyString(), this.getPrivateKeyPath(),
this.privateKeyContent, "privateKeyPath");
merchantPrivateKey = PemUtils.loadPrivateKey(keyInputStream);
try (InputStream keyInputStream = this.loadConfigInputStream(this.getPrivateKeyString(), this.getPrivateKeyPath(),
this.privateKeyContent, "privateKeyPath")) {
merchantPrivateKey = PemUtils.loadPrivateKey(keyInputStream);
}
}
if (certificate == null && StringUtils.isBlank(this.getCertSerialNo())) {
InputStream certInputStream = this.loadConfigInputStream(this.getPrivateCertString(), this.getPrivateCertPath(),
this.privateCertContent, "privateCertPath");
certificate = PemUtils.loadCertificate(certInputStream);
try (InputStream certInputStream = this.loadConfigInputStream(this.getPrivateCertString(), this.getPrivateCertPath(),
this.privateCertContent, "privateCertPath")) {
certificate = PemUtils.loadCertificate(certInputStream);
}
this.certSerialNo = certificate.getSerialNumber().toString(16).toUpperCase();
}