LzmaArchive

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

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

public class LzmaArchive extends ILicenseStateProvider implements System.IDisposable, IArchive, AutoCloseable

This class represents LZMA archive file. Use it to compose or extract LZMA archives.

Constructors

ConstructorDescription
LzmaArchive()Initializes a new instance of the LzmaArchive class and composes the archive in lzma format.
LzmaArchive(LzmaArchiveSettings settings)Initializes a new instance of the LzmaArchive class and composes the archive in lzma format.
LzmaArchive(InputStream source)Initializes a new instance of the LzmaArchive class prepared for decompressing.
LzmaArchive(String path)Initializes a new instance of the LzmaArchive 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 lzma archive to a file.
extract(OutputStream destination)Extracts lzma archive to a stream.
extract(String path)Extracts lzma 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 lzma archive.
save(File destination)Saves lzma archive to destination file provided.
save(OutputStream output)Saves lzma archive to the stream provided.
save(String destinationFileName)Saves lzma 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.

LzmaArchive()

public LzmaArchive()

Initializes a new instance of the LzmaArchive class and composes the archive in lzma format.

LzmaArchive(LzmaArchiveSettings settings)

public LzmaArchive(LzmaArchiveSettings settings)

Initializes a new instance of the LzmaArchive class and composes the archive in lzma format.

Parameters:

ParameterTypeDescription
settingsLzmaArchiveSettingsSet of setting particular lzma archive.

LzmaArchive(InputStream source)

public LzmaArchive(InputStream source)

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

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

Parameters:

ParameterTypeDescription
sourcejava.io.InputStreamThe source of the archive.

LzmaArchive(String path)

public LzmaArchive(String path)

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


     try (FileInputStream sourceLzmaFile = new FileInputStream(sourceFileName)) {
         try (FileOutputStream extractedFile = new FileOutputStream(extractedFileName)) {
             try (LzmaArchive archive = new LzmaArchive(sourceLzmaFile)) {
                 archive.extract(extractedFile);
             }
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

This constructor does not decompress. See extract(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 lzma archive to a file.


     try (FileInputStream lzmaFile = new FileInputStream(sourceFileName)) {
         try (LzmaArchive archive = new LzmaArchive(lzmaFile)) {
             archive.extract(new File("extracted.bin"));
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
filejava.io.Filefile for storing decompressed data.

extract(OutputStream destination)

public final void extract(OutputStream destination)

Extracts lzma archive to a stream.


     try (FileInputStream sourceLzmaFile = new FileInputStream(sourceFileName)) {
         try (FileOutputStream extractedFile = new FileOutputStream(extractedFileName)) {
             try (LzmaArchive archive = new LzmaArchive(sourceLzmaFile)) {
                 archive.extract(extractedFile);
             }
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
destinationjava.io.OutputStreamStream for storing decompressed data.

extract(String path)

public final File extract(String path)

Extracts lzma archive to a file by path.


     try (FileInputStream lzmaFile = new FileInputStream(sourceFileName)) {
         try (LzmaArchive archive = new LzmaArchive(lzmaFile)) {
             archive.extract("extracted.bin");
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

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

Returns: java.io.File

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 lzma archive.

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

save(File destination)

public final void save(File destination)

Saves lzma archive to destination file provided.


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

Parameters:

ParameterTypeDescription
destinationjava.io.FileFileInfo which will be opened as destination stream.

save(OutputStream output)

public final void save(OutputStream output)

Saves lzma archive to the stream provided.


     try (FileOutputStream lzmaFile = new FileOutputStream("archive.lzma")) {
         try (LzmaArchive archive = new LzmaArchive()) {
             archive.setSource("data.bin");
             archive.save(lzmaFile);
         }
     } catch (IOException ex) {
         System.out.println(ex);
     }
 

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamDestination stream.

output must be seekable. |

save(String destinationFileName)

public final void save(String destinationFileName)

Saves lzma archive to destination file provided.


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

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 (LzmaArchive archive = new LzmaArchive()) {
         archive.setSource(new File("data.bin"));
         archive.save("archive.lzma");
     }
 

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 (LzmaArchive archive = new LzmaArchive()) {
         archive.setSource(new ByteArrayInputStream(new byte[] { 0x00, (byte) 0xFF }));
         archive.save("archive.lzma");
     }
 

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 (LzmaArchive archive = new LzmaArchive()) {
         archive.setSource("data.bin");
         archive.save("archive.lzma");
     }
 

Parameters:

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