项目本身运行在tomcat里,每次如果修改了某个配置文件,就要重新启动一下项目,耗时还很麻烦,所以就想写个接口,可以在配置文件被修改时,直接调用此接口进行重载所有的配置文件或者某个配置文件。现在就有个问题是,如果修改了原本就被加载的配置项,在使用PropertiesProxy().load(Reader)时,是否会销毁之前旧的配置项,是销毁全部再重新载入,还是只载入有改动的部分?
另外在MultiLineProperties里面,是不是有个注释写错了?
/**
* <b>载入并销毁之前的记录</b>
*
* @param reader
* @throws IOException
*/
public synchronized void load(Reader reader) throws IOException {
load(reader, false);
}
public synchronized void load(Reader reader, boolean clear) throws IOException {
if (clear)
this.clear();
BufferedReader tr = null;
if (reader instanceof BufferedReader)
tr = (BufferedReader) reader;
else
tr = new BufferedReader(reader);
String s;
while (null != (s = tr.readLine())) {
if (Strings.isBlank(s))
continue;
if (s.length() > 0 && s.trim().charAt(0) == '#') // 只要第一个非空白字符是#,就认为是注释
continue;
int pos;
char c = '0';
for (pos = 0; pos < s.length(); pos++) {
c = s.charAt(pos);
if (c == '=' || c == ':')
break;
}
if (c == '=') {
String name = s.substring(0, pos);
String value = s.substring(pos + 1);
if (value.endsWith("\\") && !value.endsWith("\\\\")) {
StringBuilder sb = new StringBuilder(value.substring(0, value.length() - 1));
while (null != (s = tr.readLine())) {
if (Strings.isBlank(s))
break;
if (s.endsWith("\\") && !s.endsWith("\\\\")) {
sb.append(s.substring(0, s.length() - 1));
} else {
sb.append(s);
break;
}
}
value = sb.toString();
}
// 对value里面的\\uXXXX进行转义?
if (value.contains("\\u")) {
value = Strings.unicodeDecode(value);
}
value = value.replace("\\:", ":").replace("\\=", "=");
maps.put(Strings.trim(name), value);
} else if (c == ':') {
String name = s.substring(0, pos);
StringBuffer sb = new StringBuffer();
sb.append(s.substring(pos + 1));
String ss;
while (null != (ss = tr.readLine())) {
if (ss.length() > 0 && ss.charAt(0) == '#')
break;
sb.append("\r\n" + ss);
}
maps.put(Strings.trim(name), sb.toString());
if (null == ss)
return;
} else {
maps.put(Strings.trim(s), null);
}
}
}