summaryrefslogtreecommitdiffstats
path: root/infra/translate-utils
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-08-31 15:16:38 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-08-31 14:27:59 +0000
commit2cdd56d31c4514d7d7000ce7c7b6417ce53e2be2 (patch)
treeb474759ff9bdd3b0d310377e8435f0182454b779 /infra/translate-utils
parentdace04173cd4846c3cfbcf44ede9cc7081909588 (diff)
Fixing sonar issues #1
Change-Id: I4c27d0ad2fd1655db2237ae914361f029093084c Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'infra/translate-utils')
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/JsonUtils.java17
-rw-r--r--infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/write/TransactionWriteContext.java5
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();
}