use of org.apache.commons.io.output.WriterOutputStream in project vcell by virtualcell.
the class NFSimFileWriter method write.
@Override
public void write(String[] parameterNames) throws Exception {
WriterOutputStream wos = new WriterOutputStream(printWriter);
NFsimSimulationOptions nfsimSimulationOptions = simTask.getSimulation().getSolverTaskDescription().getNFSimSimulationOptions();
boolean bUseLocationMarks = true;
Element root = NFsimXMLWriter.writeNFsimXML(simTask, randomSeed, nfsimSimulationOptions, bUseLocationMarks);
if (bUseMessaging) {
Element jms = super.xmlJMSParameters();
root.addContent(jms);
}
// String resultString = XmlUtil.xmlToString(root);
// resultString = XmlUtil.beautify(resultString);
// resultString = resultString.replaceAll("DeleteMolecules=\"0\"", "DeleteMolecules=\"1\"");
//
// System.out.println(resultString);
//
// StringReader stringReader = new StringReader(resultString); // transform back to element
// SAXBuilder builder = new SAXBuilder();
// Document doc1 = builder.build(stringReader);
// Element root1 = doc1.getRootElement();
// XmlUtil.writeXmlToStream(root1, false, wos); // modified
// original
XmlUtil.writeXmlToStream(root, false, wos);
}
use of org.apache.commons.io.output.WriterOutputStream in project karaf by apache.
the class ShellTableTest method testTooSmall.
@Test
public void testTooSmall() {
ShellTable table = new ShellTable().size(2);
table.column(new Col("1").maxSize(5));
table.column(new Col("2").alignRight());
table.addRow().addContent("quite long", "and here an even longer text");
StringWriter writer = new StringWriter();
PrintStream out = new PrintStream(new WriterOutputStream(writer));
table.print(out, true);
out.flush();
//
String expected = //
"1 | \n" + //
"--------\n" + "quite | \n";
Assert.assertEquals(expected, getString(writer));
}
use of org.apache.commons.io.output.WriterOutputStream in project wombat by PLOS.
the class ArticleController method getXmlContent.
/**
* Gets article xml from cache if it exists; otherwise, gets it from rhino and caches it. Then it parses the
* references and does html transform
*
* @param articlePointer
* @param request
* @return an XmlContent containing the list of references and article html
* @throws IOException
*/
private XmlContent getXmlContent(Site site, ArticlePointer articlePointer, HttpServletRequest request) throws IOException {
return corpusContentApi.readManuscript(articlePointer, site, "html", (InputStream stream) -> {
byte[] xml = ByteStreams.toByteArray(stream);
final Document document = parseXmlService.getDocument(new ByteArrayInputStream(xml));
List<Reference> references = parseXmlService.parseArticleReferences(document, doi -> getLinkText(site, request, doi));
StringWriter articleHtml = new StringWriter(XFORM_BUFFER_SIZE);
try (OutputStream outputStream = new WriterOutputStream(articleHtml, charset)) {
articleTransformService.transformArticle(site, articlePointer, references, new ByteArrayInputStream(xml), outputStream);
}
return new XmlContent(articleHtml.toString(), references);
});
}
use of org.apache.commons.io.output.WriterOutputStream in project wombat by PLOS.
the class ArticleTransformServiceImpl method transformExcerpt.
/**
* Enclose an excerpt from article XML in a tag pair, then transform the created element into presentation HTML using
* the XSL transformation specified for a site.
*
* @param site the site on which the excerpt will be rendered
* @param xmlExcerpt the XML code to transform
* @return the presentation HTML
* @throws TransformerException if an error occurs when applying the transformation
*/
private String transformExcerpt(Site site, String xmlExcerpt, TransformerInitializer initialization) {
Objects.requireNonNull(site);
Objects.requireNonNull(xmlExcerpt);
StringWriter html = new StringWriter();
OutputStream outputStream = new WriterOutputStream(html, charset);
InputStream inputStream = IOUtils.toInputStream(xmlExcerpt, charset);
try {
transform(site, inputStream, outputStream, initialization);
// to flush (StringWriter doesn't require a finally block)
outputStream.close();
} catch (IOException e) {
// unexpected, since both streams are in memory
throw new RuntimeException(e);
}
return html.toString();
}
use of org.apache.commons.io.output.WriterOutputStream in project pwm by pwm-project.
the class ReportServiceTest method testOutputToCsv_onlyUserDnColumn.
@Test
public void testOutputToCsv_onlyUserDnColumn() throws Exception {
// Set the desired filters
ReportColumnFilter columnFilter = new ReportColumnFilter();
columnFilter.setUserDnVisible(true);
// Test the reportService.outputToCsv method()
StringWriter outputWriter = new StringWriter();
reportService.outputToCsv(new WriterOutputStream(outputWriter), true, Locale.ENGLISH, configuration, columnFilter);
// Verify the results
String actual = outputWriter.toString().replaceAll("\r", "");
String expected = IOUtils.toString(getClass().getResourceAsStream("allUserRecordsReport-onlyUserDnColumn.csv")).replaceAll("\r", "");
assertEqualsIgnoreLineEndings(actual, expected);
}
Aggregations