HostsFileReader { public HostsFileReader(String inFile, String exFile) throws IOException { HostDetails hostDetails = new HostDetails( inFile, Collections.emptySet(), exFile, Collections.emptyMap()); current = new AtomicReference<>(hostDetails); refresh(inFile, exFile); } HostsFileReader(String inFile,
                         String exFile); @Private  HostsFileReader(String includesFile, InputStream inFileInputStream,
      String excludesFile, InputStream exFileInputStream); static void readFileToSet(String type,
      String filename, Set<String> set); @Private static void readFileToSetWithFileInputStream(String type,
      String filename, InputStream fileInputStream, Set<String> set); void refresh(); static void readFileToMap(String type,
      String filename, Map<String, Integer> map); static void readFileToMapWithFileInputStream(String type,
      String filename, InputStream inputStream, Map<String, Integer> map); static void readXmlFileToMapWithFileInputStream(String type,
      String filename, InputStream fileInputStream, Map<String, Integer> map); void refresh(String includesFile, String excludesFile); @Private void refresh(InputStream inFileInputStream,
      InputStream exFileInputStream); Set<String> getHosts(); Set<String> getExcludedHosts(); @Deprecated void getHostDetails(Set<String> includes, Set<String> excludes); @Deprecated void getHostDetails(Set<String> includeHosts,
                             Map<String, Integer> excludeHosts); HostDetails getHostDetails(); void setIncludesFile(String includesFile); void setExcludesFile(String excludesFile); void updateFileNames(String includesFile, String excludesFile);  }
@Test public void testHostsFileReader() throws Exception { FileWriter efw = new FileWriter(excludesFile); FileWriter ifw = new FileWriter(includesFile); efw.write("#DFS-Hosts-excluded\n"); efw.write("somehost1\n"); efw.write("#This-is-comment\n"); efw.write("somehost2\n"); efw.write("somehost3 # host3\n"); efw.write("somehost4\n"); efw.write("somehost4 somehost5\n"); efw.close(); ifw.write("#Hosts-in-DFS\n"); ifw.write("somehost1\n"); ifw.write("somehost2\n"); ifw.write("somehost3\n"); ifw.write("#This-is-comment\n"); ifw.write("somehost4 # host4\n"); ifw.write("somehost4 somehost5\n"); ifw.close(); HostsFileReader hfp = new HostsFileReader(includesFile, excludesFile); int includesLen = hfp.getHosts().size(); int excludesLen = hfp.getExcludedHosts().size(); assertEquals(5, includesLen); assertEquals(5, excludesLen); assertTrue(hfp.getHosts().contains("somehost5")); assertFalse(hfp.getHosts().contains("host3")); assertTrue(hfp.getExcludedHosts().contains("somehost5")); assertFalse(hfp.getExcludedHosts().contains("host4")); String newExcludesFile = HOSTS_TEST_DIR + "/dfs1.exclude"; String newIncludesFile = HOSTS_TEST_DIR + "/dfs1.include"; efw = new FileWriter(newExcludesFile); ifw = new FileWriter(newIncludesFile); efw.write("#DFS-Hosts-excluded\n"); efw.write("node1\n"); efw.close(); ifw.write("#Hosts-in-DFS\n"); ifw.write("node2\n"); ifw.close(); hfp.refresh(newIncludesFile, newExcludesFile); assertTrue(hfp.getExcludedHosts().contains("node1")); assertTrue(hfp.getHosts().contains("node2")); HostDetails hostDetails = hfp.getHostDetails(); assertTrue(hostDetails.getExcludedHosts().contains("node1")); assertTrue(hostDetails.getIncludedHosts().contains("node2")); assertEquals(newIncludesFile, hostDetails.getIncludesFile()); assertEquals(newExcludesFile, hostDetails.getExcludesFile()); }