Code example for Logger

Methods: entering, exiting, isLoggable, logp

0
     * 
     * @throws SAXException Thrown if a parse error occurs. 
     * @throws IOException Thrown if an IO error occurs. 
     */ 
    public static void toJson(InputStream XMLStream, OutputStream JSONStream, boolean verbose) throws SAXException, IOException {
        if (logger.isLoggable(Level.FINER)) {
            logger.entering(className, "toJson(InputStream, OutputStream)");
        } 
 
        if (XMLStream == null) {
            throw new NullPointerException("XMLStream cannot be null");
        } else if (JSONStream == null) {
            throw new NullPointerException("JSONStream cannot be null");
        } else { 
 
            if (logger.isLoggable(Level.FINEST)) {
                logger.logp(Level.FINEST, className, "transform", "Fetching a SAX parser for use with JSONSAXHandler");
            } 
 
            try { 
                /** 
                 * Get a parser. 
                 */ 
                SAXParserFactory factory = SAXParserFactory.newInstance();
                factory.setNamespaceAware(true);
                SAXParser sParser = factory.newSAXParser();
                XMLReader parser = sParser.getXMLReader();
                JSONSAXHandler jsonHandler = new JSONSAXHandler(JSONStream, verbose);
                parser.setContentHandler(jsonHandler);
                parser.setErrorHandler(jsonHandler);
                InputSource source = new InputSource(new BufferedInputStream(XMLStream));
 
                if (logger.isLoggable(Level.FINEST)) {
                    logger.logp(Level.FINEST, className, "transform", "Parsing the XML content to JSON");
                } 
 
                /**  
                 * Parse it. 
                 */ 
                source.setEncoding("UTF-8");
                parser.parse(source);                 
                jsonHandler.flushBuffer();
            } catch (javax.xml.parsers.ParserConfigurationException pce) {
                throw new SAXException("Could not get a parser: " + pce.toString());
            } 
        } 
 
        if (logger.isLoggable(Level.FINER)) {
            logger.exiting(className, "toJson(InputStream, OutputStream)");
        } 
    } 
 
    /** 
     * Method to take an input stream to an XML document and return a String of the JSON format.