我需要合并两个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 输出的单个报告
请告诉如何合并两个ByteArrayOutputStream
感谢您对此的回复
最佳答案
假设这是 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
关于java - 需要合并两个 ByteArrayOutputStream 以生成单个 ByteArrayOutputStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17564021/