當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLEventReader.close方法代碼示例

本文整理匯總了Java中javax.xml.stream.XMLEventReader.close方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLEventReader.close方法的具體用法?Java XMLEventReader.close怎麽用?Java XMLEventReader.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.stream.XMLEventReader的用法示例。


在下文中一共展示了XMLEventReader.close方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: xmlToJson

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
void xmlToJson(InputStream xmlInput, OutputStream jsonOutput) throws XMLStreamException
{
   JsonXMLConfig config = new JsonXMLConfigBuilder()
         .autoArray(true)
         .autoPrimitive(false)
         .fieldPrefix("")
         .contentField("content")
         .build();
   
   XMLEventReader reader = XMLInputFactory.newInstance().createXMLEventReader(xmlInput);
   XMLEventWriter writer = new JsonXMLOutputFactory(config).createXMLEventWriter(jsonOutput);
   
   writer.add(reader);
   
   reader.close();
   writer.close();
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:18,代碼來源:SearchController.java

示例2: unmarshal

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
public JaxbRoot unmarshal(InputStream stream, Origin origin) {
	try {
		XMLEventReader staxReader = staxFactory().createXMLEventReader( stream );
		try {
			return unmarshal( staxReader, origin );
		}
		finally {
			try {
				staxReader.close();
			}
			catch ( Exception ignore ) {
			}
		}
	}
	catch ( XMLStreamException e ) {
		throw new MappingException( "Unable to create stax reader", e, origin );
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:JaxbHelper.java

示例3: unmarshal

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
public JaxbHibernateConfiguration unmarshal(InputStream stream, Origin origin) {
	try {
		XMLEventReader staxReader = staxFactory().createXMLEventReader( stream );
		try {
			return unmarshal( staxReader, origin );
		}
		finally {
			try {
				staxReader.close();
			}
			catch ( Exception ignore ) {
			}
		}
	}
	catch ( XMLStreamException e ) {
		throw new MappingException( "Unable to create stax reader", e, origin );
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:JaxbProcessor.java

示例4: eventReaderTest

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
public void eventReaderTest(XMLInputFactory xif) {
    XMLEventReader eventReader = null;
    try {
        eventReader = xif.createXMLEventReader(this.getClass().getResourceAsStream(INPUT_FILE));
        XMLEventReader filteredEventReader = xif.createFilteredReader(eventReader, new EventFilter() {
            public boolean accept(XMLEvent event) {
                if (!event.isStartElement()) {
                    return false;
                }
                QName elementQName = event.asStartElement().getName();
                if ((elementQName.getLocalPart().equals(ATTACHMENT_NAME.getLocalPart()) || elementQName.getLocalPart().equals("Attachment"))
                        && elementQName.getNamespaceURI().equals(VF_GENERIC_TT_NAMESPACE)) {
                    return true;
                }
                return false;
            }
        });
        if (filteredEventReader.hasNext()) {
            System.out.println("containsAttachments() returns true");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());

    } finally {
        if (eventReader != null) {
            try {
                eventReader.close();
            } catch (XMLStreamException xse) {
                // Ignored by intention
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:Bug6976938Test.java

示例5: testCR6419687

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
/**
 * Test: 6419687 NPE in XMLEventWriterImpl.
 */
@Test
public void testCR6419687() {

    try {
        InputStream in = getClass().getResourceAsStream("ReaderToWriterTest.wsdl");
        OutputStream out = new FileOutputStream(USER_DIR + "ReaderToWriterTest-out.xml");

        XMLEventReader reader = XML_INPUT_FACTORY.createXMLEventReader(in);
        XMLEventWriter writer = XML_OUTPUT_FACTORY.createXMLEventWriter(out, "UTF-8");
        while (reader.hasNext()) {
            XMLEvent event = reader.nextEvent();
            writer.add(event);
        }
        reader.close();
        writer.close();
    } catch (XMLStreamException xmlStreamException) {
        xmlStreamException.printStackTrace();
        Assert.fail(xmlStreamException.toString());
    } catch (FileNotFoundException fileNotFoundException) {
        fileNotFoundException.printStackTrace();
        Assert.fail(fileNotFoundException.toString());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:ReaderToWriterTest.java

示例6: readMappingDocument

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
public XmlDocument readMappingDocument(InputSource source, Origin origin) {
	XMLEventReader staxReader = buildStaxEventReader( source, origin );
	try {
		return read( staxReader, origin );
	}
	finally {
		try {
			staxReader.close();
		}
		catch ( Exception ignore ) {
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:MappingReader.java

示例7: writeEvents

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
private void writeEvents(XMLEventReader reader, XMLEventWriter writer) throws XMLStreamException {
    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        writer.add(event);
    }
    reader.close();
    writer.close();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:ReaderToWriterTest.java

示例8: checkOutput

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
private void checkOutput(String output) throws Exception {
    InputStream in = new FileInputStream(output);
    XMLEventReader reader = XML_INPUT_FACTORY.createXMLEventReader(in);
    while (reader.hasNext()) {
        reader.next();
    }
    reader.close();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:ReaderToWriterTest.java

示例9: set

import javax.xml.stream.XMLEventReader; //導入方法依賴的package包/類
public void set ( final String expression, final int targetElement, final String value ) throws IOException, XMLStreamException
{
    int pos = 0;

    final Stack<String> ele = new Stack<> ();

    final Pattern pattern = Pattern.compile ( expression );

    final XMLEventReader reader;

    Modification mod = null;

    final XMLInputFactory xmlinf = XMLInputFactory.newInstance ();
    try (final FileInputStream is = new FileInputStream ( this.inputFile ))
    {
        reader = xmlinf.createXMLEventReader ( is );
        try
        {
            while ( reader.hasNext () )
            {
                final XMLEvent event = (XMLEvent)reader.next ();
                if ( event instanceof StartElement )
                {
                    final StartElement startEvent = event.asStartElement ();
                    ele.push ( startEvent.getName ().getLocalPart () );
                }
                else if ( event instanceof EndElement )
                {
                    final EndElement endEvent = event.asEndElement ();
                    final String en = ele.pop ();
                    if ( !endEvent.getName ().getLocalPart ().equals ( en ) )
                    {
                        throw new IllegalStateException ( "Element error: " + en + " / " + endEvent.getName () );
                    }
                }

                boolean inMatch = mod != null;
                final boolean match = isMatch ( ele, pattern );
                if ( inMatch && !match )
                {
                    // end
                    if ( pos == targetElement )
                    {
                        this.mods.add ( mod );
                    }
                    pos++;
                    mod = null;
                }
                else if ( !inMatch && match )
                {
                    // starting
                    mod = new Modification ();
                    mod.start = event.getLocation ().getCharacterOffset ();
                    mod.data = value;
                }
                else if ( inMatch && match )
                {
                    mod.end = event.getLocation ().getCharacterOffset () - 2;
                }
                inMatch = match;
            }
        }
        finally
        {
            reader.close ();
        }
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:69,代碼來源:XmlModifier.java


注:本文中的javax.xml.stream.XMLEventReader.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。