File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -151,7 +151,7 @@ public void init() throws Exception {
151
151
try (InputStream input =Util .getResourceAsStream (initial_hosts_file , getClass ())) {
152
152
if (input == null )
153
153
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 , '#' );
155
155
}
156
156
}
157
157
Original file line number Diff line number Diff line change @@ -2076,13 +2076,22 @@ public static String readFile(String filename) throws FileNotFoundException {
2076
2076
2077
2077
2078
2078
public static String readContents (InputStream input ) {
2079
+ return readContents (input , (char )0 );
2080
+ }
2081
+
2082
+ public static String readContents (InputStream input , char comment ) {
2079
2083
StringBuilder sb =new StringBuilder ();
2080
2084
int ch ;
2081
2085
while (true ) {
2082
2086
try {
2083
2087
ch =input .read ();
2084
- if (ch != -1 )
2088
+ if (ch != -1 ) {
2089
+ if (comment != 0 && comment == ch ) {
2090
+ skipUntilEndOfLine (input );
2091
+ continue ;
2092
+ }
2085
2093
sb .append ((char )ch );
2094
+ }
2086
2095
else
2087
2096
break ;
2088
2097
}
@@ -2093,6 +2102,21 @@ public static String readContents(InputStream input) {
2093
2102
return sb .toString ();
2094
2103
}
2095
2104
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
+
2096
2120
public static byte [] readFileContents (InputStream input ) throws IOException {
2097
2121
byte [] contents =new byte [10000 ];
2098
2122
byte [] buf =new byte [1024 ];
You can’t perform that action at this time.
0 commit comments