Java XML JAXB Unmarshaller unmarshal(String packageName, InputStream inputStream)

Here you can find the source of unmarshal(String packageName, InputStream inputStream)

Description

unmarshal

License

Apache License

Declaration

public static Object unmarshal(String packageName, InputStream inputStream) throws JAXBException 

Method Source Code

//package com.java2s;
/**/* w  ww  .j ava 2s.co m*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;
import java.io.*;

public class Main {

    public static Object unmarshal(String packageName, String xmlFilePath, String xmlFileName)
            throws JAXBException {
        Unmarshaller unmarshaller = createUnmarshaller(packageName);
        return unmarshaller.unmarshal(new File(xmlFilePath + File.separator + xmlFileName));
    }

    public static Object unmarshal(Unmarshaller unmarshaller, String xmlFilePath, String xmlFileName)
            throws JAXBException {
        return unmarshaller.unmarshal(new File(xmlFilePath + File.separator + xmlFileName));
    }

    public static Object unmarshal(String packageName, String xmlData) throws JAXBException {
        Unmarshaller unmarshaller = createUnmarshaller(packageName);
        StringReader reader = null;
        try {
            reader = new StringReader(xmlData);
            return unmarshaller.unmarshal(reader);
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
    }

    public static Object unmarshal(Unmarshaller unmarshaller, String xmlData) throws JAXBException {
        StringReader reader = null;
        try {
            reader = new StringReader(xmlData);
            return unmarshaller.unmarshal(reader);
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
    }

    public static Object unmarshal(String packageName, InputStream inputStream) throws JAXBException {
        Unmarshaller unmarshaller = createUnmarshaller(packageName);
        return unmarshaller.unmarshal(inputStream);
    }

    public static Object unmarshal(Unmarshaller unmarshaller, InputStream inputStream) throws JAXBException {
        return unmarshaller.unmarshal(inputStream);
    }

    public static Object unmarshal(String packageName, Reader reader) throws JAXBException {
        Unmarshaller unmarshaller = createUnmarshaller(packageName);
        return unmarshaller.unmarshal(reader);
    }

    public static Object unmarshal(Unmarshaller unmarshaller, Reader reader) throws JAXBException {
        return unmarshaller.unmarshal(reader);
    }

    public static Unmarshaller createUnmarshaller(String packageName) throws JAXBException {
        JAXBContext context = JAXBContext.newInstance(packageName);
        return context.createUnmarshaller();
    }
}

Related

  1. unmarshal(org.w3c.dom.Element elem, Class c)
  2. unmarshal(String b, Class implClass, Class... bc)
  3. unmarshal(String content, Class clasz)
  4. unMarshal(String contextPath, InputStream xmlStream)
  5. unmarshal(String ObjXml, Class configurationClass)
  6. unmarshal(String string, Class clazz)
  7. unmarshal(String xml, Class c)
  8. unmarshal(String xml, Class clazz)
  9. unmarshal(String xml, Class clazz)