Java XMLStreamReader createXMLStreamReaderFromReader(final Reader reader)

Here you can find the source of createXMLStreamReaderFromReader(final Reader reader)

Description

Creates an XML stream reader from the specified input stream.

License

Apache License

Parameter

Parameter Description
reader An <code>InputStreamReader</code> object that represents the input reader to use as the source.

Exception

Parameter Description
XMLStreamException If the XML stream reader could not be created.

Return

A java.xml.stream.XMLStreamReader object that represents the XML stream reader created from the specified input stream.

Declaration

public static XMLStreamReader createXMLStreamReaderFromReader(final Reader reader) throws XMLStreamException 

Method Source Code

//package com.java2s;
/**//from  www  .  j  a va2 s  . c o  m
 * Copyright Microsoft Corporation
 * 
 * Licensed 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 java.io.Reader;

import javax.xml.stream.XMLInputFactory;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

public class Main {
    /**
     * Creates an XML stream reader from the specified input stream.
     * 
     * @param reader
     *            An <code>InputStreamReader</code> object that represents the input reader to use as the source.
     * 
     * @return A <code>java.xml.stream.XMLStreamReader</code> object that represents the XML stream reader created from
     *         the specified input stream.
     * 
     * @throws XMLStreamException
     *             If the XML stream reader could not be created.
     */
    public static XMLStreamReader createXMLStreamReaderFromReader(final Reader reader) throws XMLStreamException {
        XMLInputFactory xmlif = null;

        xmlif = XMLInputFactory.newInstance();
        xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
        xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
        // set the IS_COALESCING property to true , if application desires to
        // get whole text data as one event.
        xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);

        return xmlif.createXMLStreamReader(reader);
    }
}

Related

  1. close(XMLStreamReader reader)
  2. createFilteredReader(XMLStreamReader reader, StreamFilter filter)
  3. createXMLStreamReader(File file)
  4. createXMLStreamReader(InputStream in)
  5. createXMLStreamReader(InputStream in, String encoding)
  6. decodeAsDataHandler(XMLStreamReader reader, AttachmentUnmarshaller au)
  7. getNextEvent(XMLStreamReader reader)
  8. getXMLStreamReader(File file)
  9. getXMLStreamReader(InputStream is)