Class LzipArchive
- java.lang.Object
-
- com.aspose.zip.LzipArchive
-
- All Implemented Interfaces:
IArchive,IArchiveFileEntry,AutoCloseable
public class LzipArchive extends Object implements IArchive, IArchiveFileEntry, AutoCloseable
This class represents a Lzip archive file. Use it to compose or extract Lzip archives.
-
-
Constructor Summary
Constructors Constructor Description LzipArchive()Initializes a new instance of theLzipArchive.LzipArchive(LzipArchiveSettings settings)Initializes a new instance of theLzipArchive.LzipArchive(InputStream sourceStream)Initializes a new instance of theLzipArchiveclass prepared for decompressing.LzipArchive(InputStream sourceStream, LzipLoadOptions options)Initializes a new instance of theLzipArchiveclass prepared for decompressing.LzipArchive(String path)Initializes a new instance of theLzipArchiveclass prepared for decompressing.LzipArchive(String path, LzipLoadOptions options)Initializes a new instance of theLzipArchiveclass prepared for decompressing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidextract(File file)Extracts lzip archive to a file.voidextract(OutputStream destination)Extracts lzip archive to a stream.Fileextract(String path)Extracts lzip 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 lzip archive.ArchiveFormatgetFormat()Gets the archive format.LonggetLength()Gets length.StringgetName()The name of original file.LzipArchiveSettingsgetSettings()Gets the setting of particular lzip archive.voidsave(File destination)Saves lzip archive to destination file provided.voidsave(OutputStream outputStream)Saves lzip archive to the stream provided.voidsave(String destinationFileName)Saves lzip archive to 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 path)Sets the content to be compressed within the archive.
-
-
-
Constructor Detail
-
LzipArchive
public LzipArchive()
Initializes a new instance of the
LzipArchive.
-
LzipArchive
public LzipArchive(LzipArchiveSettings settings)
Initializes a new instance of the
LzipArchive.- Parameters:
settings- the setting of particular lzip archive with definition of dictionary size
-
LzipArchive
public LzipArchive(InputStream sourceStream)
Initializes a new instance of the
LzipArchiveclass prepared for decompressing.try (FileInputStream sourceLzipFile = new FileInputStream("sourceLzipFile")) { try (FileOutputStream extractedFile = new FileOutputStream("extractedFileName")) { try (LzipArchive archive = new LzipArchive(sourceLzipFile)) { archive.extract(extractedFile); } } } catch (IOException ex) { }This constructor does not decompress. See
extract(OutputStream)method for decompressing.- Parameters:
sourceStream- the source of the archive- Throws:
com.aspose.ms.System.ArgumentException-sourceStreamis not seekable.com.aspose.ms.System.ArgumentNullException-sourceStreamis null.com.aspose.ms.System.IO.InvalidDataException- Headers do not match lzip type of archive.
-
LzipArchive
public LzipArchive(InputStream sourceStream, LzipLoadOptions options)
Initializes a new instance of the
LzipArchiveclass prepared for decompressing.try (FileInputStream sourceLzipFile = new FileInputStream("sourceLzipFile")) { try (FileOutputStream extractedFile = new FileOutputStream("extractedFileName")) { try (LzipArchive archive = new LzipArchive(sourceLzipFile)) { archive.extract(extractedFile); } } } catch (IOException ex) { }This constructor does not decompress. See
extract(OutputStream)method for decompressing.- Parameters:
sourceStream- the source of the archiveoptions- Options to load the archive with.- Throws:
com.aspose.ms.System.ArgumentException-sourceStreamis not seekable.com.aspose.ms.System.ArgumentNullException-sourceStreamis null.com.aspose.ms.System.IO.InvalidDataException- Headers do not match lzip type of archive.
-
LzipArchive
public LzipArchive(String path)
Initializes a new instance of the
LzipArchiveclass prepared for decompressing.try (FileOutputStream extractedFile = new FileOutputStream("extractedFileName")) { try (LzipArchive archive = new LzipArchive("sourceLzipFileName")) { archive.extract(extractedFile); } } catch (IOException ex) { }This constructor does not decompress. See
extract(OutputStream)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.com.aspose.ms.System.IO.InvalidDataException- Headers do not match lzip type of archive.
-
LzipArchive
public LzipArchive(String path, LzipLoadOptions options)
Initializes a new instance of the
LzipArchiveclass prepared for decompressing.try (FileOutputStream extractedFile = new FileOutputStream("extractedFileName")) { try (LzipArchive archive = new LzipArchive("sourceLzipFileName")) { archive.extract(extractedFile); } } catch (IOException ex) { }This constructor does not decompress. See
extract(OutputStream)method for decompressing.- Parameters:
path- the path to the source of the archiveoptions- Options to load the 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.com.aspose.ms.System.IO.InvalidDataException- Headers do not match lzip type of archive.
-
-
Method Detail
-
getFileEntries
public final Iterable<IArchiveFileEntry> getFileEntries()
Gets entries of
IArchiveFileEntrytype constituting the lzip archive.- Specified by:
getFileEntriesin interfaceIArchive- Returns:
- entries of
IArchiveFileEntrytype constituting the lzip archive
-
getFormat
public final ArchiveFormat getFormat()
Gets the archive format.
-
getSettings
public final LzipArchiveSettings getSettings()
Gets the setting of particular lzip archive.
- Returns:
- the setting of particular lzip archive
-
getName
public final String getName()
The name of original file.
- Specified by:
getNamein interfaceIArchiveFileEntry- Returns:
- the name of the original file
-
getLength
public final Long getLength()
Gets length.- Specified by:
getLengthin interfaceIArchiveFileEntry- Returns:
- length
-
extract
public final void extract(OutputStream destination)
Extracts lzip archive to a stream.
try (FileInputStream sourceLzipFile = new FileInputStream("sourceLzipFile")) { try (FileOutputStream extractedFile = new FileOutputStream("extractedFileName")) { try (LzipArchive archive = new LzipArchive(sourceLzipFile)) { archive.extract(extractedFile); } } } catch (IOException ex) { }- Specified by:
extractin interfaceIArchiveFileEntry- Parameters:
destination- the stream for storing decompressed data- Throws:
com.aspose.ms.System.InvalidOperationException- Archive headers and service information were not read.com.aspose.ms.System.IO.InvalidDataException- Error in data in header or checksum.com.aspose.ms.System.ArgumentNullException- Destination stream is null.com.aspose.ms.System.ArgumentException- Destination stream does not support writing.
-
extract
public final void extract(File file)
Extracts lzip archive to a file.
try (FileInputStream lzipFile = new FileInputStream("sourceFileName")) { try (LzipArchive archive = new LzipArchive(lzipFile)) { archive.extract(new File("extracted.bin")); } } catch (IOException ex) { }- Parameters:
file- the file for storing decompressed data- Throws:
com.aspose.ms.System.InvalidOperationException- Archive headers and service information were not read.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.
-
extract
public final File extract(String path)
Extracts lzip archive to a file by path.
try (FileInputStream lzipFile = new FileInputStream("sourceFileName")) { try (LzipArchive archive = new LzipArchive(lzipFile)) { archive.extract("extracted.bin"); } } catch (IOException ex) { }- Specified by:
extractin interfaceIArchiveFileEntry- Parameters:
path- the path to the file which will store decompressed data- Returns:
- the file info of the extracted file
- Throws:
com.aspose.ms.System.InvalidOperationException- Archive headers and service information were not read.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.
-
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 in.If 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 outputStream)
Saves lzip archive to the stream provided.
try (FileOutputStream lzFile = new FileOutputStream("archive.lz")) { try (LzipArchive archive = new LzipArchive()) { archive.setSource("data.bin"); archive.save(lzFile); } } catch (IOException ex) { }- Parameters:
outputStream- destination stream- Throws:
com.aspose.ms.System.ArgumentException-outputStreamdoes not support seeking.com.aspose.ms.System.ArgumentNullException-outputStreamis null.
-
setSource
public final void setSource(InputStream source)
Sets the content to be compressed within the archive.
try (LzipArchive archive = new LzipArchive()) { archive.setSource(new ByteArrayInputStream(new byte[] {0x00, (byte)0xFF} )); archive.save("archive.lz"); }- Parameters:
source- the input stream for the archive- Throws:
com.aspose.ms.System.ArgumentException- Thesourcestream is unseekable.
-
setSource
public final void setSource(File file)
Sets the content to be compressed within the archive.
try (LzipArchive archive = new LzipArchive()) { archive.setSource(new File("data.bin")); archive.save("archive.lz"); }- Parameters:
file- the file 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- 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 path)
Sets the content to be compressed within the archive.
try (LzipArchive archive = new LzipArchive()) { archive.setSource("data.bin"); archive.save("archive.lz"); }- Parameters:
path- the path to the file to be compressed- 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.
-
save
public final void save(String destinationFileName)
Saves lzip archive to destination file provided.
try (LzipArchive archive = new LzipArchive()) { archive.setSource(new File("data.bin")); archive.save("result.lz"); }- 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(File destination)
Saves lzip archive to destination file provided.
try (LzipArchive archive = new LzipArchive()) { archive.setSource(new File("data.bin")); archive.save(new File("archive.lz")); }- Parameters:
destination- the file, which will be opened as destination stream- Throws:
com.aspose.ms.System.SecurityException- The caller does not have the required permission to open thedestination.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-destinationis 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.
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceIArchive
-
-