refactor: IO改成try resource。instanceList循环直接改成addAll
This commit is contained in:
parent
08e69a0b21
commit
4e6d8b67a2
@ -121,11 +121,8 @@ public class SystemUtils {
|
|||||||
|
|
||||||
public static List<String> readClusterConf() throws IOException {
|
public static List<String> readClusterConf() throws IOException {
|
||||||
List<String> instanceList = new ArrayList<String>();
|
List<String> instanceList = new ArrayList<String>();
|
||||||
Reader reader = null;
|
try(Reader reader = new InputStreamReader(new FileInputStream(new File(CLUSTER_CONF_FILE_PATH)),
|
||||||
|
StandardCharsets.UTF_8)) {
|
||||||
try {
|
|
||||||
reader = new InputStreamReader(new FileInputStream(new File(CLUSTER_CONF_FILE_PATH)),
|
|
||||||
StandardCharsets.UTF_8);
|
|
||||||
List<String> lines = IoUtils.readLines(reader);
|
List<String> lines = IoUtils.readLines(reader);
|
||||||
String comment = "#";
|
String comment = "#";
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
@ -142,19 +139,13 @@ public class SystemUtils {
|
|||||||
int multiIndex = instance.indexOf(Constants.COMMA_DIVISION);
|
int multiIndex = instance.indexOf(Constants.COMMA_DIVISION);
|
||||||
if (multiIndex > 0) {
|
if (multiIndex > 0) {
|
||||||
// support the format: ip1:port,ip2:port # multi inline
|
// support the format: ip1:port,ip2:port # multi inline
|
||||||
for (String ins : instance.split(Constants.COMMA_DIVISION)) {
|
instanceList.addAll(Arrays.asList(instance.split(Constants.COMMA_DIVISION)));
|
||||||
instanceList.add(ins);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//support the format: 192.168.71.52:8848
|
//support the format: 192.168.71.52:8848
|
||||||
instanceList.add(instance);
|
instanceList.add(instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return instanceList;
|
return instanceList;
|
||||||
} finally {
|
|
||||||
if (reader != null) {
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user