Commit 946881b0c0ff98fbf46dbc85180de49889df567e

Authored by blackstar-baba
Committed by Andrew Shvayka
1 parent 559183e9

close the stream after generateCertificate

close the stream after generateCertificate
... ... @@ -38,6 +38,7 @@ import javax.crypto.spec.PBEKeySpec;
38 38 import javax.net.ssl.KeyManagerFactory;
39 39 import javax.net.ssl.TrustManagerFactory;
40 40 import java.io.ByteArrayInputStream;
  41 +import java.io.InputStream;
41 42 import java.security.AlgorithmParameters;
42 43 import java.security.Key;
43 44 import java.security.KeyFactory;
... ... @@ -142,7 +143,9 @@ public class CertPemClientCredentials implements MqttClientCredentials {
142 143 .replaceAll("\\s", "");
143 144 byte[] decoded = Base64.decodeBase64(fileContent);
144 145 CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
145   - certificate = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(decoded));
  146 + try (InputStream inStream = new ByteArrayInputStream(decoded)) {
  147 + certificate = (X509Certificate) certFactory.generateCertificate(inStream);
  148 + }
146 149 }
147 150 return certificate;
148 151 }
... ...