Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * This file is part of the DiffX library.
 *
 * For licensing information please see the file license.txt included in the release.
 * A copy of this licence can also be found at
 *   http://www.opensource.org/licenses/artistic-license-2.0.php
 */

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

public class Main {
    /**
     * Parses the given {@link File} with the specified {@link XMLReader}.
     * 
     * <p>This method assumes the XML is in 'UTF-8', it will not sniff the XML to
     * determine the encoding to use.
     * 
     * @param xmlreader The XML reader to use.
     * @param file      The file to parse
     * 
     * @throws FileNotFoundException If the file does not exists
     * @throws SAXException          Should an SAX exception occur
     * @throws IOException           Should an I/O exception occur
     */
    public static void parse(XMLReader xmlreader, File file)
            throws FileNotFoundException, SAXException, IOException {
        // create the input source
        InputStream bin = new BufferedInputStream(new FileInputStream(file));
        Reader reader = new InputStreamReader(bin, "utf-8");
        InputSource source = new InputSource(reader);
        // parse the file
        xmlreader.parse(source);
        reader.close();
    }
}