Working with XZ Archives in Java

Overview

XZ archive is common in Linux. It uses LZMA2 algorithm. Aspose.ZIP for Java API lets work with creating and managing XZ archives in your applications without the need of any other 3rd party applications. Aspose.ZIP API provides  XzArchive class to work with such archives. This class provides basic methods to perform operations on archives.

Compress A File

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

1try (FileOutputStream xzFile = new FileOutputStream("data.bin.xz")) {
2    try (FileInputStream source = new FileInputStream("data.bin")) {
3        try (XzArchive archive = new XzArchive(XzArchiveSettings.getFastestSpeed())) {
4            archive.setSource(source);
5            archive.save(xzFile);
6        }
7    }
8} catch (IOException ex) {
9}

Open XZ Archive

The following simple code example shows how to open a XZ archive.

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

Choosing Checksum Calculation Method

XZ archive allows to choose data integrity calculation from CRC32, CRC64, SHA-256 or omit it. Aspose.Zip implements 3 of such methods: XzCheckType.None, XzCheckType.Crc32, XzCheckType.Crc64. Default is CRC32.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.