summaryrefslogtreecommitdiffstats
path: root/infra/translate-utils/src/main/java/io/fd
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2017-08-10 14:39:30 +0200
committerMarek Gradzki <mgradzki@cisco.com>2017-08-14 07:01:06 +0000
commit6923420946f05308af6a073d270df41d069dd532 (patch)
treed5e233246a792d223e92253bcc19f1b9b579cc8b /infra/translate-utils/src/main/java/io/fd
parentd0688f2883b3231e743dcd53bbf2203ec4639c6e (diff)
Shutdown closing of resources
Change-Id: If57a5414153cb983138872c7a1ded7c7066b1b6d Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'infra/translate-utils/src/main/java/io/fd')
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java24
1 files changed, 14 insertions, 10 deletions
diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java
index 332bf6767..324efc24c 100644
--- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java
+++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java
@@ -19,6 +19,12 @@ package io.fd.honeycomb.translate.util;
import com.google.common.base.Charsets;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
@@ -39,9 +45,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
-import java.io.*;
-
public final class JsonUtils {
private static final Logger LOG = LoggerFactory.getLogger(JsonUtils.class);
@@ -66,6 +69,8 @@ public final class JsonUtils {
writeChildren(normalizedNodeWriter,(ContainerNode) rootData);
jsonWriter.endObject();
jsonWriter.flush();
+ normalizedNodeWriter.close();
+ jsonWriter.close();
}
/**
@@ -87,9 +92,9 @@ public final class JsonUtils {
@Nonnull final SchemaNode parentSchema) {
final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> builder =
Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schemaContext.getQName()));
- final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(builder);
- try (final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
+ try (final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(builder);
+ final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
final JsonReader reader = new JsonReader(new InputStreamReader(stream, Charsets.UTF_8));
jsonParser.parse(reader);
} catch (IOException e) {
@@ -105,9 +110,9 @@ public final class JsonUtils {
@Nonnull final YangInstanceIdentifier.NodeIdentifier nodeIdentifier) {
final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> builder =
Builders.containerBuilder().withNodeIdentifier(nodeIdentifier);
- final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(builder);
- try (final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
+ try (final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(builder);
+ final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
final JsonReader reader = new JsonReader(new InputStreamReader(stream, Charsets.UTF_8));
jsonParser.parse(reader);
} catch (IOException e) {
@@ -124,9 +129,8 @@ public final class JsonUtils {
final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders.mapEntryBuilder()
.withNodeIdentifier(nodeIdentifier);
-
- final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(mapEntryBuilder);
- try (final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
+ try (final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(mapEntryBuilder);
+ final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext, parentSchema)) {
final JsonReader reader = new JsonReader(new InputStreamReader(stream, Charsets.UTF_8));
jsonParser.parse(reader);
} catch (IOException e) {