XarArchive

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

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

public class XarArchive extends ILicenseStateProvider implements IArchive, AutoCloseable

This class represents xar archive file.

Constructors

ConstructorDescription
XarArchive()Initializes a new instance of the XarArchive class.
XarArchive(XarCompressionSettings defaultCompressionSettings)Initializes a new instance of the XarArchive class.
XarArchive(InputStream sourceStream)Initializes a new instance of the XarArchive class and composes entries list can be extracted from the archive.
XarArchive(String path)Initializes a new instance of the XarArchive class and composes entries list can be extracted from the archive.

Methods

MethodDescription
close(){@inheritDoc}
createEntries(File directory)Adds to the archive all the files and directories recursively in the directory given.
createEntries(File directory, boolean includeRootDirectory)Adds to the archive all the files and directories recursively in the directory given.
createEntries(File directory, boolean includeRootDirectory, XarCompressionSettings compressionSettings)Adds to the archive all the files and directories recursively in the directory given.
createEntries(String sourceDirectory)Adds to the archive all the files and directories recursively in the directory given.
createEntries(String sourceDirectory, boolean includeRootDirectory)Adds to the archive all the files and directories recursively in the directory given.
createEntries(String sourceDirectory, boolean includeRootDirectory, XarCompressionSettings compressionSettings)Adds to the archive all the files and directories recursively in the directory given.
createEntry(String name, File file)Create single entry within the archive.
createEntry(String name, File file, boolean openImmediately)Create single entry within the archive.
createEntry(String name, File file, boolean openImmediately, XarCompressionSettings compressionSettings)Create single entry within the archive.
createEntry(String name, InputStream source)Create single entry within the archive.
createEntry(String name, InputStream source, XarCompressionSettings compressionSettings)Create single entry within the archive.
createEntry(String name, String sourcePath)Create single entry within the archive.
createEntry(String name, String sourcePath, boolean openImmediately)Create single entry within the archive.
createEntry(String name, String sourcePath, boolean openImmediately, XarCompressionSettings compressionSettings)Create single entry within the archive.
deleteEntry(XarEntry entry)Removes the first occurrence of a specific entry from the entries list.
dispose()Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
extractToDirectory(String destinationDirectory)Extracts all the files in the archive to the directory provided.
getEntries()Gets entries of XarEntry type constituting the archive.
getFileEntries()Gets entries of IArchiveFileEntry type constituting the xar archive.
save(OutputStream output)Saves archive to the stream provided.
save(String destinationFileName)Saves archive to destination file provided.

XarArchive()

public XarArchive()

Initializes a new instance of the XarArchive class.

The following example shows how to compress a file.


     try (XarArchive archive = new XarArchive()) {
         archive.createEntry("first.bin", "data.bin");
         archive.save("archive.xar");
     }
 

XarArchive(XarCompressionSettings defaultCompressionSettings)

public XarArchive(XarCompressionSettings defaultCompressionSettings)

Initializes a new instance of the XarArchive class.

The following example shows how to compress a file.


     try (XarArchive archive = new XarArchive()) {
         archive.createEntry("first.bin", "data.bin");
         archive.save("archive.xar");
     }
 

Parameters:

ParameterTypeDescription
defaultCompressionSettingsXarCompressionSettingsthe default compression settings, applyed to all entries of the archive

XarArchive(InputStream sourceStream)

public XarArchive(InputStream sourceStream)

Initializes a new instance of the XarArchive class and composes entries list can be extracted from the archive.

The following example shows how to extract all of the entries to a directory.


     try (XarArchive archive = new XarArchive(new FileInputStream("archive.xar"))) {
         archive.extractToDirectory("C:\\extracted");
     } catch (IOException ex) {
     }
 

This constructor does not unpack any entry. See XarFileEntry.open() method for unpacking.

Parameters:

ParameterTypeDescription
sourceStreamjava.io.InputStreamthe source of the archive

XarArchive(String path)

public XarArchive(String path)

Initializes a new instance of the XarArchive class and composes entries list can be extracted from the archive.

The following example shows how to extract all of the entries to a directory.


     try (XarArchive archive = new XarArchive("archive.xar")) {
         archive.extractToDirectory("C:\\extracted");
     }
 

This constructor does not unpack any entry. See XarFileEntry.open() method for unpacking.

Parameters:

ParameterTypeDescription
pathjava.lang.Stringthe path to the archive file

close()

public void close()

createEntries(File directory)

public final XarArchive createEntries(File directory)

Adds to the archive all the files and directories recursively in the directory given.


     try (FileOutputStream xarFile = new FileOutputStream("archive.xar")) {
         try (XarArchive archive = new XarArchive()) {
             archive.createEntries(new java.io.File("C:\\folder"), false);
             archive.save(xarFile);
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
directoryjava.io.Filedirectory to compress

Returns: XarArchive - Xar entry instance

createEntries(File directory, boolean includeRootDirectory)

public final XarArchive createEntries(File directory, boolean includeRootDirectory)

Adds to the archive all the files and directories recursively in the directory given.


     try (FileOutputStream xarFile = new FileOutputStream("archive.xar")) {
         try (XarArchive archive = new XarArchive()) {
             archive.createEntries(new java.io.File("C:\\folder"), false);
             archive.save(xarFile);
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
directoryjava.io.Filedirectory to compress
includeRootDirectorybooleanindicates whether to include the root directory itself or not

Returns: XarArchive - Xar entry instance

createEntries(File directory, boolean includeRootDirectory, XarCompressionSettings compressionSettings)

public final XarArchive createEntries(File directory, boolean includeRootDirectory, XarCompressionSettings compressionSettings)

Adds to the archive all the files and directories recursively in the directory given.


     try (FileOutputStream xarFile = new FileOutputStream("archive.xar")) {
         try (XarArchive archive = new XarArchive()) {
             archive.createEntries(new java.io.File("C:\\folder"), false);
             archive.save(xarFile);
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
directoryjava.io.Filedirectory to compress
includeRootDirectorybooleanindicates whether to include the root directory itself or not
compressionSettingsXarCompressionSettingsthe compression settings used for added XarEntry items

Returns: XarArchive - Xar entry instance

createEntries(String sourceDirectory)

public final XarArchive createEntries(String sourceDirectory)

Adds to the archive all the files and directories recursively in the directory given.


     try (FileOutputStream xarFile = new FileOutputStream("archive.xar")) {
         try (XarArchive archive = new XarArchive()) {
             archive.createEntries("C:\\folder", false);
             archive.save(xarFile);
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
sourceDirectoryjava.lang.Stringdirectory to compress

Returns: XarArchive - Xar entry instance

createEntries(String sourceDirectory, boolean includeRootDirectory)

public final XarArchive createEntries(String sourceDirectory, boolean includeRootDirectory)

Adds to the archive all the files and directories recursively in the directory given.


     try (FileOutputStream xarFile = new FileOutputStream("archive.xar")) {
         try (XarArchive archive = new XarArchive()) {
             archive.createEntries("C:\\folder", false);
             archive.save(xarFile);
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
sourceDirectoryjava.lang.Stringdirectory to compress
includeRootDirectorybooleanindicates whether to include the root directory itself or not

Returns: XarArchive - Xar entry instance

createEntries(String sourceDirectory, boolean includeRootDirectory, XarCompressionSettings compressionSettings)

public final XarArchive createEntries(String sourceDirectory, boolean includeRootDirectory, XarCompressionSettings compressionSettings)

Adds to the archive all the files and directories recursively in the directory given.


     try (FileOutputStream xarFile = new FileOutputStream("archive.xar")) {
         try (XarArchive archive = new XarArchive()) {
             archive.createEntries("C:\\folder", false);
             archive.save(xarFile);
         }
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
sourceDirectoryjava.lang.Stringdirectory to compress
includeRootDirectorybooleanindicates whether to include the root directory itself or not
compressionSettingsXarCompressionSettingsthe compression settings used for added XarEntry items

Returns: XarArchive - Xar entry instance

createEntry(String name, File file)

public final XarEntry createEntry(String name, File file)

Create single entry within the archive.


     java.io.File file = new java.io.File("data.bin");
     try (XarArchive archive = new XarArchive()) {
         archive.createEntry("test.bin", file);
         archive.save("archive.xar");
     }
 

Parameters:

ParameterTypeDescription
namejava.lang.Stringthe name of the entry
filejava.io.Filethe metadata of file or folder to be compressed

Returns: XarEntry - Xar entry instance

createEntry(String name, File file, boolean openImmediately)

public final XarEntry createEntry(String name, File file, boolean openImmediately)

Create single entry within the archive.


     java.io.File file = new java.io.File("data.bin");
     try (XarArchive archive = new XarArchive()) {
         archive.createEntry("test.bin", file);
         archive.save("archive.xar");
     }
 

If the file is opened immediately with openImmediately parameter it becomes blocked until archive is disposed

Parameters:

ParameterTypeDescription
namejava.lang.Stringthe name of the entry
filejava.io.Filethe metadata of file or folder to be compressed
openImmediatelybooleantrue if open the file immediately, otherwise open the file on archive saving.

Returns: XarEntry - Xar entry instance

createEntry(String name, File file, boolean openImmediately, XarCompressionSettings compressionSettings)

public final XarEntry createEntry(String name, File file, boolean openImmediately, XarCompressionSettings compressionSettings)

Create single entry within the archive.


     java.io.File file = new java.io.File("data.bin");
     try (XarArchive archive = new XarArchive()) {
         archive.createEntry("test.bin", file);
         archive.save("archive.xar");
     }
 

If the file is opened immediately with openImmediately parameter it becomes blocked until archive is disposed

Parameters:

ParameterTypeDescription
namejava.lang.Stringthe name of the entry
filejava.io.Filethe metadata of file or folder to be compressed
openImmediatelybooleantrue if open the file immediately, otherwise open the file on archive saving.
compressionSettingsXarCompressionSettingsthe compression settings used for added XarEntry item

Returns: XarEntry - Xar entry instance

createEntry(String name, InputStream source)

public final XarEntry createEntry(String name, InputStream source)

Create single entry within the archive.


     try (XarArchive archive = new XarArchive()) {
         archive.createEntry("data.bin", new FileInputStream("data.bin"));
         archive.save("archive.xar");
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
namejava.lang.Stringthe name of the entry
sourcejava.io.InputStreamthe input stream for the entry

Returns: XarEntry - Xar entry instance

createEntry(String name, InputStream source, XarCompressionSettings compressionSettings)

public final XarEntry createEntry(String name, InputStream source, XarCompressionSettings compressionSettings)

Create single entry within the archive.


     try (XarArchive archive = new XarArchive()) {
         archive.createEntry("data.bin", new FileInputStream("data.bin"));
         archive.save("archive.xar");
     } catch (IOException ex) {
     }
 

Parameters:

ParameterTypeDescription
namejava.lang.Stringthe name of the entry
sourcejava.io.InputStreamthe input stream for the entry
compressionSettingsXarCompressionSettingsthe compression settings used for added XarEntry item

Returns: XarEntry - Xar entry instance

createEntry(String name, String sourcePath)

public final XarEntry createEntry(String name, String sourcePath)

Create single entry within the archive.


     try (XarArchive archive = new XarArchive()) {
         archive.createEntry("first.bin", "data.bin");
         archive.save("archive.xar");
     }
 

The entry name is solely set within name parameter. The file name provided in sourcePath parameter does not affect the entry name.

Parameters:

ParameterTypeDescription
namejava.lang.Stringthe name of the entry
sourcePathjava.lang.Stringthe path to the file to be compressed

Returns: XarEntry - Xar entry instance

createEntry(String name, String sourcePath, boolean openImmediately)

public final XarEntry createEntry(String name, String sourcePath, boolean openImmediately)

Create single entry within the archive.


     try (XarArchive archive = new XarArchive()) {
         archive.createEntry("first.bin", "data.bin");
         archive.save("archive.xar");
     }
 

The entry name is solely set within name parameter. The file name provided in sourcePath parameter does not affect the entry name.

If the file is opened immediately with openImmediately parameter it becomes blocked until archive is disposed.

Parameters:

ParameterTypeDescription
namejava.lang.Stringthe name of the entry
sourcePathjava.lang.Stringthe path to the file to be compressed
openImmediatelybooleantrue if open the file immediately, otherwise open the file on archive saving

Returns: XarEntry - Xar entry instance

createEntry(String name, String sourcePath, boolean openImmediately, XarCompressionSettings compressionSettings)

public final XarEntry createEntry(String name, String sourcePath, boolean openImmediately, XarCompressionSettings compressionSettings)

Create single entry within the archive.


     try (XarArchive archive = new XarArchive()) {
         archive.createEntry("first.bin", "data.bin");
         archive.save("archive.xar");
     }
 

The entry name is solely set within name parameter. The file name provided in sourcePath parameter does not affect the entry name.

If the file is opened immediately with openImmediately parameter it becomes blocked until archive is disposed.

Parameters:

ParameterTypeDescription
namejava.lang.Stringthe name of the entry
sourcePathjava.lang.Stringthe path to the file to be compressed
openImmediatelybooleantrue if open the file immediately, otherwise open the file on archive saving
compressionSettingsXarCompressionSettingsthe compression settings used for added XarEntry item

Returns: XarEntry - Xar entry instance

deleteEntry(XarEntry entry)

public final XarArchive deleteEntry(XarEntry entry)

Removes the first occurrence of a specific entry from the entries list.

Here is how you can remove all entries except the last one:


     try (XarArchive archive = new XarArchive("archive.xar")) {
         while (archive.getEntries().size() > 1)
             archive.deleteEntry(archive.getEntries().get(0));
         archive.save("outputXarFile.xar");
     }
 

Parameters:

ParameterTypeDescription
entryXarEntrythe entry to remove from the entries list

Returns: XarArchive - Xar entry instance

dispose()

public final void dispose()

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

extractToDirectory(String destinationDirectory)

public final void extractToDirectory(String destinationDirectory)

Extracts all the files in the archive to the directory provided.


     try (XarArchive archive = new XarArchive("archive.xar")) {
         archive.extractToDirectory("C:\\extracted");
     }
 

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 |

getEntries()

public final List<XarEntry> getEntries()

Gets entries of XarEntry type constituting the archive.

Returns: java.util.List<com.aspose.zip.XarEntry> - entries of XarEntry type constituting the archive

getFileEntries()

public final Iterable<IArchiveFileEntry> getFileEntries()

Gets entries of IArchiveFileEntry type constituting the xar archive.

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

save(OutputStream output)

public final void save(OutputStream output)

Saves archive to the stream provided.

For large archives use save(String) instead of saving to java.io.FileOutputStream.

Parameters:

ParameterTypeDescription
outputjava.io.OutputStreamdestination stream

save(String destinationFileName)

public final void save(String destinationFileName)

Saves archive to destination file provided.

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