XarArchive
Inheritance: java.lang.Object
All Implemented Interfaces: com.aspose.zip.IArchive, java.lang.AutoCloseable
public class XarArchive implements IArchive, AutoCloseable
This class represents a xar archive file.
Constructors
| Constructor | Description |
|---|---|
| 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 an entry list can be extracted from the archive. |
| XarArchive(InputStream sourceStream, XarLoadOptions loadOptions) | Initializes a new instance of the XarArchive class and composes an entry list can be extracted from the archive. |
| XarArchive(String path) | Initializes a new instance of the XarArchive class and composes an entry list can be extracted from the archive. |
| XarArchive(String path, XarLoadOptions loadOptions) | Initializes a new instance of the XarArchive class and composes an entry list can be extracted from the archive. |
Methods
| Method | Description |
|---|---|
| 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 a single entry within the archive. |
| createEntry(String name, File file, boolean openImmediately) | Create a single entry within the archive. |
| createEntry(String name, File file, boolean openImmediately, XarCompressionSettings compressionSettings) | Create a single entry within the archive. |
| createEntry(String name, InputStream source) | Create a single entry within the archive. |
| createEntry(String name, InputStream source, XarCompressionSettings compressionSettings) | Create a single entry within the archive. |
| createEntry(String name, String sourcePath) | Create a single entry within the archive. |
| createEntry(String name, String sourcePath, boolean openImmediately) | Create a single entry within the archive. |
| createEntry(String name, String sourcePath, boolean openImmediately, XarCompressionSettings compressionSettings) | Create a single entry within the archive. |
| deleteEntry(XarEntry entry) | Removes the first occurrence of a specific entry from the entry list. |
| 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. |
| getFormat() | Gets the archive format. |
| save(OutputStream output) | Saves archive to the stream provided. |
| save(OutputStream output, XarSaveOptions saveOptions) | Saves archive to the stream provided. |
| save(String destinationFileName) | Saves archive to the destination file provided. |
| save(String destinationFileName, XarSaveOptions saveOptions) | Saves archive to the 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) {#XarArchive-com.aspose.zip.XarCompressionSettings-}
public XarArchive(XarCompressionSettings defaultCompressionSettings)
Initializes a new instance of the [XarArchive](../../com.aspose.zip/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:**
| Parameter | Type | Description |
| --- | --- | --- |
| defaultCompressionSettings | [XarCompressionSettings](../../com.aspose.zip/xarcompressionsettings) | the default compression settings, applyed to all entries of the archive |
### XarArchive(InputStream sourceStream) {#XarArchive-java.io.InputStream-}
```
public XarArchive(InputStream sourceStream)
```
Initializes a new instance of the [XarArchive](../../com.aspose.zip/xararchive) class and composes an entry list can be extracted from the archive.
The following example shows how to extract all 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()](../../com.aspose.zip/xarfileentry\#open--) method for unpacking.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourceStream | java.io.InputStream | the source of the archive |
### XarArchive(InputStream sourceStream, XarLoadOptions loadOptions) {#XarArchive-java.io.InputStream-com.aspose.zip.XarLoadOptions-}
public XarArchive(InputStream sourceStream, XarLoadOptions loadOptions)
Initializes a new instance of the [XarArchive](../../com.aspose.zip/xararchive) class and composes an entry list can be extracted from the archive.
The following example shows how to extract all 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()](../../com.aspose.zip/xarfileentry\#open--) method for unpacking.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourceStream | java.io.InputStream | the source of the archive |
| loadOptions | [XarLoadOptions](../../com.aspose.zip/xarloadoptions) | the options to load archive with |
### XarArchive(String path) {#XarArchive-java.lang.String-}
```
public XarArchive(String path)
```
Initializes a new instance of the [XarArchive](../../com.aspose.zip/xararchive) class and composes an entry list can be extracted from the archive.
The following example shows how to extract all 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()](../../com.aspose.zip/xarfileentry\#open--) method for unpacking.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| path | java.lang.String | the path to the archive file |
### XarArchive(String path, XarLoadOptions loadOptions) {#XarArchive-java.lang.String-com.aspose.zip.XarLoadOptions-}
public XarArchive(String path, XarLoadOptions loadOptions)
Initializes a new instance of the [XarArchive](../../com.aspose.zip/xararchive) class and composes an entry list can be extracted from the archive.
The following example shows how to extract all 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()](../../com.aspose.zip/xarfileentry\#open--) method for unpacking.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| path | java.lang.String | the path to the archive file |
| loadOptions | [XarLoadOptions](../../com.aspose.zip/xarloadoptions) | the options to load archive with |
### close() {#close--}
```
public void close()
```
### createEntries(File directory) {#createEntries-java.io.File-}
```
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:**
| Parameter | Type | Description |
| --- | --- | --- |
| directory | java.io.File | directory to compress |
**Returns:**
[XarArchive](../../com.aspose.zip/xararchive) - Xar entry instance
### createEntries(File directory, boolean includeRootDirectory) {#createEntries-java.io.File-boolean-}
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:**
| Parameter | Type | Description |
| --- | --- | --- |
| directory | java.io.File | directory to compress |
| includeRootDirectory | boolean | indicates whether to include the root directory itself or not |
**Returns:**
[XarArchive](../../com.aspose.zip/xararchive) - Xar entry instance
### createEntries(File directory, boolean includeRootDirectory, XarCompressionSettings compressionSettings) {#createEntries-java.io.File-boolean-com.aspose.zip.XarCompressionSettings-}
```
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:**
| Parameter | Type | Description |
| --- | --- | --- |
| directory | java.io.File | directory to compress |
| includeRootDirectory | boolean | indicates whether to include the root directory itself or not |
| compressionSettings | [XarCompressionSettings](../../com.aspose.zip/xarcompressionsettings) | the compression settings used for added [XarEntry](../../com.aspose.zip/xarentry) items |
**Returns:**
[XarArchive](../../com.aspose.zip/xararchive) - Xar entry instance
### createEntries(String sourceDirectory) {#createEntries-java.lang.String-}
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:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourceDirectory | java.lang.String | directory to compress |
**Returns:**
[XarArchive](../../com.aspose.zip/xararchive) - Xar entry instance
### createEntries(String sourceDirectory, boolean includeRootDirectory) {#createEntries-java.lang.String-boolean-}
```
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:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourceDirectory | java.lang.String | directory to compress |
| includeRootDirectory | boolean | indicates whether to include the root directory itself or not |
**Returns:**
[XarArchive](../../com.aspose.zip/xararchive) - Xar entry instance
### createEntries(String sourceDirectory, boolean includeRootDirectory, XarCompressionSettings compressionSettings) {#createEntries-java.lang.String-boolean-com.aspose.zip.XarCompressionSettings-}
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:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourceDirectory | java.lang.String | directory to compress |
| includeRootDirectory | boolean | indicates whether to include the root directory itself or not |
| compressionSettings | [XarCompressionSettings](../../com.aspose.zip/xarcompressionsettings) | the compression settings used for added [XarEntry](../../com.aspose.zip/xarentry) items |
**Returns:**
[XarArchive](../../com.aspose.zip/xararchive) - Xar entry instance
### createEntry(String name, File file) {#createEntry-java.lang.String-java.io.File-}
```
public final XarEntry createEntry(String name, File file)
```
Create a 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:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| file | java.io.File | the metadata of file or folder to be compressed |
**Returns:**
[XarEntry](../../com.aspose.zip/xarentry) - Xar entry instance
### createEntry(String name, File file, boolean openImmediately) {#createEntry-java.lang.String-java.io.File-boolean-}
public final XarEntry createEntry(String name, File file, boolean openImmediately)
Create a 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:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| file | java.io.File | the metadata of file or folder to be compressed |
| openImmediately | boolean | true if open the file immediately, otherwise open the file on archive saving. |
**Returns:**
[XarEntry](../../com.aspose.zip/xarentry) - Xar entry instance
### createEntry(String name, File file, boolean openImmediately, XarCompressionSettings compressionSettings) {#createEntry-java.lang.String-java.io.File-boolean-com.aspose.zip.XarCompressionSettings-}
```
public final XarEntry createEntry(String name, File file, boolean openImmediately, XarCompressionSettings compressionSettings)
```
Create a 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:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| file | java.io.File | the metadata of file or folder to be compressed |
| openImmediately | boolean | true, if open the file immediately, otherwise open the file on archive saving. |
| compressionSettings | [XarCompressionSettings](../../com.aspose.zip/xarcompressionsettings) | the compression settings used for added [XarEntry](../../com.aspose.zip/xarentry) item |
**Returns:**
[XarEntry](../../com.aspose.zip/xarentry) - Xar entry instance
### createEntry(String name, InputStream source) {#createEntry-java.lang.String-java.io.InputStream-}
public final XarEntry createEntry(String name, InputStream source)
Create a 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:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| source | java.io.InputStream | the input stream for the entry |
**Returns:**
[XarEntry](../../com.aspose.zip/xarentry) - Xar entry instance
### createEntry(String name, InputStream source, XarCompressionSettings compressionSettings) {#createEntry-java.lang.String-java.io.InputStream-com.aspose.zip.XarCompressionSettings-}
```
public final XarEntry createEntry(String name, InputStream source, XarCompressionSettings compressionSettings)
```
Create a 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:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| source | java.io.InputStream | the input stream for the entry |
| compressionSettings | [XarCompressionSettings](../../com.aspose.zip/xarcompressionsettings) | the compression settings used for added [XarEntry](../../com.aspose.zip/xarentry) item |
**Returns:**
[XarEntry](../../com.aspose.zip/xarentry) - Xar entry instance
### createEntry(String name, String sourcePath) {#createEntry-java.lang.String-java.lang.String-}
public final XarEntry createEntry(String name, String sourcePath)
Create a 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:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| sourcePath | java.lang.String | the path to the file to be compressed |
**Returns:**
[XarEntry](../../com.aspose.zip/xarentry) - Xar entry instance
### createEntry(String name, String sourcePath, boolean openImmediately) {#createEntry-java.lang.String-java.lang.String-boolean-}
```
public final XarEntry createEntry(String name, String sourcePath, boolean openImmediately)
```
Create a 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:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| sourcePath | java.lang.String | the path to the file to be compressed |
| openImmediately | boolean | true, if open the file immediately, otherwise open the file on archive saving |
**Returns:**
[XarEntry](../../com.aspose.zip/xarentry) - Xar entry instance
### createEntry(String name, String sourcePath, boolean openImmediately, XarCompressionSettings compressionSettings) {#createEntry-java.lang.String-java.lang.String-boolean-com.aspose.zip.XarCompressionSettings-}
public final XarEntry createEntry(String name, String sourcePath, boolean openImmediately, XarCompressionSettings compressionSettings)
Create a 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:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| sourcePath | java.lang.String | the path to the file to be compressed |
| openImmediately | boolean | true, if open the file immediately, otherwise open the file on archive saving |
| compressionSettings | [XarCompressionSettings](../../com.aspose.zip/xarcompressionsettings) | the compression settings used for added [XarEntry](../../com.aspose.zip/xarentry) item |
**Returns:**
[XarEntry](../../com.aspose.zip/xarentry) - Xar entry instance
### deleteEntry(XarEntry entry) {#deleteEntry-com.aspose.zip.XarEntry-}
```
public final XarArchive deleteEntry(XarEntry entry)
```
Removes the first occurrence of a specific entry from the entry 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:**
| Parameter | Type | Description |
| --- | --- | --- |
| entry | [XarEntry](../../com.aspose.zip/xarentry) | the entry to remove from the entries list |
**Returns:**
[XarArchive](../../com.aspose.zip/xararchive) - Xar entry instance
### extractToDirectory(String destinationDirectory) {#extractToDirectory-java.lang.String-}
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:**
| Parameter | Type | Description |
| --- | --- | --- |
| destinationDirectory | java.lang.String | the path to the directory to place the extracted files in.
If the directory does not exist, it will be created |
### getEntries() {#getEntries--}
```
public final List<XarEntry> getEntries()
```
Gets entries of [XarEntry](../../com.aspose.zip/xarentry) type constituting the archive.
**Returns:**
java.util.List<com.aspose.zip.XarEntry> - entries of [XarEntry](../../com.aspose.zip/xarentry) type constituting the archive
### getFileEntries() {#getFileEntries--}
```
public final Iterable<IArchiveFileEntry> getFileEntries()
```
Gets entries of [IArchiveFileEntry](../../com.aspose.zip/iarchivefileentry) type constituting the xar archive.
**Returns:**
java.lang.Iterable<com.aspose.zip.IArchiveFileEntry> - entries of [IArchiveFileEntry](../../com.aspose.zip/iarchivefileentry) type constituting the xar archive
### getFormat() {#getFormat--}
```
public final ArchiveFormat getFormat()
```
Gets the archive format.
**Returns:**
[ArchiveFormat](../../com.aspose.zip/archiveformat) - the archive format
### save(OutputStream output) {#save-java.io.OutputStream-}
```
public final void save(OutputStream output)
```
Saves archive to the stream provided.
For large archives use [save(String)](../../com.aspose.zip/xararchive\#save-String-) instead of saving to java.io.FileOutputStream.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| output | java.io.OutputStream | the destination stream |
### save(OutputStream output, XarSaveOptions saveOptions) {#save-java.io.OutputStream-com.aspose.zip.XarSaveOptions-}
```
public final void save(OutputStream output, XarSaveOptions saveOptions)
```
Saves archive to the stream provided.
For large archives use [save(String)](../../com.aspose.zip/xararchive\#save-String-) instead of saving to java.io.FileOutputStream.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| output | java.io.OutputStream | the destination stream |
| saveOptions | [XarSaveOptions](../../com.aspose.zip/xarsaveoptions) | the options to save xar archive with |
### save(String destinationFileName) {#save-java.lang.String-}
```
public final void save(String destinationFileName)
```
Saves archive to the destination file provided.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| destinationFileName | java.lang.String | the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten |
### save(String destinationFileName, XarSaveOptions saveOptions) {#save-java.lang.String-com.aspose.zip.XarSaveOptions-}
```
public final void save(String destinationFileName, XarSaveOptions saveOptions)
```
Saves archive to the destination file provided.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| destinationFileName | java.lang.String | the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten |
| saveOptions | [XarSaveOptions](../../com.aspose.zip/xarsaveoptions) | the options to save xar archive with |