个ByteArrayOutputStream

个ByteArrayOutputStream

我需要合并两个ByteArrayOutputStream并传递给xdo api TemplateHelper.processTemplate来生成报告

编写以下代码以在两个ByteArrayOutputStreams中获取xml输出-

ByteArrayOutputStream hdrclob = new ByteArrayOutputStream (1024);

hdrclob = (ByteArrayOutputStream)this.getDataTemplateXML(transaction,"ASO",
                      "ASOPD",parameters1,null);

ByteArrayOutputStream conclob = new ByteArrayOutputStream (1024);

ContractTermsXMLGenerator.writeXML(PrintQuote,(OutputStream) conclob, true,
            documentType, new Number(params[8]), new Number("0"));


现在将hdrclob / conclob分别传递给xdo api,然后能够在这样的单独报告中看到相应的xml输出-

TemplateHelper.processTemplate(((OADBTransactionImpl)transaction).getAppsContext(),
        "ASO", "SampleRTF", language, country,
         new ByteArrayInputStream(hdrclob.toByteArray()),
           TemplateHelper.OUTPUT_TYPE_PDF, new Properties(), pdf);


要么

TemplateHelper.processTemplate(((OADBTransactionImpl)transaction).getAppsContext(),
         "ASO", "SampleRTF", language, country,
         new ByteArrayInputStream(conclob.toByteArray()),
           TemplateHelper.OUTPUT_TYPE_PDF, new Properties(), pdf);


但是需要合并hdrclob和conclob以生成单个ByteArrayOutputStream并传递给xdo api以获取包含两个xml输出的单个报告

请告诉如何合并两个ByteArrayOutputStreams

感谢您对此的回复

最佳答案

假设这是Java,只需将一个流写入另一个流的末尾。

hdrclob.write(conclob.toByteArray());
// hdrclob.toByteArray() now returns the concatenation of the two streams


如果只想按单个InputStream顺序读取它们,则可以构造将所有两个输入流连接在一起的SequenceInputStream

InputStream everything = new SequenceInputStream(
    new ByteArrayInputStream(hdrclob.toByteArray()),
    new ByteArrayInputStream(conclob.toByteArray()));
// now read everything

10-01 07:59