public static void readFileToMapWithFileInputStream(String type, String filename, InputStream inputStream, Map<String, Integer> map) throws IOException { // The input file could be either simple text or XML. boolean xmlInput = filename.toLowerCase().endsWith(".xml"); if (xmlInput) { readXmlFileToMapWithFileInputStream(type, filename, inputStream, map); } else { HashSet<String> nodes = new HashSet<String>(); readFileToSetWithFileInputStream(type, filename, inputStream, nodes); for (String node : nodes) { map.put(node, null); } } }