Compressor4j

Compressor4j

Compressor4j

Java dependency to simplify process of compressing and decompressing files and folders.

Compressor4j is a Java dependency to simplify process of compressing and decompressing files and folders.

  • Support compressing for file types: ZIP, GZ, TAR, TAR.GZ, JAR, BZ2, TAR.BZ2, AR, CPIO, XZ.
  • Support decompressing for file types: ZIP, GZ, TAR, TAR.GZ, JAR, BZ2, TAR.BZ2, AR, CPIO, 7Z, XZ, RAR.
  • JRE support: 7+

Compress files or folders

To compress files or folders, you could use as the following example:

[code_block_line_numbers]public static void write() throws Exception {
try {
FileCompressor fileCompressor = new FileCompressor();
String[] files = new String[] { “IMG_01.JPG”, “/02/IMG_02.JPG”, “/03/IMG_03.JPG” };
for (String file : files) {
fileCompressor.add(SRC_PATH + file, file);
}
fileCompressor.setType(CompressionType.JAR);
fileCompressor.setLevel(ZipLevel.NORMAL);
fileCompressor.setCompressedPath(“output.jar”);
fileCompressor.compress();
} catch (Exception e) {
e.printStackTrace();
}
}[/code_block_line_numbers]

Extract compressed file

To decompress files or folders, you could use as the following example:

[code_block_line_numbers]public static void read() throws Exception {
try {
FileCompressor fileCompressor = FileCompressor.read(“input.zip”);
fileCompressor.decompress(“output/”);
} catch (Exception e) {
e.printStackTrace();
}
}[/code_block_line_numbers]

For more information and usages, please visit source code repository: https://github.com/travistran1989/compressor4j

Share this
Send this to a friend