本文整理汇总了Java中javax.xml.stream.XMLStreamReader.close方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader.close方法的具体用法?Java XMLStreamReader.close怎么用?Java XMLStreamReader.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLStreamReader
的用法示例。
在下文中一共展示了XMLStreamReader.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isCim14
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
private static boolean isCim14(InputStream is) throws XMLStreamException {
// check the first root element is RDF and the second one belongs to CIM 14 namespace
XMLStreamReader xmlsr = XML_INPUT_FACTORY_SUPPLIER.get().createXMLStreamReader(is);
try {
int elemIndex = 0;
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
if (eventType == XMLEvent.START_ELEMENT) {
String ns = xmlsr.getNamespaceURI();
if (elemIndex == 0) {
if (!RDF_NS.equals(ns)) {
return false;
}
} else if (elemIndex == 1) {
return CIM14_NS.equals(ns);
} else {
throw new AssertionError();
}
elemIndex++;
}
}
} finally {
xmlsr.close();
}
return false;
}
示例2: testAttributeCountNS
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testAttributeCountNS() {
XMLInputFactory ifac = XMLInputFactory.newInstance();
try {
// Turn on NS awareness to not count xmlns as attributes
ifac.setProperty("javax.xml.stream.isNamespaceAware", Boolean.TRUE);
XMLStreamReader re = ifac.createXMLStreamReader(getClass().getResource(INPUT_FILE1).toExternalForm(),
this.getClass().getResourceAsStream(INPUT_FILE1));
while (re.hasNext()) {
int event = re.next();
if (event == XMLStreamConstants.START_ELEMENT) {
// System.out.println("#attrs = " + re.getAttributeCount());
Assert.assertTrue(re.getAttributeCount() == 1);
}
}
re.close();
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception occured: " + e.getMessage());
}
}
示例3: testXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testXml() throws IOException, XMLStreamException {
String xml = "<?xml version=\"1.0\" ?><index name=\"transient\"><j>0.5</j></index>";
XMLInputFactory xmlif = XMLInputFactory.newInstance();
TransientSecurityIndex index;
try (Reader reader = new StringReader(xml)) {
XMLStreamReader xmlReader = xmlif.createXMLStreamReader(reader);
try {
index = TransientSecurityIndex.fromXml("c1", xmlReader);
} finally {
xmlReader.close();
}
}
assertTrue(index.getJ() == 0.5d);
assertEquals(xml, index.toXml());
}
示例4: testXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testXml() throws IOException, XMLStreamException {
String xml = "<?xml version=\"1.0\" ?><index name=\"tso-generator-speed-automaton\"><onUnderSpeedDisconnectedGenerators><gen>a</gen><gen>b</gen></onUnderSpeedDisconnectedGenerators><onOverSpeedDisconnectedGenerators><gen>c</gen></onOverSpeedDisconnectedGenerators></index>";
XMLInputFactory xmlif = XMLInputFactory.newInstance();
TsoGeneratorSpeedAutomaton index;
try (Reader reader = new StringReader(xml)) {
XMLStreamReader xmlReader = xmlif.createXMLStreamReader(reader);
try {
index = TsoGeneratorSpeedAutomaton.fromXml("c1", xmlReader);
} finally {
xmlReader.close();
}
}
assertTrue(index.getOnUnderSpeedDiconnectedGenerators().equals(Arrays.asList("a", "b")));
assertTrue(index.getOnOverSpeedDiconnectedGenerators().equals(Arrays.asList("c")));
assertEquals(xml, index.toXml());
}
示例5: testXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testXml() throws IOException, XMLStreamException {
String xml = "<?xml version=\"1.0\" ?><index name=\"tso-frequency\"><freq-out-count>1</freq-out-count></index>";
XMLInputFactory xmlif = XMLInputFactory.newInstance();
TsoFrequencySecurityIndex index;
try (Reader reader = new StringReader(xml)) {
XMLStreamReader xmlReader = xmlif.createXMLStreamReader(reader);
try {
index = TsoFrequencySecurityIndex.fromXml("c1", xmlReader);
} finally {
xmlReader.close();
}
}
assertTrue(index.getFreqOutCount() == 1);
assertEquals(xml, index.toXml());
}
示例6: testXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testXml() throws IOException, XMLStreamException {
String xml = "<?xml version=\"1.0\" ?><index name=\"underovervoltage\"><vx>0.5</vx></index>";
XMLInputFactory xmlif = XMLInputFactory.newInstance();
UnderOverVoltageSecurityIndex index;
try (Reader reader = new StringReader(xml)) {
XMLStreamReader xmlReader = xmlif.createXMLStreamReader(reader);
try {
index = UnderOverVoltageSecurityIndex.fromXml("c1", xmlReader);
} finally {
xmlReader.close();
}
}
assertTrue(index.getIndexValue() == 0.5d);
assertEquals(xml, index.toXml());
}
示例7: testXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testXml() throws IOException, XMLStreamException {
String xml = "<?xml version=\"1.0\" ?><index name=\"smallsignal\"><matrix name=\"gmi\"><m><r>0.5</r></m></matrix><matrix name=\"ami\"><m><r>1.0 2.0</r></m></matrix><matrix name=\"smi\"><m><r>3.0 4.0</r><r>5.0 6.0</r></m></matrix></index>";
XMLInputFactory xmlif = XMLInputFactory.newInstance();
SmallSignalSecurityIndex index;
try (Reader reader = new StringReader(xml)) {
XMLStreamReader xmlReader = xmlif.createXMLStreamReader(reader);
try {
index = SmallSignalSecurityIndex.fromXml("c1", xmlReader);
} finally {
xmlReader.close();
}
}
assertTrue(index.getGmi() == 0.5d);
assertTrue(Arrays.equals(index.getAmi(), new double[] {1, 2}));
assertTrue(Arrays.deepEquals(index.getSmi(), new double[][] {new double[] {3, 4}, new double[] {5, 6}}));
assertEquals(xml, index.toXml());
}
示例8: test0
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void test0() {
try {
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLStreamReader xsr = xif.createXMLStreamReader(getClass().getResource("sgml.xml").toString(), getClass().getResourceAsStream("sgml.xml"));
XMLEventReader xer = xif.createXMLEventReader(xsr);
Assert.assertTrue(xer.peek().getEventType() == XMLEvent.START_DOCUMENT);
Assert.assertTrue(xer.peek() == xer.nextEvent());
xsr.close();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
示例9: testAttributeCountNoNS
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testAttributeCountNoNS() {
XMLInputFactory ifac = XMLInputFactory.newInstance();
try {
// Turn off NS awareness to count xmlns as attributes
ifac.setProperty("javax.xml.stream.isNamespaceAware", Boolean.FALSE);
XMLStreamReader re = ifac.createXMLStreamReader(getClass().getResource(INPUT_FILE1).toExternalForm(),
this.getClass().getResourceAsStream(INPUT_FILE1));
while (re.hasNext()) {
int event = re.next();
if (event == XMLStreamConstants.START_ELEMENT) {
// System.out.println("#attrs = " + re.getAttributeCount());
Assert.assertTrue(re.getAttributeCount() == 3);
}
}
re.close();
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception occured: " + e.getMessage());
}
}
示例10: testXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testXml() throws IOException, XMLStreamException {
String xml = "<?xml version=\"1.0\" ?><index name=\"overload\"><fx>0.5</fx></index>";
XMLInputFactory xmlif = XMLInputFactory.newInstance();
OverloadSecurityIndex index;
try (Reader reader = new StringReader(xml)) {
XMLStreamReader xmlReader = xmlif.createXMLStreamReader(reader);
try {
index = OverloadSecurityIndex.fromXml("c1", xmlReader);
} finally {
xmlReader.close();
}
}
assertTrue(index.getIndexValue() == 0.5d);
assertEquals(xml, index.toXml());
}
示例11: readWrappedRequest
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
protected void readWrappedRequest(Message msg, Object[] args) throws JAXBException, XMLStreamException {
if (!msg.hasPayload()) {
throw new WebServiceException("No payload. Expecting payload with "+wrapperName+" element");
}
XMLStreamReader reader = msg.readPayload();
XMLStreamReaderUtil.verifyTag(reader,wrapperName);
reader.nextTag();
while(reader.getEventType()==XMLStreamReader.START_ELEMENT) {
// TODO: QName has a performance issue
QName name = reader.getName();
WrappedPartBuilder part = wrappedParts.get(name);
if(part==null) {
// no corresponding part found. ignore
XMLStreamReaderUtil.skipElement(reader);
reader.nextTag();
} else {
part.readRequest(args,reader, msg.getAttachments());
}
XMLStreamReaderUtil.toNextTag(reader, name);
}
// we are done with the body
reader.close();
XMLStreamReaderFactory.recycle(reader);
}
示例12: close
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static void close(XMLStreamReader reader) {
try {
reader.close();
} catch (XMLStreamException e) {
throw wrapException(e);
}
}
示例13: closeResource
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
* If the {@code reader} is not {@code null}, this method will try to close the
* {@code reader} instance and log warning about any unexpected
* {@link IOException} that may occur.
*
* @param reader resource to be closed
*/
public static void closeResource(XMLStreamReader reader) {
if (reader != null) {
try {
reader.close();
} catch (XMLStreamException e) {
LOGGER.warning(LocalizationMessages.WSP_0023_UNEXPECTED_ERROR_WHILE_CLOSING_RESOURCE(reader.toString()), e);
}
}
}
示例14: readXces
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
* Read XML data in <a href="http://www.xces.org/">XCES</a> format
* from the given stream and add the corresponding annotations to the
* given annotation set. This method does not close the stream, this
* is the responsibility of the caller.
*
* @param is the input stream to read from, which will <b>not</b> be
* closed before returning.
* @param as the annotation set to read into.
*/
public static void readXces(InputStream is, AnnotationSet as)
throws XMLStreamException {
if(inputFactory == null) {
inputFactory = XMLInputFactory.newInstance();
}
XMLStreamReader xsr = inputFactory.createXMLStreamReader(is);
try {
nextTagSkipDTD(xsr);
readXces(xsr, as);
}
finally {
xsr.close();
}
}
示例15: run
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public void run() {
try {
FileOutputStream fos = new FileOutputStream(USER_DIR + no);
XMLStreamWriter w = getWriter(fos);
// System.out.println("Writer="+w+" Thread="+Thread.currentThread());
w.writeStartDocument();
w.writeStartElement("hello");
for (int j = 0; j < 50; j++) {
w.writeStartElement("a" + j);
w.writeEndElement();
}
w.writeEndElement();
w.writeEndDocument();
w.close();
fos.close();
FileInputStream fis = new FileInputStream(USER_DIR + no);
XMLStreamReader r = getReader(fis);
while (r.hasNext()) {
r.next();
}
r.close();
fis.close();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}