Converting ZIP to tar.gz
Tar.gz is by far the most widespread compressed archive format in the Linux world while ZIP is the most popular for Windows. If you want to convert a ZIP archive to tar.gz read this article.
Convertation
Aspose.ZIP API provides the saveGzipped to compress a tar archive on the fly. We can extract an entry from the ZIP archive to memory without saving it into intermediate storage and pass it into the tar archive right away.
Make sure you have enough virtual memory to keep the content of all entries.
Transfer an Entry
The following code example demonstrates how to extract entries from the ZIP archive and immediately put them to the tar.gz archive. Entries that are directories are skipped, but their files are added respecting relative paths.
1try (Archive source = new Archive("source.zip")) {
2 try (TarArchive tar = new TarArchive()) {
3 for (ArchiveEntry entry : source.getEntries()) {
4 if (!entry.isDirectory()) {
5 ByteArrayOutputStream out = new ByteArrayOutputStream();
6 try (InputStream mem = entry.open()) {
7 byte[] b = new byte[8192];
8 int bytesRead;
9 while (0 < (bytesRead = mem.read(b, 0, b.length))) {
10 out.write(b, 0, bytesRead);
11 }
12 }
13 tar.createEntry(entry.getName(), new ByteArrayInputStream(out.toByteArray()));
14 }
15 }
16
17 tar.saveGzipped("result.tar.gz");
18 }
19} catch (IOException ex) {
20 System.out.println(ex);
21}