Skip to content

Commit

Permalink
Skip comments in TCPPING.initial_hosts_file's contents
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Jan 10, 2025
1 parent 57c1f93 commit 79ac5a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/org/jgroups/protocols/TCPPING.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void init() throws Exception {
try(InputStream input=Util.getResourceAsStream(initial_hosts_file, getClass())) {
if(input == null)
throw new IllegalArgumentException(String.format("initial_hosts_file '%s' not found", initial_hosts_file));
initial_hosts_str=Util.readContents(input);
initial_hosts_str=Util.readContents(input, '#');
}
}

Expand Down
26 changes: 25 additions & 1 deletion src/org/jgroups/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -2054,13 +2054,22 @@ public static String readFile(String filename) throws FileNotFoundException {


public static String readContents(InputStream input) {
return readContents(input, (char)0);
}

public static String readContents(InputStream input, char comment) {
StringBuilder sb=new StringBuilder();
int ch;
while(true) {
try {
ch=input.read();
if(ch != -1)
if(ch != -1) {
if(comment != 0 && comment == ch) {
skipUntilEndOfLine(input);
continue;
}
sb.append((char)ch);
}
else
break;
}
Expand All @@ -2071,6 +2080,21 @@ public static String readContents(InputStream input) {
return sb.toString();
}

protected static void skipUntilEndOfLine(InputStream input) {
for(;;) {
try {
int ch=input.read();
if(ch == -1)
break;
if(ch == '\n' || ch == '\r')
break;
}
catch(IOException e) {
break;
}
}
}

public static byte[] readFileContents(InputStream input) throws IOException {
byte[] contents=new byte[10000];
byte[] buf=new byte[1024];
Expand Down

0 comments on commit 79ac5a2

Please sign in to comment.