|
@@ -180,12 +180,9 @@ public class QuorumPeerConfig {
|
|
.build()).create(path);
|
|
.build()).create(path);
|
|
|
|
|
|
Properties cfg = new Properties();
|
|
Properties cfg = new Properties();
|
|
- FileInputStream in = new FileInputStream(configFile);
|
|
|
|
- try {
|
|
|
|
|
|
+ try (FileInputStream in = new FileInputStream(configFile)) {
|
|
cfg.load(in);
|
|
cfg.load(in);
|
|
configFileStr = path;
|
|
configFileStr = path;
|
|
- } finally {
|
|
|
|
- in.close();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/* Read entire config file as initial configuration */
|
|
/* Read entire config file as initial configuration */
|
|
@@ -201,8 +198,7 @@ public class QuorumPeerConfig {
|
|
if (dynamicConfigFileStr != null) {
|
|
if (dynamicConfigFileStr != null) {
|
|
try {
|
|
try {
|
|
Properties dynamicCfg = new Properties();
|
|
Properties dynamicCfg = new Properties();
|
|
- FileInputStream inConfig = new FileInputStream(dynamicConfigFileStr);
|
|
|
|
- try {
|
|
|
|
|
|
+ try (FileInputStream inConfig = new FileInputStream(dynamicConfigFileStr)) {
|
|
dynamicCfg.load(inConfig);
|
|
dynamicCfg.load(inConfig);
|
|
if (dynamicCfg.getProperty("version") != null) {
|
|
if (dynamicCfg.getProperty("version") != null) {
|
|
throw new ConfigException("dynamic file shouldn't have version inside");
|
|
throw new ConfigException("dynamic file shouldn't have version inside");
|
|
@@ -214,8 +210,6 @@ public class QuorumPeerConfig {
|
|
if (version != null) {
|
|
if (version != null) {
|
|
dynamicCfg.setProperty("version", version);
|
|
dynamicCfg.setProperty("version", version);
|
|
}
|
|
}
|
|
- } finally {
|
|
|
|
- inConfig.close();
|
|
|
|
}
|
|
}
|
|
setupQuorumPeerConfig(dynamicCfg, false);
|
|
setupQuorumPeerConfig(dynamicCfg, false);
|
|
|
|
|
|
@@ -228,11 +222,8 @@ public class QuorumPeerConfig {
|
|
if (nextDynamicConfigFile.exists()) {
|
|
if (nextDynamicConfigFile.exists()) {
|
|
try {
|
|
try {
|
|
Properties dynamicConfigNextCfg = new Properties();
|
|
Properties dynamicConfigNextCfg = new Properties();
|
|
- FileInputStream inConfigNext = new FileInputStream(nextDynamicConfigFile);
|
|
|
|
- try {
|
|
|
|
|
|
+ try (FileInputStream inConfigNext = new FileInputStream(nextDynamicConfigFile)) {
|
|
dynamicConfigNextCfg.load(inConfigNext);
|
|
dynamicConfigNextCfg.load(inConfigNext);
|
|
- } finally {
|
|
|
|
- inConfigNext.close();
|
|
|
|
}
|
|
}
|
|
boolean isHierarchical = false;
|
|
boolean isHierarchical = false;
|
|
for (Entry<Object, Object> entry : dynamicConfigNextCfg.entrySet()) {
|
|
for (Entry<Object, Object> entry : dynamicConfigNextCfg.entrySet()) {
|
|
@@ -529,18 +520,12 @@ public class QuorumPeerConfig {
|
|
new AtomicFileWritingIdiom(new File(configFileStr + ".bak"), new OutputStreamStatement() {
|
|
new AtomicFileWritingIdiom(new File(configFileStr + ".bak"), new OutputStreamStatement() {
|
|
@Override
|
|
@Override
|
|
public void write(OutputStream output) throws IOException {
|
|
public void write(OutputStream output) throws IOException {
|
|
- InputStream input = null;
|
|
|
|
- try {
|
|
|
|
- input = new FileInputStream(new File(configFileStr));
|
|
|
|
|
|
+ try (InputStream input = new FileInputStream(new File(configFileStr))) {
|
|
byte[] buf = new byte[1024];
|
|
byte[] buf = new byte[1024];
|
|
int bytesRead;
|
|
int bytesRead;
|
|
while ((bytesRead = input.read(buf)) > 0) {
|
|
while ((bytesRead = input.read(buf)) > 0) {
|
|
output.write(buf, 0, bytesRead);
|
|
output.write(buf, 0, bytesRead);
|
|
}
|
|
}
|
|
- } finally {
|
|
|
|
- if (input != null) {
|
|
|
|
- input.close();
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -597,11 +582,8 @@ public class QuorumPeerConfig {
|
|
.build()).create(dynamicFileStr);
|
|
.build()).create(dynamicFileStr);
|
|
|
|
|
|
final Properties cfg = new Properties();
|
|
final Properties cfg = new Properties();
|
|
- FileInputStream in = new FileInputStream(configFile);
|
|
|
|
- try {
|
|
|
|
|
|
+ try (FileInputStream in = new FileInputStream(configFile)) {
|
|
cfg.load(in);
|
|
cfg.load(in);
|
|
- } finally {
|
|
|
|
- in.close();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
new AtomicFileWritingIdiom(new File(configFileStr), new WriterStatement() {
|
|
new AtomicFileWritingIdiom(new File(configFileStr), new WriterStatement() {
|