use of javax.xml.stream.XMLInputFactory in project hibernate-orm by hibernate.
the class AbstractBinder method buildStaxFactory.
@SuppressWarnings({ "UnnecessaryLocalVariable" })
private XMLInputFactory buildStaxFactory() {
XMLInputFactory staxFactory = XMLInputFactory.newInstance();
staxFactory.setXMLResolver(xmlResourceResolver);
return staxFactory;
}
use of javax.xml.stream.XMLInputFactory in project camel by apache.
the class StAXJAXBIteratorExpression method evaluate.
@Override
@SuppressWarnings("unchecked")
public Object evaluate(Exchange exchange) {
try {
XMLEventReader reader;
if (isNamespaceAware) {
reader = exchange.getIn().getMandatoryBody(XMLEventReader.class);
} else {
InputStream inputStream = exchange.getIn().getMandatoryBody(InputStream.class);
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
reader = xmlInputFactory.createXMLEventReader(inputStream);
}
Class<T> clazz = handled;
if (clazz == null && handledName != null) {
clazz = (Class<T>) exchange.getContext().getClassResolver().resolveMandatoryClass(handledName);
}
return createIterator(reader, clazz);
} catch (InvalidPayloadException e) {
exchange.setException(e);
return null;
} catch (JAXBException e) {
exchange.setException(e);
return null;
} catch (ClassNotFoundException e) {
exchange.setException(e);
return null;
} catch (XMLStreamException e) {
exchange.setException(e);
return null;
}
}
use of javax.xml.stream.XMLInputFactory in project hudson-2.x by hudson.
the class ExternalRun method acceptRemoteSubmission.
/**
* Instead of performing a build, accept the log and the return code
* from a remote machine.
*
* <p>
* The format of the XML is:
*
* <pre><xmp>
* <run>
* <log>...console output...</log>
* <result>exit code</result>
* </run>
* </xmp></pre>
*/
@SuppressWarnings({ "Since15" })
@IgnoreJRERequirement
public void acceptRemoteSubmission(final Reader in) throws IOException {
final long[] duration = new long[1];
run(new Runner() {
private String elementText(XMLStreamReader r) throws XMLStreamException {
StringBuilder buf = new StringBuilder();
while (true) {
int type = r.next();
if (type == CHARACTERS || type == CDATA)
buf.append(r.getTextCharacters(), r.getTextStart(), r.getTextLength());
else
return buf.toString();
}
}
public Result run(BuildListener listener) throws Exception {
PrintStream logger = new PrintStream(new DecodingStream(listener.getLogger()));
XMLInputFactory xif = XMLInputFactory.newInstance();
XMLStreamReader p = xif.createXMLStreamReader(in);
// get to the <run>
p.nextTag();
// get to the <log>
p.nextTag();
charset = p.getAttributeValue(null, "content-encoding");
while (p.next() != END_ELEMENT) {
int type = p.getEventType();
if (type == CHARACTERS || type == CDATA)
logger.print(p.getText());
}
// get to <result>
p.nextTag();
Result r = Integer.parseInt(elementText(p)) == 0 ? Result.SUCCESS : Result.FAILURE;
// get to <duration> (optional)
p.nextTag();
if (p.getEventType() == START_ELEMENT && p.getLocalName().equals("duration")) {
duration[0] = Long.parseLong(elementText(p));
}
return r;
}
public void post(BuildListener listener) {
// do nothing
}
public void cleanUp(BuildListener listener) {
// do nothing
}
});
if (duration[0] != 0) {
super.duration = duration[0];
// save the updated duration
save();
}
}
use of javax.xml.stream.XMLInputFactory in project graphhopper by graphhopper.
the class OSMInputFile method openXMLStream.
private void openXMLStream(InputStream in) throws XMLStreamException {
XMLInputFactory factory = XMLInputFactory.newInstance();
parser = factory.createXMLStreamReader(in, "UTF-8");
int event = parser.next();
if (event != XMLStreamConstants.START_ELEMENT || !parser.getLocalName().equalsIgnoreCase("osm")) {
throw new IllegalArgumentException("File is not a valid OSM stream");
}
// See https://wiki.openstreetmap.org/wiki/PBF_Format#Definition_of_the_OSMHeader_fileblock
String timestamp = parser.getAttributeValue(null, "osmosis_replication_timestamp");
if (timestamp == null)
timestamp = parser.getAttributeValue(null, "timestamp");
if (timestamp != null) {
try {
fileheader = new OSMFileHeader();
fileheader.setTag("timestamp", timestamp);
} catch (Exception ex) {
}
}
eof = false;
}
use of javax.xml.stream.XMLInputFactory in project robovm by robovm.
the class InterfaceBuilderClassesPlugin method findCustomClassesInIBFile.
private List<String> findCustomClassesInIBFile(File file) throws XMLStreamException, IOException {
List<String> customClasses = new ArrayList<>();
try (FileInputStream fis = FileUtils.openInputStream(file)) {
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader reader = factory.createXMLStreamReader(fis);
while (reader.hasNext()) {
int event = reader.next();
switch(event) {
case XMLStreamConstants.START_ELEMENT:
String customClass = reader.getAttributeValue(null, "customClass");
if (customClass != null && !customClass.trim().isEmpty()) {
customClasses.add(customClass);
}
}
}
reader.close();
}
return customClasses;
}
Aggregations