You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2020/04/19 17:00:26 UTC

[felix-dev] branch master updated: FELIX-6263 : Generator must not be closed

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

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new dfd62d2  FELIX-6263 : Generator must not be closed
dfd62d2 is described below

commit dfd62d24e665689c296623252066eac9b29e2993
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Apr 19 19:00:15 2020 +0200

    FELIX-6263 : Generator must not be closed
---
 .../main/java/org/apache/felix/cm/json/ConfigurationWriter.java   | 6 ++++--
 .../org/apache/felix/cm/json/impl/ConfigurationWriterImpl.java    | 8 ++++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/cm.json/src/main/java/org/apache/felix/cm/json/ConfigurationWriter.java b/cm.json/src/main/java/org/apache/felix/cm/json/ConfigurationWriter.java
index 0128a88..491caeb 100644
--- a/cm.json/src/main/java/org/apache/felix/cm/json/ConfigurationWriter.java
+++ b/cm.json/src/main/java/org/apache/felix/cm/json/ConfigurationWriter.java
@@ -35,7 +35,7 @@ import org.osgi.annotation.versioning.ProviderType;
 public interface ConfigurationWriter {
 
     /**
-     * Write a single configuration to the provided writer. The writer is not
+     * Write a single configuration to the provided writer. The writer/generator is not
      * closed.
      *
      * @param properties The configuration
@@ -44,7 +44,7 @@ public interface ConfigurationWriter {
     void writeConfiguration(Dictionary<String, Object> properties) throws IOException;
 
     /**
-     * Write a configuration resource to the provided writer. The writer is not
+     * Write a configuration resource to the provided writer. The writer/generator is not
      * closed.
      *
      * @param resource The configuration resource
@@ -60,6 +60,7 @@ public interface ConfigurationWriter {
 
         /**
          * Build the configuration writer for the provided writer.
+         * The writer is not closed when configuration(s) are written
          *
          * @param writer The writer for the JSON
          * @return The configuration writer
@@ -68,6 +69,7 @@ public interface ConfigurationWriter {
 
         /**
          * Build the configuration writer for the provided JSON generator.
+         * The generator is not closed when configuration(s) are written
          *
          * @param generator The JSON generator
          * @return The configuration writer
diff --git a/cm.json/src/main/java/org/apache/felix/cm/json/impl/ConfigurationWriterImpl.java b/cm.json/src/main/java/org/apache/felix/cm/json/impl/ConfigurationWriterImpl.java
index f54703e..ef44ab9 100644
--- a/cm.json/src/main/java/org/apache/felix/cm/json/impl/ConfigurationWriterImpl.java
+++ b/cm.json/src/main/java/org/apache/felix/cm/json/impl/ConfigurationWriterImpl.java
@@ -41,6 +41,8 @@ public class ConfigurationWriterImpl
 
     private JsonGenerator generator;
 
+    private boolean closeGenerator;
+
     private void checkClosed() throws IOException {
         if (this.closed) {
             throw new IOException("Writer already closed");
@@ -60,12 +62,14 @@ public class ConfigurationWriterImpl
                     }
 
                 });
+        this.closeGenerator = true;
         return this;
     }
 
     @Override
     public ConfigurationWriter build(final JsonGenerator generator) {
         this.generator = generator;
+        this.closeGenerator = false;
         return this;
     }
 
@@ -73,7 +77,7 @@ public class ConfigurationWriterImpl
     public void writeConfiguration(final Dictionary<String, Object> properties) throws IOException {
         checkClosed();
         writeConfigurationInternal(properties);
-        this.generator.close();
+        if ( this.closeGenerator) this.generator.close();
     }
 
     private void writeConfigurationInternal(final Dictionary<String, Object> properties) throws IOException {
@@ -107,6 +111,6 @@ public class ConfigurationWriterImpl
             writeConfigurationInternal(entry.getValue());
         }
         generator.writeEnd();
-        this.generator.close();
+        if ( this.closeGenerator) this.generator.close();
     }
 }