protected BufferedReader open(String fileName) {
        String encoding = System.getProperty("file.encoding");

        try {
            if (fileName != null) {
                FileInputStream fis = new FileInputStream(fileName);
                InputStreamReader isr = new InputStreamReader(fis, encoding);
                return new BufferedReader(isr);
            } else {
                return new BufferedReader(new java.io.InputStreamReader(System.in));
            }
        } catch (FileNotFoundException x) {
            System.err.println("Cannot open " + fileName);
            System.exit(1);
        } catch (UnsupportedEncodingException x) {
            System.err.println("Unsuported encoding " + encoding);
            System.exit(1);
        } catch (IOException x) {
            System.err.println("Unable to close an open reader");
        }
        return null;
    }