tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject [5/6] incubator-tamaya git commit: TAMAYA-39 Now using InputStreamCloser to ensure that overhanded InputStream instances will be closed.
Date Sat, 28 Feb 2015 22:52:08 GMT
TAMAYA-39 Now using InputStreamCloser to ensure that overhanded InputStream instances will
be closed.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/890c4897
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/890c4897
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/890c4897

Branch: refs/heads/master
Commit: 890c48976faed023978c8fae5e64885ae2c7fcdf
Parents: e7b5a11
Author: Oliver B. Fischer <plexus@apache.org>
Authored: Sat Feb 28 14:11:03 2015 +0100
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Sat Feb 28 23:42:39 2015 +0100

----------------------------------------------------------------------
 .../tamaya/format/formats/PropertiesFormat.java       | 14 +++++---------
 .../tamaya/format/formats/PropertiesXmlFormat.java    | 14 +++++---------
 2 files changed, 10 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/890c4897/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
b/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
index 8442c6e..99ec1cc 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
@@ -21,8 +21,8 @@ package org.apache.tamaya.format.formats;
 import org.apache.tamaya.format.ConfigurationData;
 import org.apache.tamaya.format.ConfigurationDataBuilder;
 import org.apache.tamaya.format.ConfigurationFormat;
+import org.apache.tamaya.format.InputStreamCloser;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Map;
@@ -55,19 +55,15 @@ public class PropertiesFormat implements ConfigurationFormat {
     public ConfigurationData readConfiguration(String resource, InputStream inputStream)
{
         Objects.requireNonNull(inputStream);
         Objects.requireNonNull(resource);
-        try {
+
+        try (InputStream in = new InputStreamCloser(inputStream)) {
             final Properties p = new Properties();
-            p.load(inputStream);
+            p.load(in);
             return ConfigurationDataBuilder.of(resource, this).addProperties(Map.class.cast(p)).build();
         } catch (Exception e) {
             LOG.log(Level.FINEST, e, () -> "Failed to read config from resource: " + resource);
-        } finally {
-            try {
-                inputStream.close();
-            } catch (IOException e) {
-                LOG.log(Level.FINEST, e, () -> "Failed to close resource: " + resource);
-            }
         }
+
         return null;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/890c4897/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
b/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
index f10aef8..5130e3b 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
@@ -21,8 +21,8 @@ package org.apache.tamaya.format.formats;
 import org.apache.tamaya.format.ConfigurationData;
 import org.apache.tamaya.format.ConfigurationDataBuilder;
 import org.apache.tamaya.format.ConfigurationFormat;
+import org.apache.tamaya.format.InputStreamCloser;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.*;
@@ -52,19 +52,15 @@ public class PropertiesXmlFormat implements ConfigurationFormat {
     public ConfigurationData readConfiguration(String resource, InputStream inputStream)
{
         Objects.requireNonNull(inputStream);
         Objects.requireNonNull(resource);
-        try {
+
+        try (InputStream in = new InputStreamCloser(inputStream)) {
             final Properties p = new Properties();
-            p.loadFromXML(inputStream);
+            p.loadFromXML(in);
             return ConfigurationDataBuilder.of(resource, this).addProperties(Map.class.cast(p)).build();
         } catch (Exception e) {
             LOG.log(Level.FINEST, e, () -> "Failed to read config from resource: " + resource);
-        } finally {
-            try {
-                inputStream.close();
-            } catch (IOException e) {
-                LOG.log(Level.FINEST, e, () -> "Failed to close resource: " + resource);
-            }
         }
+
         return null;
     }
 }


Mime
View raw message