tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject incubator-tamaya git commit: Refactored API for formats slightly, adapted dependend modules.
Date Thu, 02 Jul 2015 22:47:21 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master c1ef16f6d -> 96a550b2a


Refactored API for formats slightly, adapted dependend modules.


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

Branch: refs/heads/master
Commit: 96a550b2a1ce8d60c721c32e0ae44f5e0dcb1924
Parents: c1ef16f
Author: anatole <atsticks@gmail.com>
Authored: Fri Jul 3 00:47:13 2015 +0200
Committer: anatole <atsticks@gmail.com>
Committed: Fri Jul 3 00:47:13 2015 +0200

----------------------------------------------------------------------
 .../apache/tamaya/format/ConfigurationData.java | 129 ++++++++++---
 .../tamaya/format/ConfigurationDataBuilder.java | 102 +++++++++--
 .../tamaya/format/ConfigurationFormat.java      |  10 +-
 .../tamaya/format/ConfigurationFormats.java     |  23 +--
 .../format/FlattenedDefaultPropertySource.java  |  12 +-
 .../apache/tamaya/format/InputStreamCloser.java |  93 ----------
 .../tamaya/format/InputStreamFactory.java       |  88 +++++++++
 .../format/formats/IniConfigurationFormat.java  |   3 +-
 .../tamaya/format/formats/PropertiesFormat.java |   7 +-
 .../format/formats/PropertiesXmlFormat.java     |   6 +-
 .../tamaya/format/ConfigurationFormatsTest.java |   2 -
 .../FlattenedDefaultPropertySourceTest.java     |  26 ++-
 .../tamaya/format/InputStreamCloserTest.java    | 182 -------------------
 .../tamaya/format/InputStreamFactoryTest.java   | 147 +++++++++++++++
 .../java/org/apache/tamaya/json/JSONFormat.java |   6 +-
 .../apache/tamaya/management/ManagedConfig.java |  63 ++-----
 .../tamaya/management/ManagedConfigMBean.java   | 131 +++----------
 17 files changed, 500 insertions(+), 530 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationData.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationData.java b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationData.java
index 3d53792..628b6bd 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationData.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationData.java
@@ -18,9 +18,7 @@
  */
 package org.apache.tamaya.format;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * Data that abstracts the data read from a configuration resources using a certain format. The data can be divided
@@ -35,24 +33,23 @@ import java.util.Set;
  * </ul>
  */
 public final class ConfigurationData {
-
     /**
-     * The default entry type returned if a format implementation does not support any explicit entry types.
+     * The properties of the default section (no name).
      */
-    public static final String DEFAULT_SECTION_NAME = "default";
-
+    private Map<String, String> defaultProperties;
     /**
-     * Name of a section that should be written by every format implementation if possible, hereby mapping the
-     * complete configuration structure to one flattened key/value layer. This section is used for creating
-     * default PropertySource for a ConfigurationData instance.
+     * A normalized flattened set of this configuration data.
      */
-    public static final String FLATTENED_SECTION_NAME = "_flattened";
+    private Map<String, String> combinedProperties;
+    /**
+     * The sections read.
+     */
+    private Map<String, Map<String, String>> namedSections;
     /** The format instance used to read this instance. */
     private ConfigurationFormat format;
     /** The resource read. */
     private String resource;
-    /** The data read. */
-    private Map<String,Map<String,String>> data = new HashMap<>();
+
 
     /**
      * COnstructor used by builder.
@@ -60,8 +57,31 @@ public final class ConfigurationData {
      */
     ConfigurationData(ConfigurationDataBuilder builder){
         this.format = builder.format;
-        this.data.putAll(builder.data);
         this.resource = builder.resource;
+        if (builder.defaultProperties != null) {
+            this.defaultProperties = new HashMap<>();
+            this.defaultProperties.putAll(builder.defaultProperties);
+        }
+        if (builder.combinedProperties != null) {
+            this.combinedProperties = new HashMap<>();
+            this.combinedProperties.putAll(builder.combinedProperties);
+        }
+        if (builder.namedSections != null) {
+            this.namedSections = new HashMap<>();
+            this.namedSections.putAll(builder.namedSections);
+        }
+        if (this.combinedProperties == null || this.combinedProperties.isEmpty()) {
+            this.combinedProperties = new HashMap<>();
+            this.combinedProperties.putAll(getDefaultProperties());
+            // popuilate it with sections...
+            for (String sectionName : getSectionNames()) {
+                Map<String, String> section = getSection(sectionName);
+                for (Map.Entry<String, String> en : section.entrySet()) {
+                    String key = sectionName + '.' + en.getKey();
+                    combinedProperties.put(key, en.getValue());
+                }
+            }
+        }
     }
 
     /**
@@ -84,8 +104,11 @@ public final class ConfigurationData {
      * Access an immutable Set of all present section names, including the default section (if any).
      * @return the set of present section names, never null.
      */
-    public Set<String> getSections(){
-        return data.keySet();
+    public Set<String> getSectionNames() {
+        if (namedSections == null) {
+            return Collections.emptySet();
+        }
+        return namedSections.keySet();
     }
 
     /**
@@ -93,32 +116,82 @@ public final class ConfigurationData {
      * @param name the section name, not null.
      * @return the data of this section, or null, if no such section exists.
      */
-    public Map<String,String> getSection(String name){
-        return this.data.get(name);
+    public Map<String, String> getSection(String name) {
+        return this.namedSections.get(name);
     }
 
     /**
      * Convenience accessor for accessing the default section.
      * @return the default section's data, or null, if no such section exists.
      */
-    public Map<String,String> getDefaultSection(){
-        return getSection(DEFAULT_SECTION_NAME);
+    public Map<String, String> getDefaultProperties() {
+        return Optional.ofNullable(defaultProperties).orElse(Collections.emptyMap());
+    }
+
+    /**
+     * Get combined properties for this config data instance. If
+     *
+     * @return the normalized properties.
+     */
+    public Map<String, String> getCombinedProperties() {
+        return Optional.ofNullable(combinedProperties).orElse(Collections.emptyMap());
+    }
+
+    /**
+     * Accessor used for easily creating a new builder based on a given data instance.
+     *
+     * @return the data contained, never null.
+     */
+    public Map<String, Map<String, String>> getSections() {
+        return Optional.ofNullable(namedSections).orElse(Collections.emptyMap());
+    }
+
+    /**
+     * Immutable accessor to ckeck, if there are default properties present.
+     *
+     * @return true, if default properties are present.
+     */
+    public boolean hasDefaultProperties() {
+        return this.defaultProperties != null && !this.defaultProperties.isEmpty();
+    }
+
+    /**
+     * Immutable accessor to ckeck, if there are combined properties set.
+     *
+     * @return true, if combined properties are set.
+     */
+    public boolean hasCombinedProperties() {
+        return this.combinedProperties != null && !this.combinedProperties.isEmpty();
+    }
+
+    /**
+     * Immutable accessor to ckeck, if there are named sections present.
+     *
+     * @return true, if at least one named section is present.
+     */
+    public boolean hasSections() {
+        return this.namedSections != null && !this.namedSections.isEmpty();
+    }
+
+    /**
+     * Checks if no properties are contained in this data item.
+     *
+     * @return true, if no properties are contained in this data item.
+     */
+    public boolean isEmpty() {
+        return !hasCombinedProperties() && !hasDefaultProperties() && !hasSections();
     }
 
     @Override
     public String toString() {
         return "ConfigurationData{" +
                 "format=" + format +
-                ", data=" + data +
+                ", default properties=" + defaultProperties +
+                ", combined properties=" + combinedProperties +
+                ", sections=" + namedSections +
                 ", resource=" + resource +
                 '}';
     }
 
-    /**
-     * Accessor used for easily creating a new builder based on a given data instance.
-     * @return the data contained, never null.
-     */
-    Map<String,Map<String,String>> getData() {
-        return data;
-    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java
index d0c3675..45645e0 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java
@@ -18,9 +18,7 @@
  */
 package org.apache.tamaya.format;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 
 /**
@@ -32,8 +30,18 @@ public final class ConfigurationDataBuilder {
     ConfigurationFormat format;
     /** The resource read. */
     String resource;
-    /** The data read. */
-    Map<String,Map<String,String>> data = new HashMap<>();
+    /**
+     * The properties of the default section (no name).
+     */
+    Map<String, String> defaultProperties;
+    /**
+     * A normalized flattened set of this configuration data.
+     */
+    Map<String, String> combinedProperties;
+    /**
+     * The sections read.
+     */
+    Map<String, Map<String, String>> namedSections;
 
     /**
      * Private constructor.
@@ -60,7 +68,15 @@ public final class ConfigurationDataBuilder {
      */
     public static ConfigurationDataBuilder of(ConfigurationData data){
         ConfigurationDataBuilder b = new ConfigurationDataBuilder(data.getResource(), data.getFormat());
-        b.data.putAll(data.getData());
+        if (data.hasDefaultProperties()) {
+            b.getDefaultProperties().putAll(data.getDefaultProperties());
+        }
+        if (data.hasCombinedProperties()) {
+            b.getCombinedProperties().putAll(data.getCombinedProperties());
+        }
+        if (data.hasSections()) {
+            b.getSections().putAll(data.getSections());
+        }
         return b;
     }
 
@@ -70,8 +86,8 @@ public final class ConfigurationDataBuilder {
      * @return the builder for chaining.
      */
     public ConfigurationDataBuilder addSections(String... sections){
-        for(String section:sections) {
-            this.data.computeIfAbsent(section, (k) -> new HashMap<>());
+        for (String section : sections) {
+            getSections().computeIfAbsent(section, (k) -> new HashMap<>());
         }
         return this;
     }
@@ -83,8 +99,8 @@ public final class ConfigurationDataBuilder {
      * @param value the entry's value
      * @return the builder for chaining.
      */
-    public ConfigurationDataBuilder addProperty(String section, String key, String value){
-        Map<String,String> map = this.data.computeIfAbsent(section, (k) -> new HashMap<>());
+    public ConfigurationDataBuilder addSectionProperty(String section, String key, String value) {
+        Map<String, String> map = getSections().computeIfAbsent(section, (k) -> new HashMap<>());
         map.put(key, value);
         return this;
     }
@@ -95,8 +111,9 @@ public final class ConfigurationDataBuilder {
      * @param value the entry's value
      * @return the builder for chaining.
      */
-    public ConfigurationDataBuilder addProperty(String key, String value){
-        return addProperty(ConfigurationData.DEFAULT_SECTION_NAME, key, value);
+    public ConfigurationDataBuilder addProperty(String key, String value) {
+        getDefaultProperties().put(key, value);
+        return this;
     }
 
     /**
@@ -105,8 +122,8 @@ public final class ConfigurationDataBuilder {
      * @param properties the entry's data
      * @return the builder for chaining.
      */
-    public ConfigurationDataBuilder addProperties(String section, Map<String,String> properties){
-        Map<String,String> map = this.data.computeIfAbsent(section, (k) -> new HashMap<>());
+    public ConfigurationDataBuilder addSectionProperties(String section, Map<String, String> properties) {
+        Map<String, String> map = getSections().computeIfAbsent(section, (k) -> new HashMap<>());
         map.putAll(properties);
         return this;
     }
@@ -116,8 +133,57 @@ public final class ConfigurationDataBuilder {
      * @param properties the entry's data
      * @return the builder for chaining.
      */
-    public ConfigurationDataBuilder addProperties( Map<String,String> properties){
-        return addProperties(ConfigurationData.DEFAULT_SECTION_NAME, properties);
+    public ConfigurationDataBuilder addProperties(Map<String, String> properties) {
+        getDefaultProperties().putAll(properties);
+        return this;
+    }
+
+    /**
+     * Sets the given entries as the <i>combined</i> properties map, all existing properties of the
+     * combined map will be overridden.
+     *
+     * @param properties the entry's data
+     * @return the builder for chaining.
+     */
+    public ConfigurationDataBuilder setCombinedProperties(Map<String, String> properties) {
+        this.combinedProperties = new HashMap<>(properties);
+        return this;
+    }
+
+    /**
+     * Access the current default section, if not present a new instance is initialized.
+     *
+     * @return the current default section, never null.
+     */
+    public Map<String, String> getDefaultProperties() {
+        if (defaultProperties == null) {
+            defaultProperties = new HashMap<>();
+        }
+        return defaultProperties;
+    }
+
+    /**
+     * Access the current combined properties, if not present a new instance is initialized.
+     *
+     * @return the current combined properties, never null.
+     */
+    public Map<String, String> getCombinedProperties() {
+        if (combinedProperties == null) {
+            combinedProperties = new HashMap<>();
+        }
+        return combinedProperties;
+    }
+
+    /**
+     * Access the current named sections, if not present a new instance is initialized.
+     *
+     * @return the current named sections, never null.
+     */
+    public Map<String, Map<String, String>> getSections() {
+        if (namedSections == null) {
+            namedSections = new HashMap<>();
+        }
+        return namedSections;
     }
 
     /**
@@ -132,7 +198,9 @@ public final class ConfigurationDataBuilder {
     public String toString() {
         return "ConfigurationDataBuilder{" +
                 "format=" + format +
-                ", data=" + data +
+                ", default properties=" + defaultProperties +
+                ", sections=" + namedSections +
+                ", combined properties=" + combinedProperties +
                 ", resource=" + resource +
                 '}';
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java
index dc3f588..ab06da1 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java
@@ -39,9 +39,9 @@ public interface ConfigurationFormat {
 
     /**
      * Get a unique name of the format. This name can be used to access the format.
-     * @return
+     * @return the (unique) format's name, never null and not empty.
      */
-    public String getName();
+    String getName();
 
     /**
      * Allows the format to examine the given resource, e.g. for a matching file ending. Only, if a format accepts an
@@ -61,9 +61,9 @@ public interface ConfigurationFormat {
      *     hierarchies. This is the case for properties and xml properties.</li>
      *     <li>Hierarchical formats such as INI, XML and JSON can map each node to a section. Each section
      *     can have its own key/value pairs. This allows to map also complex formats in a generic way. A
-     *     format implementation should then additionally flatten the whole data and store it in a section
-     *     identified by {@link ConfigurationData#FLATTENED_SECTION_NAME}. This allows to use the flattened
-     *     section as inout to a default mapping, which is always appropriate as long as no other semnatics
+     *     format implementation should then additionally flatten the whole data and store it in a accessible as
+     *     {@link ConfigurationData#getCombinedProperties()}. This allows to use the properties as inout to a default mapping,
+     *     which is always appropriate as long as no other semnatics
      *     are defined in the concrete target scenario.</li>
      *     <li>More complex custom scenarios should map their configuration data read into different
      *     sections. Typically the data will be mapped into different {@link org.apache.tamaya.spi.PropertySource}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
index 3605f99..d2c0e79 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
@@ -69,7 +69,7 @@ public final class ConfigurationFormats {
      */
     public static List<ConfigurationFormat> getFormats(String... formatNames) {
         Set<String> names = new HashSet<>(Arrays.asList(formatNames));
-        return getFormats(f -> names.contains(f));
+        return getFormats(names::contains);
     }
 
     /**
@@ -152,25 +152,10 @@ public final class ConfigurationFormats {
                                                           ConfigurationFormat... formats) throws IOException {
         Objects.requireNonNull(inputStream);
         Objects.requireNonNull(resource);
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        byte[] bytes = new byte[256];
-        try {
-            int read = inputStream.read(bytes);
-            while (read > 0) {
-                bos.write(bytes, 0, read);
-                read = inputStream.read(bytes);
-            }
-        } finally {
-            try {
-                inputStream.close();
-            } catch (IOException e) {
-                LOG.log(Level.FINEST, e, () -> "Error closing stream: " + inputStream);
-            }
-        }
-        ConfigurationData data;
+        InputStreamFactory isFactory = new InputStreamFactory(inputStream);
         for (ConfigurationFormat format : formats) {
-            try (ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray())) {
-                data = format.readConfiguration(resource, bis);
+            try (InputStream is = isFactory.createInputStream()) {
+                ConfigurationData data = format.readConfiguration(resource, is);
                 if (data != null) {
                     return data;
                 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java b/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
index 619f559..7735b81 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
@@ -56,16 +56,16 @@ public class FlattenedDefaultPropertySource implements PropertySource {
         this.defaultOrdinal = defaultOrdinal;
     }
 
-    private Map<String, String> populateData(ConfigurationData data) {
-        Map<String, String> result = data.getSection(ConfigurationData.FLATTENED_SECTION_NAME);
-        if (result == null) {
-            result = data.getDefaultSection();
+    protected Map<String, String> populateData(ConfigurationData data) {
+        Map<String, String> result = data.getCombinedProperties();
+        if (result.isEmpty()) {
+            result = data.getDefaultProperties();
         }
-        if (result == null) {
+        if (result.isEmpty()) {
             result = new HashMap<>();
         }
         if(result.isEmpty()){
-            for(String section:data.getSections()){
+            for (String section : data.getSectionNames()) {
                 Map<String,String> sectionMap = data.getSection(section);
                 for(Map.Entry<String,String> en: sectionMap.entrySet()){
                     result.put(section + '.' + en.getKey(), en.getValue());

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamCloser.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamCloser.java b/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamCloser.java
deleted file mode 100644
index 70056e6..0000000
--- a/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamCloser.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.format;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Objects;
-
-/**
- * Wrapper for a given {@link InputStream} to be able to close
- * it via the try-with-resources construct of Java 7.
- *
- * <h1>Usage example</h1>
- *
- * <pre>
- *public void readIt(InputStream inputStream) {
- *    try (InputStream is = new InputStreamCloser(inputStream) {
- *        // Consume the stream
- *    }
- *}
- * </pre>
- */
-public class InputStreamCloser extends InputStream {
-    private InputStream wrapped;
-
-    public InputStreamCloser(InputStream original) {
-        Objects.requireNonNull(original);
-
-        wrapped = original;
-    }
-
-
-    @Override
-    public int read(byte[] b) throws IOException {
-        return wrapped.read(b);
-    }
-
-    @Override
-    public int read(byte[] b, int off, int len) throws IOException {
-        return wrapped.read(b, off, len);
-    }
-
-    @Override
-    public long skip(long n) throws IOException {
-        return wrapped.skip(n);
-    }
-
-    @Override
-    public int available() throws IOException {
-        return wrapped.available();
-    }
-
-    @Override
-    public void close() throws IOException {
-        wrapped.close();
-    }
-
-    @Override
-    public synchronized void mark(int readlimit) {
-        wrapped.mark(readlimit);
-    }
-
-    @Override
-    public synchronized void reset() throws IOException {
-        wrapped.reset();
-    }
-
-    @Override
-    public boolean markSupported() {
-        return wrapped.markSupported();
-    }
-
-    @Override
-    public int read() throws IOException {
-        return wrapped.read();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamFactory.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamFactory.java b/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamFactory.java
new file mode 100644
index 0000000..255f0cc
--- /dev/null
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamFactory.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.format;
+
+import java.io.*;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Wrapper for a given {@link InputStream} to be able to close
+ * it via the try-with-resources construct of Java 7.
+ * <p>
+ * <h1>Usage example</h1>
+ * <p>
+ * <pre>
+ * public void readIt(InputStream inputStream) {
+ *    try (InputStream is = new ParallelInputStream(inputStream) {
+ *        // Consume the stream
+ *    }
+ * }
+ * </pre>
+ */
+public class InputStreamFactory implements Closeable {
+    private static final Logger LOG = Logger.getLogger(InputStreamFactory.class.getName());
+
+    private byte[] data;
+
+    /**
+     * Creates a bew InputStreamFactory.
+     *
+     * @param original the InputStream to be read for extract its data into memory.
+     * @throws IOException if thrown by the original during read.
+     */
+    public InputStreamFactory(InputStream original) throws IOException {
+        Objects.requireNonNull(original);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        byte[] bytes = new byte[256];
+        try {
+            int read = original.read(bytes);
+            while (read > 0) {
+                bos.write(bytes, 0, read);
+                read = original.read(bytes);
+            }
+            this.data = bos.toByteArray();
+        } finally {
+            try {
+                original.close();
+            } catch (IOException e) {
+                LOG.log(Level.FINEST, e, () -> "Error closing stream: " + original);
+            }
+        }
+    }
+
+    /**
+     * Creates a new InputStream with the same data as provided by the InputStream passed on factory creation.
+     *
+     * @return a new InputStream , never null.
+     */
+    public InputStream createInputStream() throws IOException {
+        byte[] bytes = this.data;
+        if (bytes == null) {
+            throw new IOException("InputStreamFactory is closed.");
+        }
+        return new ByteArrayInputStream(bytes);
+    }
+
+    @Override
+    public void close() throws IOException {
+        this.data = null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java
index f49f27a..4b4c75b 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java
@@ -79,8 +79,7 @@ public class IniConfigurationFormat implements ConfigurationFormat {
                     String key = line.substring(0, sep);
                     String value = line.substring(sep + 1);
                     if (section != null) {
-                        builder.addProperty(ConfigurationData.FLATTENED_SECTION_NAME, section + '.' + key, value);
-                        builder.addProperty(section, key, value);
+                        builder.addSectionProperty(section, key, value);
                     } else {
                         builder.addProperty(key, value);
                     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/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 9d804d6..d69f623 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,7 +21,6 @@ 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.InputStream;
 import java.net.URL;
@@ -60,15 +59,13 @@ public class PropertiesFormat implements ConfigurationFormat {
     public ConfigurationData readConfiguration(String resource, InputStream inputStream) {
         Objects.requireNonNull(inputStream);
         Objects.requireNonNull(resource);
-
-        try (InputStream in = new InputStreamCloser(inputStream)) {
+        try {
             final Properties p = new Properties();
-            p.load(in);
+            p.load(inputStream);
             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);
         }
-
         return null;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/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 50cb966..44731d8 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,7 +21,6 @@ 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.InputStream;
 import java.net.URL;
@@ -58,14 +57,13 @@ public class PropertiesXmlFormat implements ConfigurationFormat {
         Objects.requireNonNull(inputStream);
         Objects.requireNonNull(resource);
 
-        try (InputStream in = new InputStreamCloser(inputStream)) {
+        try {
             final Properties p = new Properties();
-            p.loadFromXML(in);
+            p.loadFromXML(inputStream);
             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);
         }
-
         return null;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/formats/src/test/java/org/apache/tamaya/format/ConfigurationFormatsTest.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/test/java/org/apache/tamaya/format/ConfigurationFormatsTest.java b/modules/formats/src/test/java/org/apache/tamaya/format/ConfigurationFormatsTest.java
index 273439b..0839714 100644
--- a/modules/formats/src/test/java/org/apache/tamaya/format/ConfigurationFormatsTest.java
+++ b/modules/formats/src/test/java/org/apache/tamaya/format/ConfigurationFormatsTest.java
@@ -55,8 +55,6 @@ public class ConfigurationFormatsTest {
         assertNotNull(data);
         data = ConfigurationFormats.readConfigurationData(getClass().getResource("/Test.properties"));
         assertNotNull(data);
-//        data = ConfigurationFormats.readConfigurationData(getClass().getResource("/Test.xml"));
-//        assertNotNull(data);
     }
 
     @org.junit.Test

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/formats/src/test/java/org/apache/tamaya/format/FlattenedDefaultPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/test/java/org/apache/tamaya/format/FlattenedDefaultPropertySourceTest.java b/modules/formats/src/test/java/org/apache/tamaya/format/FlattenedDefaultPropertySourceTest.java
index c39de4e..b53d367 100644
--- a/modules/formats/src/test/java/org/apache/tamaya/format/FlattenedDefaultPropertySourceTest.java
+++ b/modules/formats/src/test/java/org/apache/tamaya/format/FlattenedDefaultPropertySourceTest.java
@@ -39,23 +39,23 @@ public class FlattenedDefaultPropertySourceTest {
 
     private ConfigurationData createConfigurationData(String sourceName) {
         return ConfigurationDataBuilder.of(sourceName, new PropertiesFormat())
-                .addProperty("a", "aValue").addProperty("section1", "sectionKey1", "sectionValue11")
+                .addProperty("a", "aValue").addSectionProperty("section1", "sectionKey1", "sectionValue11")
                 .addSections("section1", "section12")
-                .addProperty("section2", "sectionKey1", "sectionValue21").build();
+                .addSectionProperty("section2", "sectionKey1", "sectionValue21").build();
     }
 
     private ConfigurationData createConfigurationData(String sourceName, int ordinal) {
         return ConfigurationDataBuilder.of(sourceName, new PropertiesFormat())
-                .addProperty("a", "aValue").addProperty("section1", "sectionKey1", "sectionValue11")
+                .addProperty("a", "aValue").addSectionProperty("section1", "sectionKey1", "sectionValue11")
                 .addSections("section1", "section12").addProperty(PropertySource.TAMAYA_ORDINAL, String.valueOf(ordinal))
-                .addProperty("section2", "sectionKey1", "sectionValue21").build();
+                .addSectionProperty("section2", "sectionKey1", "sectionValue21").build();
     }
 
     private ConfigurationData createConfigurationDataNoDefault(String sourceName) {
         return ConfigurationDataBuilder.of(sourceName, new PropertiesFormat())
-                .addProperty("section1", "sectionKey1", "sectionValue11")
+                .addSectionProperty("section1", "sectionKey1", "sectionValue11")
                 .addSections("section1", "section12")
-                .addProperty("section2", "sectionKey1", "sectionValue21").build();
+                .addSectionProperty("section2", "sectionKey1", "sectionValue21").build();
     }
 
     @Test
@@ -68,8 +68,10 @@ public class FlattenedDefaultPropertySourceTest {
     public void testGet() throws Exception {
         FlattenedDefaultPropertySource ps = new FlattenedDefaultPropertySource(createConfigurationData("test2"));
         assertEquals("aValue", ps.get("a"));
-        assertNull(ps.get("section1.sectionKey1"));
-        assertNull(ps.get("section2.sectionKey1"));
+        assertNotNull(ps.get("section1.sectionKey1"));
+        assertNotNull(ps.get("section2.sectionKey1"));
+        assertNull(ps.get("sectionKey1"));
+        assertNull(ps.get("sectionKey1"));
         ps = new FlattenedDefaultPropertySource(createConfigurationDataNoDefault("test2"));
         assertEquals("sectionValue11", ps.get("section1.sectionKey1"));
         assertEquals("sectionValue21", ps.get("section2.sectionKey1"));
@@ -82,8 +84,12 @@ public class FlattenedDefaultPropertySourceTest {
         FlattenedDefaultPropertySource ps = new FlattenedDefaultPropertySource(createConfigurationData("test3"));
         assertNotNull(ps.getProperties());
         assertEquals("aValue", ps.getProperties().get("a"));
-        assertNull(ps.getProperties().get("section1.sectionKey1"));
-        assertNull(ps.getProperties().get("section2.sectionKey1"));
+        assertNotNull(ps.getProperties().get("section1.sectionKey1"));
+        assertNotNull(ps.getProperties().get("section2.sectionKey1"));
+        assertNull(ps.getProperties().get("section1.sectionKey2"));
+        assertNull(ps.getProperties().get("section2.sectionKey2"));
+        assertNull(ps.getProperties().get("sectionKey1"));
+        assertNull(ps.getProperties().get("sectionKey2"));
         ps = new FlattenedDefaultPropertySource(createConfigurationDataNoDefault("test3"));
         assertNotNull(ps.getProperties());
         assertEquals("sectionValue11", ps.getProperties().get("section1.sectionKey1"));

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/formats/src/test/java/org/apache/tamaya/format/InputStreamCloserTest.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/test/java/org/apache/tamaya/format/InputStreamCloserTest.java b/modules/formats/src/test/java/org/apache/tamaya/format/InputStreamCloserTest.java
deleted file mode 100644
index 574573a..0000000
--- a/modules/formats/src/test/java/org/apache/tamaya/format/InputStreamCloserTest.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.format;
-
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mockito;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-public class InputStreamCloserTest {
-
-    @Test(expected = NullPointerException.class)
-    public void ctorEnforcesNonNullOriginal() {
-        new InputStreamCloser(null);
-    }
-
-    @Test
-    public void givenStreamIsClosedInTryWithResourcesConstruct() throws Exception {
-        InputStream stream = mock(InputStream.class);
-
-        doReturn(34).when(stream).read();
-
-        try (InputStream in = new InputStreamCloser(stream)) {
-            in.read();
-        }
-
-        verify(stream).close();
-    }
-
-    @Test
-    public void callToReadIsForwardedCallToWrapped() throws IOException {
-        InputStream stream = mock(InputStream.class);
-
-        doReturn(34).when(stream).read(Mockito.anyVararg());
-
-        InputStreamCloser closer = new InputStreamCloser(stream);
-
-        byte[] byteArray = new byte[4];
-        assertThat(closer.read(byteArray), equalTo(34));
-
-        verify(stream).read(byteArray);
-    }
-
-
-    @Test
-    public void callToReadWithOffsetIsForwardedCallToWrapped() throws IOException {
-        byte[] array = new byte[10];
-        ArgumentCaptor<byte[]> arrayCaptor = ArgumentCaptor.forClass(byte[].class);
-        ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
-        ArgumentCaptor<Integer> lengthCaptor = ArgumentCaptor.forClass(Integer.class);
-        InputStream stream = mock(InputStream.class);
-
-        doReturn(23).when(stream).read(Mockito.anyVararg(), Mockito.anyInt(), Mockito.anyInt());
-
-        InputStreamCloser closer = new InputStreamCloser(stream);
-
-        assertThat(closer.read(array, 10, 20), equalTo(23));
-
-        verify(stream).read(arrayCaptor.capture(), offsetCaptor.capture(), lengthCaptor.capture());
-
-        assertThat(offsetCaptor.getValue(), equalTo(10));
-        assertThat(lengthCaptor.getValue(), equalTo(20));
-        assertThat(arrayCaptor.getValue(), equalTo(array));
-    }
-
-    @Test
-    public void callToSkipIsForwardedToWrapped() throws IOException {
-        ArgumentCaptor<Long> captor = ArgumentCaptor.forClass(Long.class);
-        InputStream stream = mock(InputStream.class);
-
-        doReturn(1234L).when(stream).skip(anyLong());
-
-        InputStreamCloser closer = new InputStreamCloser(stream);
-
-        assertThat(closer.skip(4567L), equalTo(1234L));
-
-        verify(stream).skip(captor.capture());
-
-        assertThat(captor.getValue(), equalTo(4567L));
-    }
-
-
-    @Test
-    public void callToAvailableIsForwardedToWrapped() throws IOException {
-        InputStream stream = mock(InputStream.class);
-
-        doReturn(123).when(stream).available();
-
-        InputStreamCloser closer = new InputStreamCloser(stream);
-
-        assertThat(closer.available(), equalTo(123));
-
-        verify(stream).available();
-    }
-
-    @Test
-    public void callToCloseIsForwardedToWrapped() throws IOException {
-        InputStream stream = mock(InputStream.class);
-        InputStreamCloser closer = new InputStreamCloser(stream);
-
-        closer.close();
-
-        verify(stream).close();
-    }
-
-    @Test
-    public void callToMarkIsForwardedToWrapped() {
-        ArgumentCaptor<Integer> captor = ArgumentCaptor.forClass(Integer.class);
-        InputStream stream = mock(InputStream.class);
-        InputStreamCloser closer = new InputStreamCloser(stream);
-
-        closer.mark(456);
-
-        verify(stream).mark(captor.capture());
-
-        assertThat(captor.getValue(), equalTo(456));
-    }
-
-
-    @Test
-    public void callToResetIsForwardedToWrapped() throws IOException {
-        InputStream stream = mock(InputStream.class);
-
-        InputStreamCloser closer = new InputStreamCloser(stream);
-
-        closer.reset();
-
-        verify(stream).reset();
-    }
-
-    @Test
-    public void callToMarkSupportedIsForwardedToWrapped() {
-        InputStream stream = mock(InputStream.class);
-
-        doReturn(false).when(stream).markSupported();
-
-        InputStreamCloser closer = new InputStreamCloser(stream);
-
-        assertThat(closer.markSupported(), is(false));
-
-        verify(stream).markSupported();
-    }
-
-    @Test
-    public void callToReadIsForwardedToWrapped() throws IOException {
-        InputStream stream = mock(InputStream.class);
-        InputStreamCloser closer = new InputStreamCloser(stream);
-
-        doReturn(4).when(stream).read();
-
-        assertThat(closer.read(), equalTo(4));
-
-        verify(stream).read();
-    }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/formats/src/test/java/org/apache/tamaya/format/InputStreamFactoryTest.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/test/java/org/apache/tamaya/format/InputStreamFactoryTest.java b/modules/formats/src/test/java/org/apache/tamaya/format/InputStreamFactoryTest.java
new file mode 100644
index 0000000..4505dd9
--- /dev/null
+++ b/modules/formats/src/test/java/org/apache/tamaya/format/InputStreamFactoryTest.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.format;
+
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class InputStreamFactoryTest {
+
+    @Test(expected = NullPointerException.class)
+    public void ctorEnforcesNonNullOriginal() throws IOException {
+        new InputStreamFactory(null);
+    }
+
+    @Test
+    public void givenStreamIsClosedInTryWithResourcesConstruct() throws Exception {
+        InputStream stream = mock(InputStream.class);
+        doReturn(34).when(stream).read();
+
+        InputStreamFactory factory = new InputStreamFactory(stream);
+        verify(stream).close();
+        for (int i = 0; i < 100; i++) {
+            try (InputStream in = factory.createInputStream()) {
+                in.read();
+            }
+        }
+        verify(stream).close();
+    }
+
+    @Test
+    public void callToReadIsNotForwardedCallToWrapped() throws IOException {
+        InputStream stream = new ByteArrayInputStream(new byte[]{1, 2, 3, 4});
+        InputStreamFactory closer = new InputStreamFactory(stream);
+        byte[] byteArray = new byte[4];
+        for (int i = 0; i < 100; i++) {
+            InputStream is = closer.createInputStream();
+            assertThat(is.read(byteArray), equalTo(4));
+        }
+    }
+
+
+    @Test
+    public void callToSkipIsForwardedToWrapped() throws IOException {
+        InputStream stream = new ByteArrayInputStream(new byte[]{1, 2, 3, 4});
+        InputStreamFactory closer = new InputStreamFactory(stream);
+        for (int i = 0; i < 100; i++) {
+            InputStream is = closer.createInputStream();
+            assertThat(is.skip(2L), equalTo(2L));
+        }
+    }
+
+
+    @Test
+    public void callToAvailableIsNotForwardedToWrapped() throws IOException {
+        InputStream stream = new ByteArrayInputStream(new byte[]{1, 2, 3, 4});
+        InputStreamFactory closer = new InputStreamFactory(stream);
+        for (int i = 0; i < 100; i++) {
+            InputStream is = closer.createInputStream();
+            assertThat(is.available(), equalTo(4));
+        }
+    }
+
+    @Test
+    public void callToCloseIsNotForwardedToWrapped() throws IOException {
+        InputStream stream = new ByteArrayInputStream(new byte[]{1, 2, 3, 4});
+        InputStreamFactory closer = new InputStreamFactory(stream);
+        for (int i = 0; i < 100; i++) {
+            InputStream is = closer.createInputStream();
+            is.close();
+        }
+    }
+
+    @Test
+    public void callToMarkIsNotForwardedToWrapped() throws IOException {
+        ArgumentCaptor<Integer> captor = ArgumentCaptor.forClass(Integer.class);
+        InputStream stream = new ByteArrayInputStream(new byte[]{1, 2, 3, 4});
+        InputStreamFactory closer = new InputStreamFactory(stream);
+        for (int i = 0; i < 100; i++) {
+            InputStream is = closer.createInputStream();
+            is.mark(2);
+        }
+    }
+
+
+    @Test
+    public void callToResetIsNotForwardedToWrapped() throws IOException {
+        InputStream stream = new ByteArrayInputStream(new byte[]{1, 2, 3, 4});
+        InputStreamFactory closer = new InputStreamFactory(stream);
+        for (int i = 0; i < 100; i++) {
+            InputStream is = closer.createInputStream();
+            is.reset();
+        }
+    }
+
+    @Test
+    public void callToMarkSupportedIsNotForwardedToWrapped() throws IOException {
+        InputStream stream = new ByteArrayInputStream(new byte[]{1, 2, 3, 4});
+        InputStreamFactory closer = new InputStreamFactory(stream);
+        for (int i = 0; i < 100; i++) {
+            InputStream is = closer.createInputStream();
+            assertThat(is.markSupported(), is(true));
+        }
+    }
+
+    @Test
+    public void callToReadIsForwardedToWrapped() throws IOException {
+        InputStream stream = new ByteArrayInputStream(new byte[]{1, 2, 3, 4});
+        InputStreamFactory closer = new InputStreamFactory(stream);
+        for (int i = 0; i < 100; i++) {
+            InputStream is = closer.createInputStream();
+            assertThat(is.read(), equalTo(1));
+            assertThat(is.read(), equalTo(2));
+            assertThat(is.read(), equalTo(3));
+            assertThat(is.read(), equalTo(4));
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/modules/json/src/main/java/org/apache/tamaya/json/JSONFormat.java
----------------------------------------------------------------------
diff --git a/modules/json/src/main/java/org/apache/tamaya/json/JSONFormat.java b/modules/json/src/main/java/org/apache/tamaya/json/JSONFormat.java
index 06a5f93..cdacf41 100644
--- a/modules/json/src/main/java/org/apache/tamaya/json/JSONFormat.java
+++ b/modules/json/src/main/java/org/apache/tamaya/json/JSONFormat.java
@@ -25,7 +25,6 @@ import org.apache.tamaya.ConfigException;
 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;
@@ -54,10 +53,9 @@ public class JSONFormat implements ConfigurationFormat {
     @Override
     public ConfigurationData readConfiguration(String resource, InputStream inputStream) {
 
-        try (InputStream is = new InputStreamCloser(inputStream)){
+        try {
             ObjectMapper mapper = new ObjectMapper();
-            JsonNode root = mapper.readTree(is);
-
+            JsonNode root = mapper.readTree(inputStream);
             HashMap<String, String> values = new HashMap<>();
             JSONVisitor visitor = new JSONVisitor((ObjectNode) root, values);
             visitor.run();

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/sandbox/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java
----------------------------------------------------------------------
diff --git a/sandbox/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java b/sandbox/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java
index b991690..db013ac 100644
--- a/sandbox/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java
+++ b/sandbox/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java
@@ -16,10 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.tamaya.se;
+package org.apache.tamaya.management;
 
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.AggregationPolicy;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
 
 import java.util.Map;
 import java.util.Set;
@@ -29,67 +30,33 @@ import java.util.Set;
  */
 public class ManagedConfig implements ManagedConfigMBean{
     @Override
-    public Set<String> getConfigurationNames() {
-        return null;
-    }
-
-    @Override
-    public String getConfigurationInfo(String configName) {
-        return null;
-    }
-
-    @Override
-    public boolean isConfigurationAvailable(String configName, String envType, String context) {
-        return false;
-    }
-
-    @Override
-    public boolean isConfigurationLoaded(String configName, String envType, String context) {
-        return false;
-    }
-
-    @Override
-    public Map<String, String> getConfiguration(String configName, String envType, String context) throws ConfigException {
+    public String getConfigurationInfo() {
         return null;
     }
 
     @Override
-    public Map<String, String> getRecursiveConfigValues(String area, String configName, String envType, String context) throws ConfigException {
-        return null;
+    public Map<String, String> getConfiguration() {
+        return ConfigurationProvider.getConfiguration().getProperties();
     }
 
     @Override
-    public Map<String, String> getConfigValues(String area, String configName, String envType, String context) throws ConfigException {
-        return null;
+    public Map<String, String> getConfigurationArea(String area, boolean recursive) {
+        return ConfigurationProvider.getConfiguration().with(ConfiguationFunctions.getArea(area, recursive);
     }
 
     @Override
-    public Map<String, String> updateConfiguration(String configName, String envType, String context, Map<String, String> values, AggregationPolicy aggregationPolicy) throws ConfigException {
-        return null;
+    public Set<String> getAreas() {
+        return ConfigurationProvider.getConfiguration().with(ConfiguationFunctions.getAreas();
     }
 
     @Override
-    public String getConfigurationInfo(String configName, String envType, String context) {
-        return null;
+    public Set<String> getTransitiveAreas() {
+        return ConfigurationProvider.getConfiguration().with(ConfiguationFunctions.getTransitiveAreas();
     }
 
     @Override
-    public Set<String> getAreas(String configName, String envType, String context) {
-        return null;
-    }
-
-    @Override
-    public Set<String> getTransitiveAreas(String configName, String envType, String context) {
-        return null;
-    }
-
-    @Override
-    public boolean isAreaExisting(String area, String configName, String envType, String context) {
-        return false;
-    }
-
-    @Override
-    public boolean isAreaEmpty(String area, String configName, String envType, String context) {
+    public boolean isAreaExisting(String area) {
         return false;
     }
 }
+

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/96a550b2/sandbox/management/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java
----------------------------------------------------------------------
diff --git a/sandbox/management/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java b/sandbox/management/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java
index c2ade13..94ec3ea 100644
--- a/sandbox/management/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java
+++ b/sandbox/management/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java
@@ -16,11 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.tamaya.se;
-
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.AggregationPolicy;
+package org.apache.tamaya.management;
 
 import java.util.Map;
 import java.util.Set;
@@ -29,148 +25,73 @@ import java.util.Set;
  * Managed bean interface for accessing environment data.
  */
 public interface ManagedConfigMBean {
-    /**
-     * Get the names current the configuration's defined.
-     *
-     * @return the names current the configuration's defined.
-     */
-    public Set<String> getConfigurationNames();
 
     /**
-     * Get a general configuration info descriptor in JSON format for a configuration
-     * type in the following form:
+     * Get a general description of the configuration (context) in place, in JSON format:
      * <pre>
-     *     tbd
+     *     ConfigurationContext[gqContextClassName] {
+     *         version = 2345-34334-2333-3434,
+     *         config {
+     *             key = "value",
+     *             key2 = "value2"
+     *             ...
+     *         },
+     *         filters = [...],
+     *         converters{...},
+     *         property-sources{...}
+     *     }
      * </pre>
      *
-     * @param configName the configuration name, not null.
      * @return a JSON formatted meta-information.
      */
-    public String getConfigurationInfo(String configName);
+    String getConfigurationInfo();
 
-    /**
-     * Allows to determine if a configuration current a given type is available (accessible) in the
-     * given environment context.
-     *
-     * @param configName the configuration name, not null.
-     * @param envType        the environment context, not null.
-     * @param envContext        the environment context, not null.
-     * @return true, if such a configuration is accessible.
-     */
-    public boolean isConfigurationAvailable(String configName, String envType, String envContext);
-
-    /**
-     * Allows to determine if a configuration current a given type is loaded in the
-     * given environment context.
-     *
-     * @param configName the configuration name, not null.
-     * @param envType        the environment context, not null.
-     * @param envContext        the environment context, not null.
-     * @return true, if such a configuration is accessible.
-     */
-    public boolean isConfigurationLoaded(String configName, String envType, String envContext);
 
     /**
      * Accesses a configuration current a given type as Map.
      *
-     * @param configName the configuration name, not null.
-     * @param envType        the environment context, not null.
-     * @param envContext        the environment context, not null.
-     * @return true, if such a configuration is accessible.
-     * @throws org.apache.tamaya.ConfigException If the configuration is not yet loaded.
+     * @return the current configuration map.
+     * @throws org.apache.tamaya.ConfigException If the configuration is not available.
      */
-    public Map<String, String> getConfiguration(String configName, String envType, String envContext)
-            throws ConfigException;
+    Map<String, String> getConfiguration();
 
     /**
      * Accesses a configuration values for current a given config area as Map.
      * @param area the target area key, not null.
-     * @param configName the configuration name, not null.
-     * @param envType        the environment context, not null.
-     * @param envContext        the environment context, not null.
+     * @param recursive if set to false only direct child keys of the given area are returned.
      * @return the key/values found, including the recursive child values.
      * @throws org.apache.tamaya.ConfigException If the configuration is not yet loaded.
      */
-    public Map<String, String> getRecursiveConfigValues(String area, String configName, String envType, String envContext)
-            throws ConfigException;
-
-    /**
-     * Accesses a configuration values for current a given config area as Map.
-     * @param area the target area key, not null.
-     * @param configName the configuration name, not null.
-     * @param envType        the environment context, not null.
-     * @param envContext        the environment context, not null.
-     * @return the key/values found, not transitive.
-     * @throws org.apache.tamaya.ConfigException If the configuration is not yet loaded.
-     */
-    public Map<String, String> getConfigValues(String area, String configName, String envType, String envContext)
-            throws ConfigException;
-
-    /**
-     * Updates a configuration current a given type.
-     *
-     * @param configName        the configuration name, not null.
-     * @param envType        the environment context, not null.
-     * @param envContext        the environment context, not null.
-     * @param values            the values to be changed.
-     * @param aggregationPolicy the aggregation Policy to be used.
-     * @return the configuration after the changesd have been applied.
-     * @throws org.apache.tamaya.ConfigException If the configuration is not yet loaded, or not
-     *                                           mutable.
-     */
-    public Map<String, String> updateConfiguration(String configName, String envType, String envContext, Map<String, String> values, AggregationPolicy aggregationPolicy)
-            throws ConfigException;
-
-    /**
-     * Access a JSON formatted info on a configuration loaded in the form as
-     * <pre>
-     *     tbd
-     * </pre>
-     * @param configName        the configuration name, not null.
-     * @param envType        the environment context, not null.
-     * @param envContext        the environment context, not null.
-     * @return the JSON formatted info, never null.
-     * @throws org.apache.tamaya.ConfigException If the configuration is not yet loaded
-     */
-    public String getConfigurationInfo(String configName, String envType, String envContext);
+    Map<String, String> getConfigurationArea(String area, boolean recursive);
 
     /**
      * Access the defined areas for a given configuration.
-     * @param configName        the configuration name, not null.
-     * @param envContext        the environment context, not null.
      * @return the areas defined (only returning the areas that contain properties).
      * @throws org.apache.tamaya.ConfigException If the configuration is not yet loaded
      */
-    public Set<String> getAreas(String configName, String envType, String envContext);
+    Set<String> getAreas();
 
     /**
-     * Access the transitive areas for a given configuration.
-     * @param configName        the configuration name, not null.
-     * @param envType        the environment context, not null.
-     * @param envContext        the environment context, not null.
+     * Access the transitive areas for the current configuration.
      * @return the transitive areas defined.
      * @throws org.apache.tamaya.ConfigException If the configuration is not yet loaded
      */
-    public Set<String> getTransitiveAreas(String configName, String envType, String envContext);
+    Set<String> getTransitiveAreas();
 
     /**
      * Allows to determine if an area is existing.
      * @param area the target area key, not null.
-     * @param configName        the configuration name, not null.
-     * @param envType        the environment context, not null.
-     * @param envContext        the environment context, not null.
      * @return true, if such an area exists (the area may be empty).
      */
-    public boolean isAreaExisting(String area, String configName, String envType, String envContext);
+    boolean isAreaExisting(String area);
 
     /**
      * Allows to determine if an area is empty.
      * @param area the target area key, not null.
-     * @param configName        the configuration name, not null.
-     * @param envType        the environment context, not null.
-     * @param envContext        the environment context, not null.
      * @return true, if such an area exists and is not empty.
      */
-    public boolean isAreaEmpty(String area, String configName, String envType, String envContext);
+    default boolean isAreaEmpty(String area){
+        return getConfigurationArea(area, true).isEmpty();
+    }
 
 }
\ No newline at end of file


Mime
View raw message