0

我有 2 个字节的数组。我正在使用 system.arraycopy 进行连接。它没有抛出异常,但结果流仅显示第二个数组数据

byte mainPdf[] = generatePDF(creditAppPDFurl, cifNumber,appRefId,pdfid1,appTransId);
byte supportingPdf[] = generateSupportingDocPDF();

byte[] destination = new byte[mainPdf.length + supportingPdf.length];
System.arraycopy(mainPdf, 0, destination, 0, mainPdf.length);
System.arraycopy(supportingPdf, 0, destination, mainPdf.length, supportingPdf.length);
pdfInputStreamData = new ByteArrayInputStream(destination);

pdfInputStreamData 仅显示支持 PDF 数据

4

2 回答 2

2

您的代码很好,错误在其他地方。特别是,原始数组可能不包含您期望的信息。

您可以尝试这个简单的示例来确认代码的数组连接部分是否有效:

public static void main(String[] args) throws Exception {
    byte mainPdf[] = {1, 2, 3};
    byte supportingPdf[] = {4, 5, 6};

    byte[] destination = new byte[mainPdf.length + supportingPdf.length];
    System.arraycopy(mainPdf, 0, destination, 0, mainPdf.length);
    System.arraycopy(supportingPdf, 0, destination, mainPdf.length, supportingPdf.length);

    System.out.println(Arrays.toString(destination));
}

打印[1, 2, 3, 4, 5, 6]

于 2013-06-10T16:11:16.450 回答
0

对于上述相同的编码行,当我运行时

pdfInputStreamData = new ByteArrayInputStream(mainPdf);

它为第一个字节 [] 提供正确的数据。

当我跑

pdfInputStreamData = new ByteArrayInputStream(supportingPdf);

它为第二个字节 [] 提供了正确的数据。

但是最后一行

byte[] destination = new byte[mainPdf.length + supportingPdf.length];
System.arraycopy(mainPdf, 0, destination, 0, mainPdf.length);
System.arraycopy(supportingPdf, 0, destination, mainPdf.length, supportingPdf.length);
pdfInputStreamData = new ByteArrayInputStream(destination);

打印时仅提供supportingPdf数据。

我无法弄清楚这种情况下的问题是什么

于 2013-06-19T12:37:32.427 回答