forked from ScottOaks/JavaPerformanceTuning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStAXParserTest.java
More file actions
54 lines (49 loc) · 1.78 KB
/
Copy pathStAXParserTest.java
File metadata and controls
54 lines (49 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Copyright (c) 2013,2014 Scott Oaks. All rights reserved.
*/
package net.sdo;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
public class StAXParserTest extends AbstractParsingTest {
protected XMLInputFactory staxFactory;
@Override
protected void engineInit(RunParams rp) throws IOException {
staxFactory = XMLInputFactory.newInstance();
staxFactory.setProperty (XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
}
@Override
protected void engineRun(InputStream ins) throws IOException {
try {
XMLStreamReader reader = staxFactory.createXMLStreamReader(ins);
while (reader.hasNext()) {
reader.next();
int state = reader.getEventType();
switch (state) {
case XMLStreamConstants.START_ELEMENT:
String s = reader.getLocalName();
if (ITEM_ID.equals(s)) {
isItemID = true;
}
break;
case XMLStreamConstants.CHARACTERS:
if (isItemID) {
String id = reader.getText();
isItemID = false;
if (addItemId(id)) {
return;
}
}
break;
default:
break;
}
}
} catch (XMLStreamException ex) {
throw new IOException("STAX Parsing Exception ", ex);
}
}
}