Merge pull request #1039 from kpm1985/FLUO-1038
FLUO-1038 Use try with resources for streams in FluoAdminImpl
diff --git a/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java b/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
index 5210cc0..b2ee018 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
@@ -329,11 +329,11 @@
}
}
- try {
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
CuratorFramework curator = getAppCurator();
ObserverUtil.initialize(curator, config);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
sharedProps.store(baos, "Shared java props");
CuratorUtil.putData(curator, ZookeeperPath.CONFIG_SHARED, baos.toByteArray(),
@@ -451,13 +451,14 @@
try (CuratorFramework curator = CuratorUtil.newAppCurator(config)) {
curator.start();
- ByteArrayInputStream bais =
- new ByteArrayInputStream(curator.getData().forPath(ZookeeperPath.CONFIG_SHARED));
- Properties sharedProps = new Properties();
- sharedProps.load(bais);
+ try (ByteArrayInputStream bais =
+ new ByteArrayInputStream(curator.getData().forPath(ZookeeperPath.CONFIG_SHARED))) {
- for (String prop : sharedProps.stringPropertyNames()) {
- zooConfig.setProperty(prop, sharedProps.getProperty(prop));
+ Properties sharedProps = new Properties();
+ sharedProps.load(bais);
+ for (String prop : sharedProps.stringPropertyNames()) {
+ zooConfig.setProperty(prop, sharedProps.getProperty(prop));
+ }
}
} catch (Exception e) {
throw new IllegalStateException(e);