summaryrefslogtreecommitdiffstats
path: root/infra/translate-utils/src/main
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 15:39:43 +0200
commitd41b116f0a177683a326a9d18c4f6aa1ece651de (patch)
treee41057bb035c7ea6762e27f48224ac4822bcd00b /infra/translate-utils/src/main
parent7567ab4670f6cdf44e227ab8d547414a755401df (diff)
Fixing sonar issues #1
Change-Id: I4c27d0ad2fd1655db2237ae914361f029093084c Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'infra/translate-utils/src/main')
-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();
}