SkillAgentSearch skills...

Zip4jvm

This is NOT zip4j; this is much better! zip files support for JDK application: split, zip64, encryption, streaming

Install / Use

/learn @oleg-cherednik/Zip4jvm
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Maven Central javadoc java1.8 License

github-ci license-scan quality coverage

<details><summary>develop</summary> <p>

github-ci quality coverage

</p> </details> <p align="center"> <a href="https://github.com/oleg-cherednik/zip4jvm/blob/master/img/zip4jvm_qr.png?raw=true"> <img alt="QR-code" src="img/zip4jvm_qr_small.png" /> </a> </p>

zip4jvm - a java library for working with zip files

Features

  • Add regular files or directories to new or existed zip archive;

  • Extract regular files or directories from zip archive;

  • Encryption algorithms support:

  • Compression support:

  • Individual settings for each zip entry (i.e. some of the files can be encrypted, and some - not);

  • Streaming support for adding and extracting;

  • Read/Write password-protected Zip files and streams;

  • ZIP64 format support;

  • Multi-volume zip archive support:

    • PKWare, i.e. filename.zip, filename.z01, filename.z02
    • 7-Zip, i.e. filename.zip.001, filename.zip.002, filename.zip.003 (read-only)
  • Unicode for comments and file names;

  • Unzip using multiple threads;

  • Unzip zip recursively (unzip including zip as well).

Gradle

compile 'ru.oleg-cherednik.zip4jvm:zip4jvm:1.12'

Maven

<dependency>
    <groupId>ru.oleg-cherednik.zip4jvm</groupId>
    <artifactId>zip4jvm</artifactId>
    <version>1.12</version>
</dependency>

Usage

To simplify usage of zip4jvm, there are following classes:

  • ZipIt - add files to archive;
  • UnzipIt - extract files from archive;
  • ZipMisc - other zip file activities;
  • ZipInfo - zip file information and diagnostics.

ZipIt

Regular files and directories can be represented as Path

Create (or open existed) zip archive and add regular file /cars/bentley-continental.jpg
Path zip = Paths.get("filename.zip");
Path file = Path.get("/cars/bentley-continental.jpg")
ZipIt.zip(zip).add(file);
/-
|-- cars
|    |-- bentley-continental.jpg
|    |-- ferrari-458-italia.jpg
|    |-- wiesmann-gt-mf5.jpg
|-- bikes
|    |-- ducati-panigale-1199.jpg
|    |-- kawasaki-ninja-300.jpg
|    |-- honda-cbr600rr.jpg
|-- saint-petersburg.jpg
filename.zip
|-- bentley-continental.jpg

Note: regular file is added to the root of the zip archive.

Create (or open existed) zip archive and add directory /cars
Path zip = Paths.get("filename.zip");
Path dir = Path.get("/cars");
ZipIt.zip(zip).add(dir);
/-
|-- cars
|    |-- bentley-continental.jpg
|    |-- ferrari-458-italia.jpg
|    |-- wiesmann-gt-mf5.jpg
|-- bikes
|    |-- ducati-panigale-1199.jpg
|    |-- kawasaki-ninja-300.jpg
|    |-- honda-cbr600rr.jpg
|-- saint-petersburg.jpg
filename.zip
|-- cars
     |-- bentley-continental.jpg
     |-- ferrari-458-italia.jpg
     |-- wiesmann-gt-mf5.jpg

Note: directory is added to the root of the zip archive keeping the initial structure.

Create (or open existed) zip archive and add some regular files and/or directories
Path zip = Paths.get("filename.zip");
Collection<Path> paths = Arrays.asList(
        Paths.get("/bikes/ducati-panigale-1199.jpg"),
        Paths.get("/bikes/honda-cbr600rr.jpg"),
        Paths.get("/cars"),
        Paths.get("/saint-petersburg.jpg"));
ZipIt.zip(zip).add(paths);
/-
|-- cars
|    |-- bentley-continental.jpg
|    |-- ferrari-458-italia.jpg
|    |-- wiesmann-gt-mf5.jpg
|-- bikes
|    |-- ducati-panigale-1199.jpg
|    |-- kawasaki-ninja-300.jpg
|    |-- honda-cbr600rr.jpg
|-- saint-petersburg.jpg
filename.zip
|-- cars
|    |-- bentley-continental.jpg
|    |-- ferrari-458-italia.jpg
|    |-- wiesmann-gt-mf5.jpg
|-- ducati-panigale-1199.jpg
|-- honda-cbr600rr.jpg
|-- saint-petersburg.jpg

Note: each regular file from the list is added to the root of the zip archive.

Note: each directory from the list is added to the root of the zip archive keeping the initial structure.

Regular files and empty directories are available as InputStream

Create (or open existed) zip archive and add input streams content as regular files
Path zip = Zip4jvmSuite.subDirNameAsMethodName(rootDir).resolve("filename.zip");

ZipIt.zip(zip).execute(zipFile -> {
    zipFile.add(ZipFile.Entry.builder()
                             .inputStreamSupplier(() -> new FileInputStream("/cars/bentley-continental.jpg"))
                             .fileName("my_cars/bentley-continental.jpg")
                             .uncompressedSize(Files.size(Paths.get("/cars/bentley-continental.jpg"))).build());

    zipFile.add(ZipFile.Entry.builder()
                             .inputStreamSupplier(() -> new FileInputStream("/bikes/kawasaki-ninja-300.jpg"))
                             .fileName("my_bikes/kawasaki.jpg")
                             .uncompressedSize(Files.size(Paths.get("/bikes/kawasaki-ninja-300.jpg"))).build());
});
/-
|-- cars
|    |-- bentley-continental.jpg
|    |-- ferrari-458-italia.jpg
|    |-- wiesmann-gt-mf5.jpg
|-- bikes
|    |-- ducati-panigale-1199.jpg
|    |-- kawasaki-ninja-300.jpg
|    |-- honda-cbr600rr.jpg
|-- saint-petersburg.jpg
filename.zip
|-- my_cars
|    |-- bentley-continental.jpg
|-- my_bikes
|    |-- kawasaki.jpg

Note: each entry is treated as separate input stream of the regular file.

UnzipIt

Regular files and directories to Path destination

Extract all entries into given directory

Path zip = Paths.get("filename.zip");
Path destDir = Paths.get("/filename_content");
UnzipIt.zip(zip).destDir(destDir).extract();
filename.zip
|-- cars
|    |-- bentley-continental.jpg
|    |-- ferrari-458-italia.jpg
|    |-- wiesmann-gt-mf5.jpg
|-- bikes
|    |-- ducati-panigale-1199.jpg
|    |-- kawasaki-ninja-300.jpg
|-- saint-petersburg.jpg
/filename_content
 |-- cars
 |-- cars
 |    |-- bentley-continental.jpg
 |    |-- ferrari-458-italia.jpg
 |    |-- wiesmann-gt-mf5.jpg
 |-- bikes
 |    |-- ducati-panigale-1199.jpg
 |    |-- kawasaki-ninja-300.jpg
 |-- saint-petersburg.jpg

Note: all entries (i.e. regular files and empty directories) are added to the destination directory keeping the initial structure.

Extract regular file's entry into given directory
Path zip = Paths.get("filename.zip");
Path destDir = Paths.get("/filename_content");
UnzipIt.zip(zip).destDir(destDir).extract("/cars/bentley-continental.jpg");
filename.zip
|-- cars
|    |-- bentley-continental.jpg
|    |-- ferrari-458-italia.jpg
|    |-- wiesmann-gt-mf5.jpg
|-- bikes
|    |-- ducati-panigale-1199.jpg
|    |-- kawasaki-ninja-300.jpg
|-- saint-petersburg.jpg
/filename_content
 |-- bentley-continental.jpg

Note: regular file's entry is added to the root of the destination directory.

Extract directory entries into given directory
Path zip = Paths.get("filename.zip");
Path destDir = Paths.get("/filename_content");
UnzipIt.zip(zip).destDir(destDir).extract("cars");
filename.zip
|-- cars
|    |-- bentley-continental.jpg
|    |-- ferrari-458-italia.jpg
|    |-- wiesmann-gt-mf5.jpg
|-- bikes
|    |-- ducati-panigale-1199.jpg
|    |-- kawasaki-ninja-300.jpg
|-- saint-petersburg.jpg
/filename_content
 |-- cars
 |    |-- bentley-continental.jpg
 |    |-- ferrari-458-italia.jpg
 |    |-
View on GitHub
GitHub Stars28
CategoryCustomer
Updated4d ago
Forks3

Languages

Java

Security Score

95/100

Audited on Mar 23, 2026

No findings