Skip to content

Commit ace28d1

Browse files
committed
Skip comments in TCPPING.initial_hosts_file's contents
1 parent d118f6e commit ace28d1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/org/jgroups/protocols/TCPPING.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void init() throws Exception {
151151
try(InputStream input=Util.getResourceAsStream(initial_hosts_file, getClass())) {
152152
if(input == null)
153153
throw new IllegalArgumentException(String.format("initial_hosts_file '%s' not found", initial_hosts_file));
154-
initial_hosts_str=Util.readContents(input);
154+
initial_hosts_str=Util.readContents(input, '#');
155155
}
156156
}
157157

src/org/jgroups/util/Util.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2076,13 +2076,22 @@ public static String readFile(String filename) throws FileNotFoundException {
20762076

20772077

20782078
public static String readContents(InputStream input) {
2079+
return readContents(input, (char)0);
2080+
}
2081+
2082+
public static String readContents(InputStream input, char comment) {
20792083
StringBuilder sb=new StringBuilder();
20802084
int ch;
20812085
while(true) {
20822086
try {
20832087
ch=input.read();
2084-
if(ch != -1)
2088+
if(ch != -1) {
2089+
if(comment != 0 && comment == ch) {
2090+
skipUntilEndOfLine(input);
2091+
continue;
2092+
}
20852093
sb.append((char)ch);
2094+
}
20862095
else
20872096
break;
20882097
}
@@ -2093,6 +2102,21 @@ public static String readContents(InputStream input) {
20932102
return sb.toString();
20942103
}
20952104

2105+
protected static void skipUntilEndOfLine(InputStream input) {
2106+
for(;;) {
2107+
try {
2108+
int ch=input.read();
2109+
if(ch == -1)
2110+
break;
2111+
if(ch == '\n' || ch == '\r')
2112+
break;
2113+
}
2114+
catch(IOException e) {
2115+
break;
2116+
}
2117+
}
2118+
}
2119+
20962120
public static byte[] readFileContents(InputStream input) throws IOException {
20972121
byte[] contents=new byte[10000];
20982122
byte[] buf=new byte[1024];

0 commit comments

Comments
 (0)