use of javax.xml.transform.stream.StreamResult in project spring-framework by spring-projects.
the class XStreamMarshallerTests method marshalStreamResultOutputStream.
@Test
public void marshalStreamResultOutputStream() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
StreamResult result = new StreamResult(os);
marshaller.marshal(flight, result);
String s = new String(os.toByteArray(), "UTF-8");
assertThat("Marshaller writes invalid StreamResult", s, isSimilarTo(EXPECTED_STRING));
}
use of javax.xml.transform.stream.StreamResult in project dbeaver by serge-rider.
the class DBDDocumentXML method serializeDocument.
@Override
public void serializeDocument(@NotNull DBRProgressMonitor monitor, @NotNull OutputStream stream, String encoding) throws DBException {
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Result output = new StreamResult(new OutputStreamWriter(stream, encoding));
transformer.transform(new DOMSource(document), output);
} catch (Exception e) {
throw new DBException("Error serializing XML document", e);
}
}
use of javax.xml.transform.stream.StreamResult in project nokogiri by sparklemotion.
the class XmlRelaxng method getSchema.
private Schema getSchema(Source source, ThreadContext context) {
InputStream is;
VerifierFactory factory = new com.thaiopensource.relaxng.jarv.VerifierFactoryImpl();
if (source instanceof StreamSource) {
StreamSource ss = (StreamSource) source;
is = ss.getInputStream();
} else {
//if (this.source instanceof DOMSource)
DOMSource ds = (DOMSource) source;
StringWriter xmlAsWriter = new StringWriter();
StreamResult result = new StreamResult(xmlAsWriter);
try {
TransformerFactory.newInstance().newTransformer().transform(ds, result);
} catch (TransformerConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (TransformerException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
try {
is = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
}
try {
return factory.compileSchema(is);
} catch (VerifierConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (SAXException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (IOException ex) {
throw context.getRuntime().newIOError(ex.getMessage());
}
}
use of javax.xml.transform.stream.StreamResult in project nokogiri by sparklemotion.
the class XsltStylesheet method retryXsltTransformation.
private String retryXsltTransformation(ThreadContext context, IRubyObject[] args, DOMSource domSource, NokogiriXsltErrorListener elistener) throws TransformerException, IOException {
Templates templates = getTemplatesFromStreamSource();
Transformer transf = templates.newTransformer();
transf.setErrorListener(elistener);
if (args.length > 1) {
addParametersToTransformer(context, transf, args[1]);
}
PipedWriter pwriter = new PipedWriter();
PipedReader preader = new PipedReader();
pwriter.connect(preader);
StreamResult result = new StreamResult(pwriter);
transf.transform(domSource, result);
char[] cbuf = new char[1024];
int len = preader.read(cbuf, 0, 1024);
StringBuilder builder = new StringBuilder(len);
builder.append(cbuf, 0, len);
// judge from the first chunk
htmlish = isHtml(builder);
while (len == 1024) {
len = preader.read(cbuf, 0, 1024);
if (len > 0) {
builder.append(cbuf, 0, len);
}
}
preader.close();
pwriter.close();
return builder.toString();
}
use of javax.xml.transform.stream.StreamResult in project camel by apache.
the class XQueryBuilder method evaluateAsBytes.
public byte[] evaluateAsBytes(Exchange exchange) throws Exception {
LOG.debug("evaluateAsBytes: {} for exchange: {}", expression, exchange);
initialize(exchange);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
Result result = new StreamResult(buffer);
getExpression().pull(createDynamicContext(exchange), result, properties);
byte[] answer = buffer.toByteArray();
buffer.close();
return answer;
}
Aggregations