File tree Expand file tree Collapse file tree
main/java/org/xbill/DNS/hosts
test/java/org/xbill/DNS/hosts Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,6 +103,12 @@ Do NOT use it.
103103|true
104104|false
105105
106+ .2+|dnsjava.hostsfile.max_size_bytes
107+ 3+|Set the size of the hosts file to be loaded at a time, in bytes.
108+ |Integer
109+ |16384
110+ |1000000
111+
106112.2+|dnsjava.nio.selector_timeout
1071133+|Set selector timeout in milliseconds. Default/Max 1000, Min 1.
108114|Integer
Original file line number Diff line number Diff line change 2929 */
3030@ Slf4j
3131public final class HostsFileParser {
32- private static final int MAX_FULL_CACHE_FILE_SIZE_BYTES = 16384 ;
32+ private final int MAX_FULL_CACHE_FILE_SIZE_BYTES = Integer .parseInt (
33+ System .getProperty ("dnsjava.hostsfile.max_size_bytes" , "16384" ));
3334
3435 private final Map <String , InetAddress > hostsCache = new HashMap <>();
3536 private final Path path ;
Original file line number Diff line number Diff line change @@ -171,6 +171,19 @@ void testBigFileIsNotCompletelyCachedA() throws IOException {
171171 assertEquals (1 , hostsFileParser .cacheSize ());
172172 }
173173
174+ @ Test
175+ void testBigFileCompletelyCachedA () throws IOException {
176+ try {
177+ System .setProperty ("dnsjava.hostsfile.max_size_bytes" , 1024 * 1024 * 1024 + "" );
178+ HostsFileParser hostsFileParser = generateLargeHostsFile ("testBigFileCompletelyCachedA" );
179+ hostsFileParser .getAddressForHost (Name .fromConstantString ("localhost-10." ), Type .A )
180+ .orElseThrow (() -> new IllegalStateException ("Host entry not found" ));
181+ assertEquals (1280 , hostsFileParser .cacheSize ());
182+ } finally {
183+ System .clearProperty ("dnsjava.hostsfile.max_size_bytes" );
184+ }
185+ }
186+
174187 @ Test
175188 void testBigFileIsNotCompletelyCachedAAAA () throws IOException {
176189 HostsFileParser hostsFileParser =
You can’t perform that action at this time.
0 commit comments