Search in sources :

Example 6 with WriterOutputStream

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);
}
Also used : NFsimSimulationOptions(cbit.vcell.solver.NFsimSimulationOptions) Element(org.jdom.Element) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream)

Example 7 with WriterOutputStream

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));
}
Also used : Col(org.apache.karaf.shell.table.Col) PrintStream(java.io.PrintStream) ShellTable(org.apache.karaf.shell.table.ShellTable) StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Example 8 with WriterOutputStream

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);
    });
}
Also used : StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Reference(org.ambraproject.wombat.model.Reference) OutputStream(java.io.OutputStream) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Document(org.w3c.dom.Document) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream)

Example 9 with WriterOutputStream

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();
}
Also used : StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) IOException(java.io.IOException) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream)

Example 10 with WriterOutputStream

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);
}
Also used : StringWriter(java.io.StringWriter) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Aggregations

WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)149 StringWriter (java.io.StringWriter)142 PrintStream (java.io.PrintStream)137 Test (org.junit.Test)132 LogConfig (io.restassured.config.LogConfig)46 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)44 ResponseBuilder (io.restassured.builder.ResponseBuilder)36 Filter (io.restassured.filter.Filter)35 FilterContext (io.restassured.filter.FilterContext)35 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)35 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)35 IOException (java.io.IOException)6 Col (org.apache.karaf.shell.table.Col)6 ShellTable (org.apache.karaf.shell.table.ShellTable)6 OutputStream (java.io.OutputStream)5 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)4 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)4 InputStream (java.io.InputStream)4 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)3 ScalatraObject (io.restassured.itest.java.objects.ScalatraObject)3