This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 1a7860070d970f65b7c005752021312097095216
Author: Pascal Schumacher <[email protected]>
AuthorDate: Sun Jan 19 12:26:28 2020 +0100

    Close InputStreams as reported by lgtm.com.
---
 .../java/org/apache/camel/maven/GenerateMojo.java  |  3 +-
 .../camel/component/cm/CMSenderOneMessageImpl.java | 64 +++++++++++-----------
 .../pubsub/GooglePubsubConnectionFactory.java      | 12 ++--
 .../maven/packaging/PrepareCatalogKarafMojo.java   |  6 +-
 4 files changed, 42 insertions(+), 43 deletions(-)

diff --git 
a/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
 
b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
index a6946ff..346554b 100644
--- 
a/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
+++ 
b/catalog/camel-main-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
@@ -413,8 +413,7 @@ public class GenerateMojo extends AbstractMainMojo {
     protected Properties loadMappingsFile() throws MojoFailureException {
         Properties mappings = new OrderedProperties();
         if (mappingsFile.exists() && mappingsFile.isFile()) {
-            try {
-                InputStream is = new FileInputStream(mappingsFile);
+            try (InputStream is = new FileInputStream(mappingsFile)) {
                 mappings.load(is);
             } catch (IOException e) {
                 throw new MojoFailureException("Cannot load file: " + 
mappingsFile);
diff --git 
a/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/CMSenderOneMessageImpl.java
 
b/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/CMSenderOneMessageImpl.java
index 820fa7c..d753edc 100644
--- 
a/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/CMSenderOneMessageImpl.java
+++ 
b/components/camel-cm-sms/src/main/java/org/apache/camel/component/cm/CMSenderOneMessageImpl.java
@@ -205,47 +205,47 @@ public class CMSenderOneMessageImpl implements CMSender {
             // result of the request processing.
 
             // We obtaing the result text
-            final BufferedReader rd = new BufferedReader(new 
InputStreamReader(response.getEntity().getContent()));
-
-            final StringBuffer result = new StringBuffer();
-            String line = null;
-            while ((line = rd.readLine()) != null) {
-                result.append(line);
-            }
+            try (BufferedReader rd = new BufferedReader(new 
InputStreamReader(response.getEntity().getContent()))) {
+                final StringBuffer result = new StringBuffer();
+                String line = null;
+                while ((line = rd.readLine()) != null) {
+                    result.append(line);
+                }
 
-            // ... and process it
+                // ... and process it
 
-            line = result.toString();
-            if (!line.isEmpty()) {
+                line = result.toString();
+                if (!line.isEmpty()) {
 
-                // Line is not empty = error
-                LOG.debug("Result of the request processing: FAILED\n{}", 
line);
+                    // Line is not empty = error
+                    LOG.debug("Result of the request processing: FAILED\n{}", 
line);
 
-                // The response text contains the error description. We will
-                // throw a custom exception for each.
+                    // The response text contains the error description. We 
will
+                    // throw a custom exception for each.
 
-                if (line.contains(CMConstants.ERROR_UNKNOWN)) {
-                    throw new UnknownErrorException();
-                } else if (line.contains(CMConstants.ERROR_NO_ACCOUNT)) {
-                    throw new NoAccountFoundForProductTokenException();
-                } else if 
(line.contains(CMConstants.ERROR_INSUFICIENT_BALANCE)) {
-                    throw new InsufficientBalanceException();
-                } else if 
(line.contains(CMConstants.ERROR_UNROUTABLE_MESSAGE)) {
-                    throw new UnroutableMessageException();
-                } else if 
(line.contains(CMConstants.ERROR_INVALID_PRODUCT_TOKEN)) {
-                    throw new InvalidProductTokenException();
-                } else {
+                    if (line.contains(CMConstants.ERROR_UNKNOWN)) {
+                        throw new UnknownErrorException();
+                    } else if (line.contains(CMConstants.ERROR_NO_ACCOUNT)) {
+                        throw new NoAccountFoundForProductTokenException();
+                    } else if 
(line.contains(CMConstants.ERROR_INSUFICIENT_BALANCE)) {
+                        throw new InsufficientBalanceException();
+                    } else if 
(line.contains(CMConstants.ERROR_UNROUTABLE_MESSAGE)) {
+                        throw new UnroutableMessageException();
+                    } else if 
(line.contains(CMConstants.ERROR_INVALID_PRODUCT_TOKEN)) {
+                        throw new InvalidProductTokenException();
+                    } else {
 
-                    // SO FAR i would expect other kind of ERROR.
+                        // SO FAR i would expect other kind of ERROR.
 
-                    // MSISDN correctness and message validity is client
-                    // responsibility
-                    throw new CMResponseException("CHECK ME. I am not 
expecting this. ");
+                        // MSISDN correctness and message validity is client
+                        // responsibility
+                        throw new CMResponseException("CHECK ME. I am not 
expecting this. ");
+                    }
                 }
-            }
 
-            // Ok. Line is EMPTY - successfully submitted
-            LOG.debug("Result of the request processing: Successfully 
submited");
+                // Ok. Line is EMPTY - successfully submitted
+                LOG.debug("Result of the request processing: Successfully 
submited");
+            }
         } catch (final IOException io) {
             throw new CMDirectException(io);
         } catch (Throwable t) {
diff --git 
a/components/camel-google-pubsub/src/main/java/org/apache/camel/component/google/pubsub/GooglePubsubConnectionFactory.java
 
b/components/camel-google-pubsub/src/main/java/org/apache/camel/component/google/pubsub/GooglePubsubConnectionFactory.java
index ac21646..eb49057 100644
--- 
a/components/camel-google-pubsub/src/main/java/org/apache/camel/component/google/pubsub/GooglePubsubConnectionFactory.java
+++ 
b/components/camel-google-pubsub/src/main/java/org/apache/camel/component/google/pubsub/GooglePubsubConnectionFactory.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.google.pubsub;
 
 import java.io.FileInputStream;
+import java.io.InputStream;
 import java.security.KeyFactory;
 import java.security.PrivateKey;
 import java.security.spec.PKCS8EncodedKeySpec;
@@ -112,14 +113,15 @@ public class GooglePubsubConnectionFactory {
     }
 
     private GoogleCredential createFromFile() throws Exception {
+        try (InputStream is = new FileInputStream(credentialsFileLocation)) {
+            GoogleCredential credential = GoogleCredential.fromStream(is);
 
-        GoogleCredential credential = GoogleCredential.fromStream(new 
FileInputStream(credentialsFileLocation));
+            if (credential.createScopedRequired()) {
+                credential = credential.createScoped(PubsubScopes.all());
+            }
 
-        if (credential.createScopedRequired()) {
-            credential = credential.createScoped(PubsubScopes.all());
+            return credential;
         }
-
-        return credential;
     }
 
     private GoogleCredential createDefault() throws Exception {
diff --git 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java
 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java
index 81dac41..5057f8b 100644
--- 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java
+++ 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java
@@ -527,10 +527,8 @@ public class PrepareCatalogKarafMojo extends AbstractMojo {
         // load features.xml file and parse it
 
         Set<String> answer = new LinkedHashSet<>();
-        try {
-            File file = new File(featuresDir, "features.xml");
-            InputStream is = new FileInputStream(file);
-
+        File file = new File(featuresDir, "features.xml");
+        try (InputStream is = new FileInputStream(file)) {
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
             
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl";, true);
             dbf.setIgnoringComments(true);

Reply via email to