Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.ByteArrayInputStream;

import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class Main {
    /**
     * Parses a {@link Document} from an {@link InputStream} containing one.
     * This is quite usual start {@link PersistenceHandler #load(InputStream)
     * load()}-method of an {@link PersistenceHandler}-implementor.
     * 
     * @param inStream
     *            {@link InputStream} from which to parse
     * @return {@link Document} parsed from the input-stream
     * @throws ParserConfigurationException
     * @throws SAXException
     * @throws IOException
     */
    public static Document parseFromBytes(byte[] dataPres)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilder dBuilder = null;
        Document doc = null;
        dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

        // no external resources are tied with ByteArray-streams;
        // no need to worry about closing
        doc = dBuilder.parse(new ByteArrayInputStream(dataPres));

        doc.getDocumentElement().normalize();
        return doc;
    }
}