Skip to content

Commit f6e300b

Browse files
committed
🎨 及时关闭打开的InputStream对象
1 parent 5a811ff commit f6e300b

File tree

1 file changed

+9
-6
lines changed
  • weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config

1 file changed

+9
-6
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,18 @@ public CloseableHttpClient initApiV3HttpClient() throws WxPayException {
279279
if (StringUtils.isNotBlank(this.getPrivateKeyString())) {
280280
this.setPrivateKeyString(Base64.getEncoder().encodeToString(this.getPrivateKeyString().getBytes()));
281281
}
282-
InputStream keyInputStream = this.loadConfigInputStream(this.getPrivateKeyString(), this.getPrivateKeyPath(),
283-
this.privateKeyContent, "privateKeyPath");
284-
merchantPrivateKey = PemUtils.loadPrivateKey(keyInputStream);
282+
283+
try (InputStream keyInputStream = this.loadConfigInputStream(this.getPrivateKeyString(), this.getPrivateKeyPath(),
284+
this.privateKeyContent, "privateKeyPath")) {
285+
merchantPrivateKey = PemUtils.loadPrivateKey(keyInputStream);
286+
}
285287

286288
}
287289
if (certificate == null && StringUtils.isBlank(this.getCertSerialNo())) {
288-
InputStream certInputStream = this.loadConfigInputStream(this.getPrivateCertString(), this.getPrivateCertPath(),
289-
this.privateCertContent, "privateCertPath");
290-
certificate = PemUtils.loadCertificate(certInputStream);
290+
try (InputStream certInputStream = this.loadConfigInputStream(this.getPrivateCertString(), this.getPrivateCertPath(),
291+
this.privateCertContent, "privateCertPath")) {
292+
certificate = PemUtils.loadCertificate(certInputStream);
293+
}
291294
this.certSerialNo = certificate.getSerialNumber().toString(16).toUpperCase();
292295
}
293296

0 commit comments

Comments
 (0)