0

3 バイト配列を結合して 1 つの配列を形成し、レポートを生成しようとしていました。

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();

これを報告書に書いてみると、内容が思い通りにならない。最初のbArrayコンテンツのみを表示します。ここで私が間違ったところ。

編集:

次のgetTheReportContent手順を実行します。

jasper を使用してレポートをエクスポートします。そして、byteArrList を返します。

 List byteArrList = new ArrayList();
 --------
 exporterXLS.exportReport();
 byteArrList.add(outputStream.toByteArray());
4

1 に答える 1

0

List を byte[] に割り当てています-これは起こり得ません。したがって、完全なコードを貼り付けていない可能性があると思います。

コードを試してみると、結果の長さは適切です。以下のクラスで確認できますので、受信部分に問題があるのではないかと思います。お知らせ下さい

public static void main(String[] args) {
    byte[] bArray=null;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream( );

    for(int i=0;i<3;i++)
    {
        try {
            //Other stuff
            bArray = getTheReportContent(); //The return type of this method is List<byte[]> 
            outputStream.write(bArray);
        } catch (IOException e) {
            e.printStackTrace();
        }
    } 

    byte bArrayCombined[] = outputStream.toByteArray( );  //Checked the count. bArrayCombined.length=sum of all the 3 bArray
    System.out.println("Size is " + bArrayCombined.length);

    ByteArrayOutputStream outStream = new ByteArrayOutputStream( );
    outStream.write(bArrayCombined, 0, bArrayCombined.length);

    System.out.println("new outStream size is " + outStream.toByteArray().length);

}

private static byte[] getTheReportContent() {
    return "123".getBytes();
}
于 2014-11-26T12:24:22.740 に答える