当前位置: 首页>>代码示例>>Java>>正文


Java XmlStreamReader类代码示例

本文整理汇总了Java中org.apache.commons.io.input.XmlStreamReader的典型用法代码示例。如果您正苦于以下问题:Java XmlStreamReader类的具体用法?Java XmlStreamReader怎么用?Java XmlStreamReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XmlStreamReader类属于org.apache.commons.io.input包,在下文中一共展示了XmlStreamReader类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createInvalidXmlCharacterReplacingReader

import org.apache.commons.io.input.XmlStreamReader; //导入依赖的package包/类
public ModifyingReader createInvalidXmlCharacterReplacingReader(InputStream xmlStream, String replacement)
        throws IOException {

    // buffer stream
    // (is this really necessary to get optimal performance?)
    if (!(xmlStream instanceof BufferedInputStream)) {
        xmlStream = new BufferedInputStream(xmlStream);
    }

    // get the XML version
    XmlStreamReader xmlReader = new XmlStreamReader(xmlStream);
    XmlVersionReader xmlVersionReader = new XmlVersionReader(xmlReader);
    String xmlVersion = xmlVersionReader.getXmlVersion();

    // what kind of replacement?
    boolean dollarZero;
    if (replacement.contains("$0")) {
        dollarZero = true;
    } else {
        dollarZero = false;
    }

    // create the reader that replaces invalid XML characters
    Modifier modifier = new InvalidXmlCharacterModifier(8192, replacement, xmlVersion, dollarZero);
    return new ModifyingReader(xmlVersionReader, modifier);
}
 
开发者ID:rwitzel,项目名称:streamflyer,代码行数:27,代码来源:ModifyingReaderFactory.java

示例2: createXmlVersionModifyingReader

import org.apache.commons.io.input.XmlStreamReader; //导入依赖的package包/类
public ModifyingReader createXmlVersionModifyingReader(InputStream xmlStream, String newXmlVersion)
        throws IOException {

    // buffer stream
    // (is this really necessary to get optimal performance?)
    if (!(xmlStream instanceof BufferedInputStream)) {
        xmlStream = new BufferedInputStream(xmlStream);
    }

    XmlStreamReader xmlReader = new XmlStreamReader(xmlStream);
    XmlVersionReader xmlVersionReader = new XmlVersionReader(xmlReader);

    // create the reader that replaces the XML version in prolog
    Modifier modifier = new XmlVersionModifier(newXmlVersion, 8192);
    return new ModifyingReader(xmlVersionReader, modifier);
}
 
开发者ID:rwitzel,项目名称:streamflyer,代码行数:17,代码来源:ModifyingReaderFactory.java

示例3: parseFeed

import org.apache.commons.io.input.XmlStreamReader; //导入依赖的package包/类
public Feed parseFeed(Feed feed) throws SAXException, IOException,
        ParserConfigurationException, UnsupportedFeedtypeException {
    TypeGetter tg = new TypeGetter();
    TypeGetter.Type type = tg.getType(feed);
    SyndHandler handler = new SyndHandler(feed, type);

    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    SAXParser saxParser = factory.newSAXParser();
    File file = new File(feed.getFile_url());
    Reader inputStreamReader = new XmlStreamReader(file);
    InputSource inputSource = new InputSource(inputStreamReader);

    saxParser.parse(inputSource, handler);
    inputStreamReader.close();
    return handler.state.feed;
}
 
开发者ID:danieloeh,项目名称:AntennaPodSP,代码行数:18,代码来源:FeedHandler.java

示例4: getEncoding

import org.apache.commons.io.input.XmlStreamReader; //导入依赖的package包/类
/**
 * Get the encoding from an XML-file.
 *
 * @param webXml the XML-file
 * @return The encoding of the XML-file, or UTF-8 if it's not specified in the file
 * @throws java.io.IOException if an error occurred while reading the file
 */
protected String getEncoding( File webXml )
    throws IOException
{
    XmlStreamReader xmlReader = new XmlStreamReader( webXml );
    try
    {
        return xmlReader.getEncoding();
    }
    finally
    {
        IOUtil.close( xmlReader );
    }
}
 
开发者ID:zhegexiaohuozi,项目名称:maven-seimicrawler-plugin,代码行数:21,代码来源:AbstractWarPackagingTask.java

示例5: testExampleFromJavadoc

import org.apache.commons.io.input.XmlStreamReader; //导入依赖的package包/类
@Test
public void testExampleFromJavadoc() throws Exception {

    byte UTF16LE_BOM_BYTE_1 = (byte) 0xFF;
    byte UTF16LE_BOM_BYTE_2 = (byte) 0xFE;

    // version in prolog is 1.0
    String input = "<?xml version='1.0'>";
    byte[] bytes = input.getBytes("UTF-16LE");
    byte[] bytesWithBom = new byte[bytes.length + 2];
    bytesWithBom[0] = UTF16LE_BOM_BYTE_1;
    bytesWithBom[1] = UTF16LE_BOM_BYTE_2;
    System.arraycopy(bytes, 0, bytesWithBom, 2, bytes.length);

    // choose the input stream to modify
    ByteArrayInputStream inputStream = new ByteArrayInputStream(bytesWithBom);

    // wrap the input stream by BOM skipping reader
    Reader reader = new XmlStreamReader(inputStream);

    // create the reader that changes the XML version to 1.1
    ModifyingReader modifyingReader = new ModifyingReader(reader, new XmlVersionModifier("1.1", 8192));

    // use the modifying reader instead of the original reader
    String xml = IOUtils.toString(modifyingReader);

    assertTrue(xml.startsWith("<?xml version='1.1'"));
}
 
开发者ID:rwitzel,项目名称:streamflyer,代码行数:29,代码来源:XmlVersionModifierTest.java

示例6: assertXmlVersionInProlog

import org.apache.commons.io.input.XmlStreamReader; //导入依赖的package包/类
private void assertXmlVersionInProlog(byte[] input, String newXmlVersion, String expectedProlog) throws Exception {

        XmlVersionReader xmlVersionReader = new XmlVersionReader(new XmlStreamReader(new ByteArrayInputStream(input)));

        // create the reader that modifies the XML version
        ModifyingReader reader = new ModifyingReader(xmlVersionReader, createModifier(newXmlVersion, 5));

        String actualProlog = IOUtils.toString(reader);

        assertEquals(expectedProlog, actualProlog);
    }
 
开发者ID:rwitzel,项目名称:streamflyer,代码行数:12,代码来源:XmlVersionModifierTest.java


注:本文中的org.apache.commons.io.input.XmlStreamReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。