本文整理匯總了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());
}
}