连接两个压缩的字节数组

连接两个压缩的字节数组

问题描述:

你好我有一个map reduce工作,它根据一些分组算法​​将不同的字节数组合在一起。

Hello I am having a map reduce job which merges different byte arrays together based on some grouping algorithm.

我尝试使用Java Deflater单独压缩每个数组但是当我尝试提取生成的压缩字节数组时,它只是我提取的第一个子数组。

I tried zipping each array individually using Java Deflater but when I try to extract the resultant zipped byte array, it is only the first sub array that I extracted.

是否可能将一个压缩后的字节数组连接起来然后解压缩,或者情况不是这样?

Is it it possible byte arrays once zipped to be just concatenated and then extracted or this is not the case ?

什么我想要的是:

byte array1[] - zip
byte array2[] - zip
byte array3[] = append(array1,array2).
unzip resulting array3.

当我解压缩它时,我只收到数组1。

When I unzip it I receive only array 1.

zip文件是结构化的,它们不仅包含压缩数据。对于文件中的每个条目,都有一个本地标题和相应的条目数据。在文件的末尾有一个中央目录,它列举了归档中包含的所有zip条目以及这些条目的起始位置。您可能会想到一个大致如下的zip文件:

The zip files are structured and they contain not only "zipped" data. For each entry in the file there is a local header and corresponding entry data. At the end of the file there is a central directory which enumerates all zip entries contained in the archive and the offsets where these start. You may think of a zip file roughly like this:

[entry-header,data][entry-header,data].....[central dir with entry meta-data][end-of-file]

你不能只将两个zip文件合并为字节数组,因为结果不是有效的zip。

You cannot just "merge" two zip files as byte arrays because the result will not be a valid zip.