diff --git a/README.adoc b/README.adoc index 11e92d5b..6c999969 100644 --- a/README.adoc +++ b/README.adoc @@ -103,6 +103,12 @@ Do NOT use it. |true |false +.2+|dnsjava.hostsfile.max_size_bytes +3+|Set the size of the hosts file to be loaded at a time, in bytes. +|Integer +|16384 +|1000000 + .2+|dnsjava.nio.selector_timeout 3+|Set selector timeout in milliseconds. Default/Max 1000, Min 1. |Integer diff --git a/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java b/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java index 2e6ac420..4bf614a3 100644 --- a/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java +++ b/src/main/java/org/xbill/DNS/hosts/HostsFileParser.java @@ -29,7 +29,8 @@ */ @Slf4j public final class HostsFileParser { - private static final int MAX_FULL_CACHE_FILE_SIZE_BYTES = 16384; + private final int MAX_FULL_CACHE_FILE_SIZE_BYTES = Integer.parseInt( + System.getProperty("dnsjava.hostsfile.max_size_bytes", "16384")); private final Map hostsCache = new HashMap<>(); private final Path path; diff --git a/src/test/java/org/xbill/DNS/hosts/HostsFileParserTest.java b/src/test/java/org/xbill/DNS/hosts/HostsFileParserTest.java index a9ae9d37..10ffef41 100644 --- a/src/test/java/org/xbill/DNS/hosts/HostsFileParserTest.java +++ b/src/test/java/org/xbill/DNS/hosts/HostsFileParserTest.java @@ -171,6 +171,19 @@ void testBigFileIsNotCompletelyCachedA() throws IOException { assertEquals(1, hostsFileParser.cacheSize()); } + @Test + void testBigFileCompletelyCachedA() throws IOException { + try { + System.setProperty("dnsjava.hostsfile.max_size_bytes", 1024 * 1024 * 1024 + ""); + HostsFileParser hostsFileParser = generateLargeHostsFile("testBigFileCompletelyCachedA"); + hostsFileParser.getAddressForHost(Name.fromConstantString("localhost-10."), Type.A) + .orElseThrow(() -> new IllegalStateException("Host entry not found")); + assertEquals(1280, hostsFileParser.cacheSize()); + } finally { + System.clearProperty("dnsjava.hostsfile.max_size_bytes"); + } + } + @Test void testBigFileIsNotCompletelyCachedAAAA() throws IOException { HostsFileParser hostsFileParser =