You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/12/30 09:11:24 UTC

[camel] 04/05: camel-google-bigquery: Close the FileInputStream in GoogleBigQueryConnectionFactory#createFromFile

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

davsclaus pushed a commit to branch camel-3.0.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit e039a8f93952fa82bb6234d67a6f4075df514b21
Author: Pascal Schumacher <pa...@gmx.net>
AuthorDate: Sun Dec 29 16:36:11 2019 +0100

    camel-google-bigquery: Close the FileInputStream in GoogleBigQueryConnectionFactory#createFromFile
---
 .../google/bigquery/GoogleBigQueryConnectionFactory.java      | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryConnectionFactory.java b/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryConnectionFactory.java
index 3c7db1d..5fc3536 100644
--- a/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryConnectionFactory.java
+++ b/components/camel-google-bigquery/src/main/java/org/apache/camel/component/google/bigquery/GoogleBigQueryConnectionFactory.java
@@ -113,14 +113,15 @@ public class GoogleBigQueryConnectionFactory {
     }
 
     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(BigqueryScopes.all());
+            }
 
-        if (credential.createScopedRequired()) {
-            credential = credential.createScoped(BigqueryScopes.all());
+            return credential;
         }
-
-        return credential;
     }
 
     private GoogleCredential createDefault() throws Exception {