Class ZArchive
- java.lang.Object
-
- com.aspose.zip.ZArchive
-
- All Implemented Interfaces:
IArchive,IArchiveFileEntry,AutoCloseable
public class ZArchive extends Object implements IArchiveFileEntry, IArchive, AutoCloseable
This class represents a Z (compress) archive file. Use it to compose or extract Z archives.
-
-
Constructor Summary
Constructors Constructor Description ZArchive()Initializes a new instance of theZArchiveclass prepared for compressing.ZArchive(InputStream source)Initializes a new instance of theZArchiveclass prepared for decompressing.ZArchive(InputStream source, ZArchiveLoadOptions loadOptions)Initializes a new instance of theZArchiveclass prepared for decompressing.ZArchive(String path)Initializes a new instance of theZArchiveclass prepared for decompressing.ZArchive(String path, ZArchiveLoadOptions loadOptions)Initializes a new instance of theZArchiveclass prepared for decompressing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidextract(File file)Extracts Z archive to a file.voidextract(OutputStream destination)Extracts Z archive to a stream.Fileextract(String path)Extracts Z archive to a file by path.voidextractToDirectory(String destinationDirectory)Extracts content of the archive to the directory provided.Iterable<IArchiveFileEntry>getFileEntries()Gets entries ofIArchiveFileEntrytype constituting the Z archive.ArchiveFormatgetFormat()Gets the archive format.LonggetLength()Gets the length of the entry in bytes.StringgetName()Gets the name of the entry within archive.voidsave(OutputStream output)Saves Z archive to the stream provided.voidsave(OutputStream output, ZArchiveSaveOptions settings)Saves Z archive to the stream provided.voidsave(String destinationFileName)Saves Z archive to the destination file provided.voidsave(String destinationFileName, ZArchiveSaveOptions settings)Saves Z archive to the destination file provided.voidsetSource(File file)Sets the content to be compressed within the archive.voidsetSource(InputStream source)Sets the content to be compressed within the archive.voidsetSource(String sourcePath)Sets the content to be compressed within the archive.
-
-
-
Constructor Detail
-
ZArchive
public ZArchive()
Initializes a new instance of the
ZArchiveclass prepared for compressing.
-
ZArchive
public ZArchive(InputStream source)
Initializes a new instance of the
ZArchiveclass prepared for decompressing.This constructor does not decompress. See
extract(OutputStream)method for decompressing.- Parameters:
source- the source of the archive- Throws:
com.aspose.ms.System.ArgumentNullException-sourceis null.
-
ZArchive
public ZArchive(InputStream source, ZArchiveLoadOptions loadOptions)
Initializes a new instance of the
ZArchiveclass prepared for decompressing.This constructor does not decompress. See
extract(OutputStream)method for decompressing.- Parameters:
source- the source of the archiveloadOptions- the options to load archive with- Throws:
com.aspose.ms.System.ArgumentNullException-sourceis null.
-
ZArchive
public ZArchive(String path)
Initializes a new instance of the
ZArchiveclass prepared for decompressing.This constructor does not decompress. See
extract(String)method for decompressing.- Parameters:
path- the path to the source of the archive- Throws:
com.aspose.ms.System.ArgumentNullException-pathis null.com.aspose.ms.System.SecurityException- The caller does not have the required permission to access.com.aspose.ms.System.ArgumentException- Thepathis empty, contains only white spaces, or contains invalid characters.com.aspose.ms.System.IO.PathTooLongException- The specifiedpath, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.com.aspose.ms.System.NotSupportedException- File atpathcontains a colon (:) in the middle of the string.com.aspose.ms.System.IO.FileNotFoundException- The file is not found.com.aspose.ms.System.IO.DirectoryNotFoundException- The specified path is invalid, such as being on an unmapped drive.com.aspose.ms.System.IO.IOException- The file is already open.
-
ZArchive
public ZArchive(String path, ZArchiveLoadOptions loadOptions)
Initializes a new instance of the
ZArchiveclass prepared for decompressing.This constructor does not decompress. See
extract(String)method for decompressing.- Parameters:
path- the path to the source of the archiveloadOptions- the options to load archive with- Throws:
com.aspose.ms.System.ArgumentNullException-pathis null.com.aspose.ms.System.SecurityException- The caller does not have the required permission to access.com.aspose.ms.System.ArgumentException- Thepathis empty, contains only white spaces, or contains invalid characters.com.aspose.ms.System.IO.PathTooLongException- The specifiedpath, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.com.aspose.ms.System.NotSupportedException- File atpathcontains a colon (:) in the middle of the string.com.aspose.ms.System.IO.FileNotFoundException- The file is not found.com.aspose.ms.System.IO.DirectoryNotFoundException- The specified path is invalid, such as being on an unmapped drive.com.aspose.ms.System.IO.IOException- The file is already open.
-
-
Method Detail
-
getName
public final String getName()
Gets the name of the entry within archive.
- Specified by:
getNamein interfaceIArchiveFileEntry- Returns:
- the name of the entry within archive
-
getLength
public final Long getLength()
Gets the length of the entry in bytes.
- Specified by:
getLengthin interfaceIArchiveFileEntry- Returns:
- the length of the entry in bytes
-
getFileEntries
public final Iterable<IArchiveFileEntry> getFileEntries()
Gets entries of
IArchiveFileEntrytype constituting the Z archive.- Specified by:
getFileEntriesin interfaceIArchive- Returns:
- entries of
IArchiveFileEntrytype constituting the Z archive
-
getFormat
public final ArchiveFormat getFormat()
Gets the archive format.
-
extract
public final void extract(OutputStream destination)
Extracts Z archive to a stream.
try (FileInputStream zFile = new FileInputStream("sourceFileName")) { try (FileOutputStream extractedFile = new FileOutputStream("extractedFileName")) { try (ZArchive archive = new ZArchive(zFile)) { archive.extract(extractedFile); } } } catch (IOException ex) { }- Specified by:
extractin interfaceIArchiveFileEntry- Parameters:
destination- the stream for storing decompressed data- Throws:
com.aspose.ms.System.IO.InvalidDataException- Data can not be decompressed.
-
extract
public final void extract(File file)
Extracts Z archive to a file.
try (FileInputStream zFile = new FileInputStream("sourceFileName")) { try (ZArchive archive = new ZArchive(zFile)) { archive.extract(new File("extracted.bin")); } } catch (IOException ex) { }- Parameters:
file- the file for storing decompressed data- Throws:
com.aspose.ms.System.SecurityException- The caller does not have the required permission to open thefile.com.aspose.ms.System.ArgumentException- The file path is empty or contains only white spaces.com.aspose.ms.System.IO.FileNotFoundException- The file is not found.com.aspose.ms.System.ArgumentNullException-fileis null.com.aspose.ms.System.IO.DirectoryNotFoundException- The specified path is invalid, such as being on an unmapped drive.com.aspose.ms.System.IO.IOException- The file is already open.com.aspose.ms.System.IO.InvalidDataException- Data can not be decompressed.
-
extract
public final File extract(String path)
Extracts Z archive to a file by path.
try (FileInputStream zFile = new FileInputStream("sourceFileName")) { try (ZArchive archive = new ZArchive(zFile)) { archive.extract("extracted.bin"); } } catch (IOException ex) { }- Specified by:
extractin interfaceIArchiveFileEntry- Parameters:
path- the path to file which will store decompressed data- Returns:
- the file info of the extracted file
- Throws:
com.aspose.ms.System.ArgumentNullException-pathis null.com.aspose.ms.System.SecurityException- The caller does not have the required permission to access.com.aspose.ms.System.ArgumentException- Thepathis empty, contains only white spaces, or contains invalid characters.com.aspose.ms.System.IO.PathTooLongException- The specifiedpath, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.com.aspose.ms.System.NotSupportedException- File atpathcontains a colon (:) in the middle of the string.com.aspose.ms.System.IO.InvalidDataException- Data can not be decompressed.
-
extractToDirectory
public final void extractToDirectory(String destinationDirectory)
Extracts content of the archive to the directory provided.
- Specified by:
extractToDirectoryin interfaceIArchive- Parameters:
destinationDirectory- the path to the directory to place the extracted files inIf the directory does not exist, it will be created.
- Throws:
com.aspose.ms.System.ArgumentNullException-destinationDirectoryis null.com.aspose.ms.System.IO.PathTooLongException- The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters.com.aspose.ms.System.SecurityException- The caller does not have the required permission to access the existing directory.com.aspose.ms.System.NotSupportedException- If the directory does not exist, the path contains a colon character (:) that is not part of a drive label ("C:\").com.aspose.ms.System.ArgumentException-destinationDirectoryis a zero-length string, contains only white space, or contains one or more invalid characters.com.aspose.ms.System.IO.IOException- The directory specified by path is a file. -or- The network name is not known.
-
save
public final void save(OutputStream output)
Saves Z archive to the stream provided.
try (FileOutputStream zFile = new FileOutputStream("data.bin.Z")) { try (ZArchive archive = new ZArchive()) { archive.setSource("data.bin"); archive.save(zFile); } } catch (IOException ex) { }- Parameters:
output- the destination stream- Throws:
com.aspose.ms.System.ArgumentException-outputdoes not support seeking.com.aspose.ms.System.ArgumentNullException-outputis null.
-
save
public final void save(OutputStream output, ZArchiveSaveOptions settings)
Saves Z archive to the stream provided.
try (FileOutputStream zFile = new FileOutputStream("data.bin.Z")) { try (ZArchive archive = new ZArchive()) { archive.setSource("data.bin"); archive.save(zFile); } } catch (IOException ex) { }- Parameters:
output- the destination streamsettings- the settings for archive composition- Throws:
com.aspose.ms.System.ArgumentException-outputdoes not support seeking.com.aspose.ms.System.ArgumentNullException-outputis null.
-
save
public final void save(String destinationFileName)
Saves Z archive to the destination file provided.
try (ZArchive archive = new ZArchive()) { archive.setSource(new File("data.bin")); archive.save("data.bin.Z"); }- Parameters:
destinationFileName- the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten- Throws:
com.aspose.ms.System.ArgumentNullException-destinationFileNameis null.com.aspose.ms.System.SecurityException- The caller does not have the required permission to access.com.aspose.ms.System.ArgumentException- ThedestinationFileNameis empty, contains only white spaces, or contains invalid characters.com.aspose.ms.System.IO.PathTooLongException- The specifieddestinationFileName, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.com.aspose.ms.System.NotSupportedException- File atdestinationFileNamecontains a colon (:) in the middle of the string.
-
save
public final void save(String destinationFileName, ZArchiveSaveOptions settings)
Saves Z archive to the destination file provided.
try (ZArchive archive = new ZArchive()) { archive.setSource(new File("data.bin")); archive.save("data.bin.Z"); }- Parameters:
destinationFileName- the path of the archive to be created. If the specified file name points to an existing file, it will be overwrittensettings- the settings for archive composition- Throws:
com.aspose.ms.System.ArgumentNullException-destinationFileNameis null.com.aspose.ms.System.SecurityException- The caller does not have the required permission to access.com.aspose.ms.System.ArgumentException- ThedestinationFileNameis empty, contains only white spaces, or contains invalid characters.com.aspose.ms.System.IO.PathTooLongException- The specifieddestinationFileName, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.com.aspose.ms.System.NotSupportedException- File atdestinationFileNamecontains a colon (:) in the middle of the string.
-
setSource
public final void setSource(InputStream source)
Sets the content to be compressed within the archive.
try (ZArchive archive = new ZArchive()) { archive.setSource(new ByteArrayInputStream(new byte[] { 0x00, (byte) 0xFF })); archive.save("archive.Z"); }- Parameters:
source- the input stream for the archive
-
setSource
public final void setSource(File file)
Sets the content to be compressed within the archive.
try (ZArchive archive = new ZArchive()) { archive.setSource(new File("data.bin")); archive.save("data.bin.Z"); }- Parameters:
file- the file info which will be opened as input stream- Throws:
com.aspose.ms.System.SecurityException- The caller does not have the required permission to open thefile.com.aspose.ms.System.ArgumentException- The file path is empty or contains only white spaces.com.aspose.ms.System.IO.FileNotFoundException- The file is not found.com.aspose.ms.System.ArgumentNullException-fileis null.com.aspose.ms.System.IO.DirectoryNotFoundException- The specified path is invalid, such as being on an unmapped drive.com.aspose.ms.System.IO.IOException- The file is already open.
-
setSource
public final void setSource(String sourcePath)
Sets the content to be compressed within the archive.
try (ZArchive archive = new ZArchive()) { archive.setSource("data.bin"); archive.save("data.bin.Z"); }- Parameters:
sourcePath- the path to the file which will be opened as input stream- Throws:
com.aspose.ms.System.ArgumentNullException-sourcePathis null or empty string.com.aspose.ms.System.SecurityException- The caller does not have the required permission to access a resource.com.aspose.ms.System.ArgumentException- ThesourcePathis empty, contains only white spaces, or contains invalid characters.com.aspose.ms.System.IO.PathTooLongException- The specifiedsourcePath, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.com.aspose.ms.System.NotSupportedException- File atsourcePathcontains a colon (:) in the middle of the string.
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceIArchive
-
-