use of javax.xml.stream.XMLOutputFactory in project spring-framework by spring-projects.
the class AbstractMarshallerTests method marshalJaxp14StaxResultEventWriter.
@Test
public void marshalJaxp14StaxResultEventWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
StAXResult result = new StAXResult(eventWriter);
marshaller.marshal(flights, result);
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
}
use of javax.xml.stream.XMLOutputFactory in project CFLint by cflint.
the class DefaultCFlintResultMarshaller method output.
@Override
public void output(BugList bugList, Writer writer, boolean showStats) throws MarshallerException {
try {
final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter xtw = new IndentingXMLStreamWriter(xmlOutputFactory.createXMLStreamWriter(writer));
writeIssues(bugList, xtw, showStats);
xtw.flush();
} catch (XMLStreamException e) {
throw new MarshallerException(e);
}
}
use of javax.xml.stream.XMLOutputFactory in project jqa-core-framework by buschmais.
the class RuleSetWriterImpl method marshal.
private void marshal(Writer writer, JqassistantRules rules) {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter streamWriter = null;
try {
streamWriter = xof.createXMLStreamWriter(writer);
} catch (XMLStreamException e) {
e.printStackTrace();
}
XMLStreamWriter indentingStreamWriter = new IndentingXMLStreamWriter(new CDataXMLStreamWriter(streamWriter));
try {
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.marshal(rules, indentingStreamWriter);
} catch (JAXBException e) {
throw new IllegalArgumentException("Cannot write rules to " + writer, e);
}
}
use of javax.xml.stream.XMLOutputFactory in project webservices-axiom by apache.
the class TestCreateXMLStreamWriterThreadSafety method runTest.
@SuppressWarnings("deprecation")
protected void runTest() throws Throwable {
final XMLOutputFactory factory = staxImpl.getDialect().makeThreadSafe(staxImpl.newNormalizedXMLOutputFactory());
ConcurrentTestUtils.testThreadSafety(new Action() {
public void execute() throws Exception {
String text = String.valueOf((int) (Math.random() * 10000));
StringWriter out = new StringWriter();
XMLStreamWriter writer = factory.createXMLStreamWriter(out);
writer.writeStartElement("root");
writer.writeCharacters(text);
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
writer.close();
assertEquals("<root>" + text + "</root>", out.toString());
}
});
}
use of javax.xml.stream.XMLOutputFactory in project webservices-axiom by apache.
the class TestCreateXMLStreamWriterWithNullEncoding method runTest.
protected void runTest() throws Throwable {
XMLOutputFactory factory = staxImpl.newNormalizedXMLOutputFactory();
// This should cause an exception
try {
factory.createXMLStreamWriter(System.out, null);
} catch (Throwable ex) {
// Expected
return;
}
// Attention here: since the fail method works by throwing an exception and we
// catch Throwable, it must be invoked outside of the catch block!
fail("Expected createXMLStreamWriter to throw an exception");
}
Aggregations