This discussion is archived
1 Reply Latest reply: Dec 14, 2012 9:45 AM by DrClap RSS

OutputStream - ApachePOI - Workbook.write to outputStream

Venkatesh Ramasamy Newbie
Currently Being Moderated
Hello,

I have a requirement, where an input XML from a webservice is read and have to create an MS Excel file sent via Oracle B2B to SFTP server. I have written a Java code that can read xml and write to MS Excel as a file if I use FileOutPutStream (for testing purpose). However, when I use an ByteArrayOutputStream, I get the ASCII in the Excel file.here is the spinet of the code,
public class xmlexcel implements Callout {

public void execute(CalloutContext calloutContext, List input,
                        List output) throws CalloutDomainException,
                                            CalloutSystemException {

.....................
....................
...................
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos); //Write Workbook to ByteArrayOutputStream
        CalloutMessage cmOut;
        cmOut = new CalloutMessage(bos.toString());  //CalloutMessage can be either String or byte[]
output.add(cmOut);
bos.close();
Also tried this,
ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
byte[] bytes = bos.toByteArray();
        CalloutMessage cmOut;
        cmOut = new CalloutMessage(bytes);
output.add(cmOut);
bos.close();
In both the cases, the Excel (xls) file that gets created has ASCII values, like this, ÐÏࡱá;þÿ.

Any ideas and suggestions are greatly appreciated,
Ven

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points