gzip archive with multiple files inside

前端 未结 2 1050
天命终不由人
天命终不由人 2020-12-31 12:40

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

2条回答
  •  我在风中等你
    2020-12-31 13:44

    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.

提交回复
热议问题