Here you can find the source of removeMatchingLines( final Map
private static boolean removeMatchingLines( final Map<String, Integer> d1LineMap, final Path tableDir, final String table, final BufferedWriter errors) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; import java.util.zip.GZIPInputStream; public class Main { private static boolean removeMatchingLines( final Map<String, Integer> d1LineMap, final Path tableDir, final String table, final BufferedWriter errors) throws IOException { boolean passed = true; try (DirectoryStream<Path> listing = Files .newDirectoryStream(tableDir)) { for (final Path file : listing) { try (BufferedReader in = getReaderForFile(file)) { String line = in.readLine(); while (line != null) { if (!d1LineMap.containsKey(line)) { passed = false; errors.write("> " + table + ": " + line); }/*from w w w. j av a 2 s . co m*/ if (d1LineMap.get(line) == 1) { d1LineMap.remove(line); } else { d1LineMap.put(line, d1LineMap.get(line) - 1); } line = in.readLine(); } } } } return passed; } private static BufferedReader getReaderForFile(final Path file) throws FileNotFoundException, IOException { final String filename = file.getFileName().toString().toLowerCase(); if (filename.endsWith(".gz")) { return new BufferedReader(new InputStreamReader( new GZIPInputStream(Files.newInputStream(file)))); } return Files.newBufferedReader(file); } }