diff options
Diffstat (limited to 'infra/translate-utils')
2 files changed, 15 insertions, 7 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 a26334454..d551802e4 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 @@ -40,13 +40,17 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeS import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public final class JsonUtils { + private static final Logger LOG = LoggerFactory.getLogger(JsonUtils.class); + private JsonUtils() {} /** - * Serialize normalized node root structure into provided output stream + * Serialize normalized node root structure into provided output stream. * * @throws IOException if serialized data cannot be written into provided output stream */ @@ -79,15 +83,18 @@ public final class JsonUtils { Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schemaContext.getQName())); final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(builder); - final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext); - final JsonReader reader = new JsonReader(new InputStreamReader(stream, Charsets.UTF_8)); - jsonParser.parse(reader); + try (final JsonParserStream jsonParser = JsonParserStream.create(writer, schemaContext)) { + final JsonReader reader = new JsonReader(new InputStreamReader(stream, Charsets.UTF_8)); + jsonParser.parse(reader); + } catch (IOException e) { + LOG.warn("Unable to close json parser. Ignoring exception", e); + } return builder.build(); } private static void writeChildren(final NormalizedNodeWriter nnWriter, final ContainerNode data) throws IOException { - for(final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> child : data.getValue()) { + for (final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> child : data.getValue()) { nnWriter.write(child); } } diff --git a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java index 51f999294..5d801edab 100644 --- a/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java +++ b/infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java @@ -35,7 +35,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; /** - * Transaction based WriteContext + * Transaction backed WriteContext. */ public final class TransactionWriteContext implements WriteContext { @@ -110,11 +110,12 @@ public final class TransactionWriteContext implements WriteContext { } /** - * Does not close the transactions + * Does not close the transactions. */ @Override public void close() { ctx.close(); + mappingContext.close(); beforeTx.close(); afterTx.close(); } |