summaryrefslogtreecommitdiffstats
path: root/infra/data-impl/src/main/java/io
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-11-03 16:21:13 +0100
committerMaros Marsalek <mmarsale@cisco.com>2016-11-03 18:04:44 +0100
commit49ff45b7612f3a0d89c931ee218c80400eedbec2 (patch)
tree25b0d6bca03a047ce3ad3f8bd32df5a9b5452a61 /infra/data-impl/src/main/java/io
parente83f0e1d6451c96ef9850b4a8b058c4b5c307617 (diff)
Properly close open files(persistence)
Change-Id: I0b6a01c7360e056059b0c8ed1821a0fdddc59308 Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'infra/data-impl/src/main/java/io')
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapter.java8
1 files changed, 4 insertions, 4 deletions
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapter.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapter.java
index 356ca51c1..3c356c256 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapter.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapter.java
@@ -24,6 +24,7 @@ import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import io.fd.honeycomb.translate.util.JsonUtils;
import java.io.IOException;
+import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
@@ -109,11 +110,10 @@ public class PersistingDataTreeAdapter implements DataTree {
void persistCurrentData(final Optional<NormalizedNode<?, ?>> currentRoot) {
if (currentRoot.isPresent()) {
- try {
+ try (OutputStream outputStream = Files.newOutputStream(path, StandardOpenOption.CREATE,
+ StandardOpenOption.TRUNCATE_EXISTING)) {
LOG.trace("Persisting current data: {} into: {}", currentRoot.get(), path);
- JsonUtils.writeJsonRoot(currentRoot.get(), schemaServiceDependency.getGlobalContext(),
- Files.newOutputStream(path, StandardOpenOption.CREATE,
- StandardOpenOption.TRUNCATE_EXISTING));
+ JsonUtils.writeJsonRoot(currentRoot.get(), schemaServiceDependency.getGlobalContext(), outputStream);
LOG.trace("Data persisted successfully in {}", path);
} catch (IOException e) {
throw new IllegalStateException("Unable to persist current data", e);