XarArchive
Inheritance: java.lang.Object
All Implemented Interfaces: com.aspose.zip.IArchive, java.lang.AutoCloseable
public class XarArchive implements IArchive, AutoCloseable
This class represents 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 entries list can be extracted from the archive. |
XarArchive(InputStream sourceStream, XarLoadOptions loadOptions) | 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. |
XarArchive(String path, XarLoadOptions loadOptions) | Initializes a new instance of the XarArchive class and composes entries list can be extracted from the archive. |
Methods
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:
Parameter | Type | Description |
---|---|---|
defaultCompressionSettings | XarCompressionSettings | the 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:
Parameter | Type | Description |
---|---|---|
sourceStream | java.io.InputStream | the source of the archive |
XarArchive(InputStream sourceStream, XarLoadOptions loadOptions)
public XarArchive(InputStream sourceStream, XarLoadOptions loadOptions)
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:
Parameter | Type | Description |
---|---|---|
sourceStream | java.io.InputStream | the source of the archive |
loadOptions | XarLoadOptions | the options to load archive with |
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:
Parameter | Type | Description |
---|---|---|
path | java.lang.String | the path to the archive file |
XarArchive(String path, XarLoadOptions loadOptions)
public XarArchive(String path, XarLoadOptions loadOptions)
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:
Parameter | Type | Description |
---|---|---|
path | java.lang.String | the path to the archive file |
loadOptions | XarLoadOptions | the options to load archive with |
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:
Parameter | Type | Description |
---|---|---|
directory | java.io.File | directory 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:
Parameter | Type | Description |
---|---|---|
directory | java.io.File | directory to compress |
includeRootDirectory | boolean | indicates 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:
Parameter | Type | Description |
---|---|---|
directory | java.io.File | directory to compress |
includeRootDirectory | boolean | indicates whether to include the root directory itself or not |
compressionSettings | XarCompressionSettings | the 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:
Parameter | Type | Description |
---|---|---|
sourceDirectory | java.lang.String | directory 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:
Parameter | Type | Description |
---|---|---|
sourceDirectory | java.lang.String | directory to compress |
includeRootDirectory | boolean | indicates 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:
Parameter | Type | Description |
---|---|---|
sourceDirectory | java.lang.String | directory to compress |
includeRootDirectory | boolean | indicates whether to include the root directory itself or not |
compressionSettings | XarCompressionSettings | the 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:
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 - 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:
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 - 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:
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 | the 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:
Parameter | Type | Description |
---|---|---|
name | java.lang.String | the name of the entry |
source | java.io.InputStream | the 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:
Parameter | Type | Description |
---|---|---|
name | java.lang.String | the name of the entry |
source | java.io.InputStream | the input stream for the entry |
compressionSettings | XarCompressionSettings | the 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:
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 - 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:
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 - 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:
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 | the 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:
Parameter | Type | Description |
---|---|---|
entry | XarEntry | the entry to remove from the entries list |
Returns: XarArchive - Xar entry instance
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:
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()
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:
Parameter | Type | Description |
---|---|---|
output | java.io.OutputStream | the destination stream |
save(OutputStream output, XarSaveOptions saveOptions)
public final void save(OutputStream output, XarSaveOptions saveOptions)
Saves archive to the stream provided.
For large archives use save(String) instead of saving to java.io.FileOutputStream.
Parameters:
Parameter | Type | Description |
---|---|---|
output | java.io.OutputStream | the destination stream |
saveOptions | XarSaveOptions | the options to save xar archive with |
save(String destinationFileName)
public final void save(String destinationFileName)
Saves archive to 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)
public final void save(String destinationFileName, XarSaveOptions saveOptions)
Saves archive to 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 | the options to save xar archive with |