gzip archive with multiple files inside

早过忘川 提交于 2019-12-30 03:11:05

问题


I need to create a gzip archive with multiple files inside, how can I do this without ArchiveEntry available for java.util.zip.GZIPOutputStream class?


回答1:


According to the Wikipedia entry on gzip:

Although its file format also allows for multiple such streams to be concatenated (zipped files are simply decompressed concatenated as if they were originally one file), gzip is normally used to compress just single files.

This is why GZIPOutputStream doesn't support ArchiveEntry.

Normally, multiple files are archived into one with tar, then compressed with gzip to produce a .tar.gz compressed archive.

You could create a tar.gz in this way by using the Apache Commons Compress implementation for tar:

file_out = new FileOutputStream (new File ("archive.tar.gz"));
buffer_out = new BufferedOutputStream (file_out);
gzip_out = new GzipCompressorOutputStream (buffer_out);
tar_out = new TarArchiveOutputStream (gzip_out);

// .. and then talk to 'tar_out' to write stuff

Here is a more thorough example that compresses entire directories.




回答2:


GZip compresses a stream. Typically, when people use GZip with multiple files, they also use tar to munch them together

You can find a java tar libarary here: http://www.trustice.com/java/tar/

Or you could use Zip instead of GZip



来源:https://stackoverflow.com/questions/10653683/gzip-archive-with-multiple-files-inside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!