I was trying to combine 3 byte arrays to form a single one to generate a report.
byte[] bArray=null;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream( );
for(int i=0;i<3;i++)
{
//Other stuff
bArray = getTheReportContent(); //The return type of this method is List<byte[]>
outputStream.write(bArray);
}
byte bArrayCombined[] = outputStream.toByteArray( ); //Checked the count. bArrayCombined.length=sum of all the 3 bArray
response.setContentLength((int) bArrayCombined.length);
outStream.write(bArrayCombined, 0, bArrayCombined.length);
outStream.flush();
When I have written this in to the report, the content is not as expected. It shows only first bArray
contents. Where I went wrong here.
EDIT:
The getTheReportContent
do the following:
Exports the report using jasper. And returns byteArrList.
List byteArrList = new ArrayList();
--------
exporterXLS.exportReport();
byteArrList.add(outputStream.toByteArray());
You are assigning List to byte[] -- which cannot happen. So I believe u might have not pasted the full code.
Tried your code, the resultant length is proper. You can check with the following class.So I think the problem might be there in the receiving part. Let me know