Apache commons compress | TAR, GZip, BZip2, XZ, Snappy, Deflate Examples | un-GZip, UnTar Examples

In this article we will go through some examples using Apache commons compress for TAR, GZip, BZip2, XZ, Snappy, Deflate.

Examples in this article:

  • Simple TAR with files, directory & sub directory or sub folders.
  • Use above TAR & compress further using GZip, BZip2, XZ, Snappy, Deflate.
  • UnGZip and UnTar files/folders.

Dependency (maven, gradle, ivy etc.)

https://mvnrepository.com/artifact/org.apache.commons/commons-compress

Project structure (Basic maven project)

  • compress-me –> Folder to compress. Files range from 5 MB to 12 MB.
  • output –> output folder



Create TAR file from folders, sub folders



GZip from existing TAR file



BZip2 from existing TAR file



XZ from existing TAR file



Snappy from existing TAR file



Deflate existing TAR file

 

Here are the files created through above programs.

Here is the GZIP file opened in compression software.




UnGZipping and UnTaring

Below are the ungzipped and untared content.

Further Reading

Apache commons compress | Simplest zip, zip with directory, compression level, unzip

Apache commons compress | SevenZip unSevenZip Examples (.7z)



Leave a Reply

Your email address will not be published. Required fields are marked *