import java.io.*; public final class TextHandler extends AbstractHandler { private final static TextHandler INSTANCE = new TextHandler(); public static Handler getInstance() {return INSTANCE;} public String description() { return "Text files"; } void explainRest(File f) { BufferedReader in = null; try { int lines = 0; int words = 0; String line; in = new BufferedReader(new FileReader(f)); while ((line = in.readLine()) != null) { lines++; words += line.split("\\s+").length; } add("# lines",lines); add("# words",words); } catch (IOException e) { Util.getInstance().handle("Trouble reading " + f,e); if (in != null) { try { in.close(); } catch (IOException ee) { Util.getInstance().handle("Trouble closing " + f,e); } } } } }