Jesper de Jong wrote:You have: TarArchiveOutputStream(GZIPOutputStream(BufferedOutputStream(FileOutputStream)))
I think that is correct. Any bytes written to the TarArchiveOutputStream are passed to the GZIPOutputStream, which in turn passes its bytes (after GZIP applied) to the BufferedOutputStream which in turn passed them to the FileOutputStream which finally writes the bytes to disk.
If the TarArchiveOutputStream and GZIPOutputStream are switched you're applying GZIP before applying TAR, which would be something like a .gz.tar file.
The rule is:
- With OutputStream (and Writer), the innermost OutputStream (Writer) will be applied last.
- With InputStream (and Reader), the innermost InputStream (Reader) will be applied first.
Because with .tar.gz TAR must be applied before GZIP, wrapping the GZIPOutputStream in the TarArchiveOutputStream is the correct way. When reading it back in, GZIP must be applied before TAR so the GZIPInputStream would need to be wrapped in the TarArchiveInputStream.