Working with Z Archives in Java

Overview

Compress is a Unix shell utility producing an archive with .Z extension. Aspose.ZIP for Java API lets work with creating and managing Z archives in your applications without the need of any other 3rd party applications. Aspose.ZIP API provides  ZArchive class to work with such archives. This class provides basic methods to perform operations on archives.

This utility iplements LZC algorithm which is modification of LZW algorithm.

Compress A File

The following code example shows how to compress a file using ZArchive instance.

1try (FileInputStream source = new FileInputStream("alice29.txt")) {
2    try (ZArchive archive = new ZArchive()) {
3        archive.setSource(source);
4        archive.save("alice29.txt.Z");
5    }
6} catch (IOException ex) {
7}

Open Z Archive

The following code example shows how to open a Z archive.

1try (ZArchive archive = new ZArchive("data.bin.Z")) {
2    archive.extract("data.bin");
3}

Save to Stream

The following code example shows how to save to stream.

1ByteArrayOutputStream bs = new ByteArrayOutputStream();
2try (FileInputStream source = new FileInputStream("alice29.txt")) {
3    try (ZArchive archive = new ZArchive()) {
4        archive.setSource(source);
5        archive.save(bs);
6    }
7} catch (IOException ex) {
8}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.