JavaBlog.fr / Java.lu DEVELOPMENT,Java Apache: Commons Compress – zip, tar, gzip

Apache: Commons Compress – zip, tar, gzip

For the needs of a project, I have had the opportunity to use the Apache Commons Compress libary in order to archive and compress files in ZIP, TAR, GZIP.

Here, a brief presentation of this library from Apache:
Apache Commons Compress software defines an API for working with compression and archive formats. These include: bzip2, gzip, pack200 and ar, cpio, jar, tar, zip, dump. This is a Java API for working with tar, zip, gz, jar, cpio and bzip2 files. The code has origins in other Apache projects like Excalibur, Ant, Commons-IO and jRPM.
The compress component is split into compressors and archivers. While compressors (un)compress streams that usually store a single entry, archivers deal with archives that contain structured content represented by ArchiveEntry instances which in turn usually correspond to single files or directories. Currently the bzip2 and gzip formats are supported as compressors where gzip support is provided by the java.util.zip package of the Java class library. The ar, cpio, tar and zip formats are supported as archivers where the zip implementation provides capabilities that go beyond the features found in java.util.zip. The compress component provides abstract base classes for compressors and archivers together with factories that can be used to choose implementations by algorithm name.
In the case of input streams the factories can also be used to guess the format and provide the matching implementation.

A note concerning the differences between GZIP and ZIP:
+ GZIP files (the Gnu format) are not archives and compress only one file. GZIP is essentially a one file subset of the Zip format.
+ GZIP compresses only one file and does not have a header. ZIP contains header information about what files are contained in the file.
+ ZIP is an archive file format, popularized on PCs, that contains multiple compressed files.

In the attachments files, you could find a project using commons-compress-1.0.jar with the classes:
CompressArchiveUtil: tool allowing the manipulations of tar or tar.gz documents;
ZipUtil: Utility to Zip and Unzip nested directories recursively

The outputs/files are created in test_compress1\bin\jUnitResources folder.

test_compress1.zip

Source: Apache Commons Compress

2 thoughts on “Apache: Commons Compress – zip, tar, gzip”

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

Related Post

Documentum : Audit trail entries dm_audittrail / SessionConfig / application_codeDocumentum : Audit trail entries dm_audittrail / SessionConfig / application_code

Hi, After my previous posts concerning the Documentum audit trail entries (dm_audittrail) http://www.javablog.fr/documentum-creation-of-audit-trail-entries-dm_audittrail.html and http://www.javablog.fr/deleting-of-audit-trail-entries-dm_audittrail.html, here, I would like to expose a solution in order to force content server to