Example usage for java.io OutputStream toString

List of usage examples for java.io OutputStream toString

Introduction

In this page you can find the example usage for java.io OutputStream toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.zanata.adapter.PropertiesUTF8AdapterTest.java

@Test
public void testTranslatedPropertiesDocument() {
    TranslationsResource tResource = new TranslationsResource();
    addTranslation(tResource, "line1", "Found metalkcta", ContentState.Approved);
    addTranslation(tResource, "line2", "Tbad metalkcta", ContentState.Translated);
    addTranslation(tResource, "line3", "Kbad metalkcta", ContentState.NeedReview);

    Resource resource = parseTestFile("test-properties-utf8.properties");
    File originalFile = new File(resourcePath.concat("test-properties-utf8.properties"));
    OutputStream outputStream = new ByteArrayOutputStream();

    adapter.writeTranslatedFile(outputStream, originalFile.toURI(), resource, tResource, "ru",
            Optional.absent());/*from   www  .j  a  va  2 s .co m*/

    assertThat(outputStream.toString())
            .isEqualTo("line1=Found metalkcta\n" + "line2=Tbad metalkcta\n" + "line3=\n");
}

From source file:pt.ua.tm.neji.web.batch.ServerBatchExecutor.java

@Override
public void run(Class<? extends Processor> processorCls, Context context, Object... args) throws NejiException {

    // Add false positives
    if (service.getFalsePositives() != null) {
        byte[] fpByte = service.getFalsePositives().getBytes();
        context.getConfiguration().setFalsePositives(fpByte);
    } else {/*from  w  w  w .  ja v  a2 s.  co  m*/
        context.getConfiguration().setFalsePositives(null);
    }

    // Add semantic groups normalization (just when exporting, if format 
    // equals to null, then is an annotate)        
    if ((format != null) && !service.getGroupsNormalization().isEmpty()) {
        byte[] gnByte = service.getGroupsNormalizationByteArray();
        context.getConfiguration().setSemanticGroupsNormalization(gnByte);
    } else {
        context.getConfiguration().setSemanticGroupsNormalization(null);
    }

    // Distribution of output streams to the pipeline
    Map<OutputFormat, OutputStream> formatToStreamMap = new HashMap<>();
    List<OutputStream> outputStreams = new ArrayList<>();

    for (OutputFormat f : context.getConfiguration().getOutputFormats()) {
        OutputStream o = new ByteArrayOutputStream();
        formatToStreamMap.put(f, o);
        outputStreams.add(o);
    }

    Processor processor;
    Pipeline p = new DefaultPipeline(corpus);
    try {
        if (args != null && args.length != 0) {
            processor = newProcessor(processorCls, context, inputStream, outputStreams, service, p, groups,
                    filterGroups, args);
        } else {
            processor = newProcessor(processorCls, context, inputStream, outputStreams, service, p, groups,
                    filterGroups);
        }
    } catch (NejiException ex) {
        String m = "There was a problem creating the server processor";
        logger.error(m, ex);
        throw new RuntimeException(m, ex);
    }

    logger.info("");
    logger.info("Started processing a new document...");
    StopWatch timer = new StopWatch();
    timer.start();

    executor.execute(processor);

    try {
        synchronized (processor) {
            processor.wait();
        }
    } catch (InterruptedException ex) {
        throw new RuntimeException("There was a problem running the annotation service.", ex);
    }

    timer.stop();
    logger.info("Processed document in {}", timer.toString());

    if (format != null) {
        OutputStream output = formatToStreamMap.get(format);
        annotatedText = output.toString();
    }
}

From source file:org.opencds.vmr.v1_0.mappings.out.MarshalVMR2VMRSchemaPayload.java

public synchronized String mappingOutbound(Map<String, List<?>> results, DSSRequestKMItem dssRequestKMItem)
        throws InvalidDriDataFormatExceptionFault, UnrecognizedLanguageExceptionFault,
        RequiredDataNotProvidedExceptionFault, UnsupportedLanguageExceptionFault,
        UnrecognizedScopedEntityExceptionFault, EvaluationExceptionFault, InvalidTimeZoneOffsetExceptionFault,
        DSSRuntimeExceptionFault {//  w w  w.jav  a 2s  .c o m
    String interactionId = dssRequestKMItem.getDssRequestDataItem().getInteractionId();
    String requestedKmId = dssRequestKMItem.getRequestedKmId();
    String streamResultString = "";

    log.debug("II: " + interactionId + " KMId: " + requestedKmId + " begin buildVMRSchemaResultSet");
    BuildVMRSchemaResultSet buildVMRSchemaResultSet = BuildVMRSchemaResultSet.getInstance();
    org.opencds.vmr.v1_0.schema.CDSOutput cdsXMLOutput = buildVMRSchemaResultSet.buildResultSet(results,
            dssRequestKMItem);

    log.debug("II: " + interactionId + " KMId: " + requestedKmId + " finish buildVMRSchemaResultSet");
    dssRequestKMItem.getKmTimingData().setFinishBuildOutputTime(new AtomicLong(System.nanoTime()));

    JAXBElement<org.opencds.vmr.v1_0.schema.CDSOutput> jaxbCDSOutput;

    try {
        log.debug("II: " + interactionId + " KMId: " + requestedKmId + " begin factory.createCdsOutput");

        org.opencds.vmr.v1_0.schema.ObjectFactory factory = new org.opencds.vmr.v1_0.schema.ObjectFactory();
        jaxbCDSOutput = factory.createCdsOutput(cdsXMLOutput);

        log.debug("II: " + interactionId + " KMId: " + requestedKmId + " finish factory.createCdsOutput");
    } catch (RuntimeException e) {
        e.printStackTrace();
        throw new DSSRuntimeExceptionFault("RuntimeException in mappingOutbound ObjectFactory cdsOutput: "
                + e.getMessage() + ", vmrOutput=" + cdsXMLOutput.getVmrOutput().toString(), e);
    }

    if ((null == cdsXMLOutput)
            || ((null == cdsXMLOutput.getSimpleOutput()) && (null == cdsXMLOutput.getVmrOutput()))) {
        // show the tags, but empty payload
        streamResultString = "";
        //FIXME          throw new DSSRuntimeExceptionFault("Marshalled Rules Engine results are empty.");

    } else {
        log.debug("II: " + interactionId + " KMId: " + requestedKmId
                + " begin marshalling results to external VMR: "
                + cdsXMLOutput.getVmrOutput().getTemplateId().toString());

        ByteArrayOutputStream output = new ByteArrayOutputStream();
        StreamResult streamResult = new StreamResult();
        streamResult.setOutputStream(output);

        try {
            JAXBContext jaxbContext = SimpleKnowledgeRepository
                    .getRequiredJAXBContextForMarshallerClassCache(this.getClass().getName());

            Marshaller marshaller = SimpleKnowledgeRepository
                    .getRequiredMarshallerInstanceForMarshallerClassCache(this.getClass().getName(),
                            jaxbContext);

            marshaller.marshal(jaxbCDSOutput, streamResult);

        } catch (JAXBException e) {
            e.printStackTrace();
            throw new EvaluationExceptionFault(
                    "JAXBException in mappingOutbound marshalling cdsOutput: " + e.getMessage(), e);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw new DSSRuntimeExceptionFault(
                    "RuntimeException in mappingOutbound marshalling cdsOutput: " + e.getMessage(), e);
        }

        log.debug("II: " + interactionId + " KMId: " + requestedKmId
                + " finished marshalling results to external VMR: "
                + cdsXMLOutput.getVmrOutput().getTemplateId().toString());

        OutputStream outputStream = streamResult.getOutputStream();
        streamResultString = outputStream.toString();

    }

    dssRequestKMItem.getKmTimingData().setFinishMarshalTime(new AtomicLong(System.nanoTime()));

    return streamResultString;
}

From source file:org.sventon.diff.DiffProducerTest.java

@Test
public void testDoNormalDiffNoDiff() throws Exception {
    final String leftString = "More!" + NL + "Even more!" + NL;

    final String rightString = "More!" + NL + "Even more!" + NL;

    final InputStream left = IOUtils.toInputStream(leftString);
    final InputStream right = IOUtils.toInputStream(rightString);

    final DiffProducer diffProducer = new DiffProducer(left, right, null);
    final OutputStream output = new ByteArrayOutputStream();
    diffProducer.doNormalDiff(output);//w ww  .  j  a v  a 2s . c om
    assertEquals("", output.toString());
}

From source file:org.hupo.psi.mi.rdf.BioPaxUriFixer.java

public void fixBioPaxUris(Model model, Writer writer) throws IOException {
    model.getNameSpacePrefixMap().clear();

    Map<String, String> mappings = new HashMap<String, String>();
    mappings.put("psi-mi", "mi");
    mappings.put("rcsb pdb", "pdb");

    fixXrefs(model, mappings);//  w w  w . j a v  a 2s  . co m

    Map<String, String> idMappings = calculateIdMapings(model);

    new Normalizer().normalize(model);

    OutputStream baos = new ByteArrayOutputStream();

    new JenaIOHandler(this.biopaxLevel).convertToOWL(model, baos);

    fixURIs(idMappings, new StringReader(baos.toString()), writer);

    // close OutputStream
    baos.close();
}

From source file:org.sventon.diff.DiffProducerTest.java

@Test
public void testDoNormalDiffIII() throws Exception {
    final String leftString = NL + "test" + NL;
    final String rightString = "test" + NL;
    final String result = "1d1" + NL + "<" + NL;

    final InputStream left = new ByteArrayInputStream(leftString.getBytes());
    final InputStream right = new ByteArrayInputStream(rightString.getBytes());

    final DiffProducer diffProducer = new DiffProducer(left, right, null);
    final OutputStream output = new ByteArrayOutputStream();
    diffProducer.doNormalDiff(output);//w  ww . j ava2 s . co  m
    assertEquals(result, output.toString());
}

From source file:com.groupon.jenkins.buildsetup.GithubRepoAction.java

public String getHtml(ProjectConfigInfo projectConfigInfo)
        throws IOException, ClassNotFoundException, JellyException {
    String name = getClass().getName().replace('.', '/').replace('$', '/') + "/" + "index.jelly";
    URL actionTemplate = getClass().getClassLoader().getResource(name);
    JellyContext context = new JellyContext();
    context.setVariable("p", projectConfigInfo);
    context.setVariable("it", this);
    OutputStream outputStream = new ByteArrayOutputStream();
    XMLOutput output = XMLOutput.createXMLOutput(outputStream);
    context.runScript(actionTemplate, output);
    output.flush();//from  w w  w .  j a va2 s . co m
    return "<p>" + outputStream.toString() + " </p>";
}

From source file:org.duracloud.stitch.stream.MultiContentInputStreamTest.java

@Test
public void testReadWithoutListener() throws Exception {
    String text = createReadMocks();
    replayMocks();/*from  w ww.j  av  a 2s.c  o  m*/

    OutputStream out = new ByteArrayOutputStream();

    multiStream = new MultiContentInputStream(dataSource, contentItems);
    IOUtils.copy(multiStream, out);
    Assert.assertEquals(text, out.toString());
    out.close();
}

From source file:fi.mystes.synapse.mediator.util.XslTransformer.java

/**
 * Performs XML transformation with given XSL.
 * //from   w w  w .  j  ava  2 s .c  om
 * @param xml Content to transform
 * @param xsl Transformation style sheet
 * 
 * @return Transformed content
 */
public String transform(String xml, String xsl) {
    log.info("Starting XML content transformation");
    try {
        DOMSource source = createDomSource(xml);

        Transformer xslTransformer = createTransformerFor(xsl);

        final OutputStream outputStream = new ByteArrayOutputStream();
        Result result = new StreamResult(outputStream);

        xslTransformer.transform(source, result);

        return outputStream.toString();

    } catch (Exception e) {
        log.error(e);
        return "";
    }
}

From source file:org.sventon.diff.DiffProducerTest.java

@Test
public void testDoUnifiedDiffNoGutter() throws Exception {
    final String leftString = "[.ShellClassInfo]" + NL + "IconIndex=-238" + NL + "[DeleteOnCopy]" + NL
            + "Owner=Jesper" + NL + "Owner=Patrik&Jesper" + NL + "Personalized=14" + NL
            + "PersonalizedName=Mina videoklipp" + NL;

    final String rightString = "[.ShellClassInfo]" + NL + "IconIndex=-2388" + NL + "[DeleteOnCopy]" + NL
            + "Owner=Jesper" + NL + "Owner=Patrik&Jesper" + NL + "Personalized=14" + NL
            + "PersonalizedName=Mina videoklipp" + NL + "OneMore=true" + NL + "OneMore=1" + NL + "OneMore=2"
            + NL + "OneMore=3" + NL + NL;

    final String result = "@@ -2 +2 @@" + NL + "-IconIndex=-238" + NL + "+IconIndex=-2388" + NL
            + "@@ -8 +8,5 @@" + NL + "+OneMore=true" + NL + "+OneMore=1" + NL + "+OneMore=2" + NL + "+OneMore=3"
            + NL + "+" + NL;

    final InputStream left = IOUtils.toInputStream(leftString);
    final InputStream right = IOUtils.toInputStream(rightString);

    final Map props = new HashMap();
    //noinspection unchecked
    props.put(QDiffGeneratorFactory.GUTTER_PROPERTY, 0);
    final DiffProducer diffProducer = new DiffProducer(left, right, null, props);
    final OutputStream output = new ByteArrayOutputStream();
    diffProducer.doUnifiedDiff(output);/* w w w .j  a  v a  2s  .  c o  m*/
    assertEquals(result, output.toString());
}