XzArchive

Inheritance: java.lang.Object, com.aspose.zip.ILicenseStateProvider

All Implemented Interfaces: com.aspose.zip.IArchiveFileEntry, com.aspose.ms.System.IDisposable, com.aspose.zip.IArchive, java.lang.AutoCloseable

public class XzArchive extends ILicenseStateProvider implements IArchiveFileEntry, System.IDisposable, IArchive, AutoCloseable

This class represents xz archive file. Use it to compose and extract xz archives.

Constructors

ConstructorDescription
XzArchive()Initializes a new instance of the XzArchive class and composes the archive in xz format.
XzArchive(XzArchiveSettings settings)Initializes a new instance of the XzArchive class and composes the archive in xz format.
XzArchive(InputStream source)Initializes a new instance of the XzArchive class prepared for decompressing.
XzArchive(String path)Initializes a new instance of the XzArchive class prepared for decompressing.

Methods

MethodDescription
close(){@inheritDoc}
dispose()Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
extract(File file)Extracts xz archive to a file.
extract(OutputStream destination)Extracts xz archive to a stream.
extract(String path)Extracts xz archive to a file by path.
extractToDirectory(String destinationDirectory)Extracts content of the archive to the directory provided.
getFileEntries()Gets entries of IArchiveFileEntry type constituting the xz archive.
getLength()Gets length.
getName()Gets name of the entry within archive.
save(OutputStream output)Saves xz archive to the stream provided.
save(String destinationFileName)Saves xz archive to destination file provided.
setSource(File file)Sets the content to be compressed within the archive.
setSource(InputStream source)Sets the content to be compressed within the archive.
setSource(String sourcePath)Sets the content to be compressed within the archive.

XzArchive()

public XzArchive()

Initializes a new instance of the XzArchive class and composes the archive in xz format.

XzArchive(XzArchiveSettings settings)

public XzArchive(XzArchiveSettings settings)

Initializes a new instance of the XzArchive class and composes the archive in xz format.

Parameters:

ParameterTypeDescription
settingsXzArchiveSettingsset of setting particular xz archive: dictionary size, block size, check type

XzArchive(InputStream source)

public XzArchive(InputStream source)

Initializes a new instance of the XzArchive class prepared for decompressing.

This constructor does not decompress. See extract(java.io.OutputStream) method for decompressing.

Parameters:

ParameterTypeDescription
sourcejava.io.InputStreamthe source of the archive

XzArchive(String path)

public XzArchive(String path)

Initializes a new instance of the XzArchive class prepared for decompressing.

This constructor does not decompress. See extract(java.io.OutputStream) method for decompressing.

Parameters:

ParameterTypeDescription
pathjava.lang.Stringpath to the source of the archive

close()

public void close()

dispose()

public final void dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

extract(File file)

public final void extract(File file)

Extracts xz archive to a file.


     try (FileInputStream xzFile = new FileInputStream("sourceFileName")) {
         try (XzArchive archive = new XzArchive(xzFile)) {
             archive.extract(new File("extracted.bin"));
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
filejava.io.Filefile for storing decompressed data

extract(OutputStream destination)

public final void extract(OutputStream destination)

Extracts xz archive to a stream.


     try (FileInputStream xzFile = new FileInputStream("sourceFileName")) {
         try (FileOutputStream extractedFile = new FileOutputStream("extractedFileName")) {
             try (XzArchive archive = new XzArchive(xzFile)) {
                 archive.extract(extractedFile);
             }
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
destinationjava.io.OutputStreamstream for storing decompressed data

extract(String path)

public final File extract(String path)

Extracts xz archive to a file by path.


     try (FileInputStream xzFile = new FileInputStream("sourceFileName")) {
         try (XzArchive archive = new XzArchive(xzFile)) {
             archive.extract("extracted.bin");
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
pathjava.lang.Stringpath to file which will store decompressed data

Returns: java.io.File - java.io.File instance containing extracted data

extractToDirectory(String destinationDirectory)

public final void extractToDirectory(String destinationDirectory)

Extracts content of the archive to the directory provided.

Parameters:

ParameterTypeDescription
destinationDirectoryjava.lang.Stringthe path to the directory to place the extracted files in.

If the directory does not exist, it will be created. |

getFileEntries()

public final Iterable<IArchiveFileEntry> getFileEntries()

Gets entries of IArchiveFileEntry type constituting the xz archive.

Returns: java.lang.Iterable<com.aspose.zip.IArchiveFileEntry> - entries of IArchiveFileEntry type constituting the xz archive

getLength()

public final Long getLength()

Gets length.

Returns: java.lang.Long - length

getName()

public final String getName()

Gets name of the entry within archive.

Returns: java.lang.String - name of the entry within archive

save(OutputStream output)

public final void save(OutputStream output)

Saves xz archive to the stream provided.


     try (FileOutputStream xzFile = new FileOutputStream("archive.xz")) {
         try (XzArchive archive = new XzArchive()) {
             archive.setSource("data.bin");
             archive.save(xzFile);
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamdestination stream

output must be seekable |

save(String destinationFileName)

public final void save(String destinationFileName)

Saves xz archive to destination file provided.


     try (XzArchive archive = new XzArchive()) {
         archive.setSource(new File("data.bin"));
         archive.save("result.xz");
     }
 

Parameters:

ParameterTypeDescription
destinationFileNamejava.lang.Stringthe path of the archive to be created. If the specified file name points to an existing file, it will be overwritten

setSource(File file)

public final void setSource(File file)

Sets the content to be compressed within the archive.


     try (XzArchive archive = new XzArchive()) {
         archive.setSource(new File("data.bin"));
         archive.save("archive.xz");
     }
 

Parameters:

ParameterTypeDescription
filejava.io.Filefile which will be opened as input stream

setSource(InputStream source)

public final void setSource(InputStream source)

Sets the content to be compressed within the archive.


     try (XzArchive archive = new XzArchive()) {
         archive.setSource(new ByteArrayInputStream(new byte[] { 0x00, (byte) 0xFF }));
         archive.save("archive.xz");
     }
 

Parameters:

ParameterTypeDescription
sourcejava.io.InputStreamthe input stream for the archive

setSource(String sourcePath)

public final void setSource(String sourcePath)

Sets the content to be compressed within the archive.


     try (XzArchive archive = new XzArchive()) {
         archive.setSource("data.bin");
         archive.save("archive.xz");
     }
 

Parameters:

ParameterTypeDescription
sourcePathjava.lang.Stringpath to file which will be opened as input stream