Class Lz4Archive
- java.lang.Object
-
- com.aspose.zip.Lz4Archive
-
- All Implemented Interfaces:
IArchive,IArchiveFileEntry,AutoCloseable
public class Lz4Archive extends Object implements IArchive, IArchiveFileEntry, AutoCloseable
This class represents LZ4 archive file. Use it to extract or compose LZ4 archives.
-
-
Constructor Summary
Constructors Constructor Description Lz4Archive()Initializes a new instance of theLz4Archiveclass prepared for compressing.Lz4Archive(Lz4ArchiveSetting settings)Initializes a new instance of theLz4Archiveclass prepared for compressing.Lz4Archive(InputStream sourceStream)Initializes a new instance of theLz4Archiveclass prepared for decompressing.Lz4Archive(InputStream sourceStream, Lz4LoadOptions loadOptions)Initializes a new instance of theLz4Archiveclass prepared for decompressing.Lz4Archive(String path)Initializes a new instance of theLz4Archiveclass.Lz4Archive(String path, Lz4LoadOptions loadOptions)Initializes a new instance of theLz4Archiveclass.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidextract(OutputStream destination)Extracts the archive to the stream provided.Fileextract(String path)Extracts the archive to the file by path.voidextractToDirectory(String destinationDirectory)Extracts content of the archive to the directory provided.Iterable<IArchiveFileEntry>getFileEntries()Gets entries ofIArchiveFileEntrytype constituting the archive.ArchiveFormatgetFormat()Gets the archive format.LonggetLength()Gets length.StringgetName()Gets the original name.InputStreamopen()Opens the archive for extraction and provides a stream with archive content.voidsave(File destination)Saves lz4 archive to destination file provided.voidsave(OutputStream output)Saves lz4 archive to the stream provided.voidsave(String destinationFileName)Saves archive to the destination file provided.voidsetSource(TarArchive tarArchive)Sets the content to be compressed within the archive.voidsetSource(TarArchive tarArchive, TarFormat format)Sets the content to be compressed within the archive.voidsetSource(File fileInfo)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
-
Lz4Archive
public Lz4Archive(InputStream sourceStream)
Initializes a new instance of the
Lz4Archiveclass prepared for decompressing.Open an archive from a stream and extract it to a
MemoryStreamByteArrayOutputStream ms = new ByteArrayOutputStream(); try (Lz4Archive archive = new Lz4Archive(new FileInputStream("archive.lz4"))) { InputStream decompressed = archive.open(); byte[] b = new byte[8192]; int bytesRead; while (0 < (bytesRead = decompressed.read(b, 0, b.length))) { ms.write(b, 0, bytesRead); } } catch (IOException ex) { }This constructor does not decompress. See
open()method for decompressing.- Parameters:
sourceStream- the source of the archive- Throws:
com.aspose.ms.System.ArgumentException- Cannot read fromsourceStreamcom.aspose.ms.System.ArgumentNullException-sourceStreamis null.com.aspose.ms.System.IO.EndOfStreamException-sourceStreamis too short.com.aspose.ms.System.IO.InvalidDataException- ThesourceStreamhas wrong signature.
-
Lz4Archive
public Lz4Archive(InputStream sourceStream, Lz4LoadOptions loadOptions)
Initializes a new instance of the
Lz4Archiveclass prepared for decompressing.Open an archive from a stream and extract it to a
MemoryStreamByteArrayOutputStream ms = new ByteArrayOutputStream(); try (Lz4Archive archive = new Lz4Archive(new FileInputStream("archive.lz4"))) { InputStream decompressed = archive.open(); byte[] b = new byte[8192]; int bytesRead; while (0 < (bytesRead = decompressed.read(b, 0, b.length))) { ms.write(b, 0, bytesRead); } } catch (IOException ex) { }This constructor does not decompress. See
open()method for decompressing.- Parameters:
sourceStream- the source of the archiveloadOptions- The options to load archive with.- Throws:
com.aspose.ms.System.ArgumentException- Cannot read fromsourceStreamcom.aspose.ms.System.ArgumentNullException-sourceStreamis null.com.aspose.ms.System.IO.EndOfStreamException-sourceStreamis too short.com.aspose.ms.System.IO.InvalidDataException- ThesourceStreamhas wrong signature.
-
Lz4Archive
public Lz4Archive(String path)
Initializes a new instance of the
Lz4Archiveclass.Open an archive from file by path and extract it to a
MemoryStreamByteArrayOutputStream ms = new ByteArrayOutputStream(); try (Lz4Archive archive = new Lz4Archive("archive.lz4")) { InputStream decompressed = archive.open(); byte[] b = new byte[8192]; int bytesRead; while (0 < (bytesRead = decompressed.read(b, 0, b.length))) { ms.write(b, 0, bytesRead); } } catch (IOException ex) { }This constructor does not decompress. See
open()method for decompressing.- Parameters:
path- the path to the archive file- Throws:
com.aspose.ms.System.ArgumentNullException-pathis null.com.aspose.ms.System.SecurityException- The caller does not have the required permission to accesscom.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.EndOfStreamException- The file is too short.com.aspose.ms.System.IO.InvalidDataException- Data in the file has the wrong signature.
-
Lz4Archive
public Lz4Archive(String path, Lz4LoadOptions loadOptions)
Initializes a new instance of the
Lz4Archiveclass.Open an archive from file by path and extract it to a
MemoryStreamByteArrayOutputStream ms = new ByteArrayOutputStream(); try (Lz4Archive archive = new Lz4Archive("archive.lz4")) { InputStream decompressed = archive.open(); byte[] b = new byte[8192]; int bytesRead; while (0 < (bytesRead = decompressed.read(b, 0, b.length))) { ms.write(b, 0, bytesRead); } } catch (IOException ex) { }This constructor does not decompress. See
open()method for decompressing.- Parameters:
path- the path to the archive fileloadOptions- 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 accesscom.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.EndOfStreamException- The file is too short.com.aspose.ms.System.IO.InvalidDataException- Data in the file has the wrong signature.
-
Lz4Archive
public Lz4Archive()
Initializes a new instance of the
Lz4Archiveclass prepared for compressing.
-
Lz4Archive
public Lz4Archive(Lz4ArchiveSetting settings)
Initializes a new instance of the
Lz4Archiveclass prepared for compressing.- Parameters:
settings- The setting of the composed archive.
-
-
Method Detail
-
getName
public final String getName()
Gets the original name.
- Specified by:
getNamein interfaceIArchiveFileEntry- Returns:
- the original name
-
getLength
public final Long getLength()
Gets length.- Specified by:
getLengthin interfaceIArchiveFileEntry- Returns:
- length
-
getFileEntries
public final Iterable<IArchiveFileEntry> getFileEntries()
Gets entries of
IArchiveFileEntrytype constituting the archive.- Specified by:
getFileEntriesin interfaceIArchive- Returns:
- entries of
IArchiveFileEntrytype constituting the archive
-
getFormat
public final ArchiveFormat getFormat()
Gets the archive format.
-
extract
public final File extract(String path)
Extracts the archive to the file by path.
- Specified by:
extractin interfaceIArchiveFileEntry- Parameters:
path- the path to destination file. If the file already exists, it will be overwritten- Returns:
- info of an extracted file
- Throws:
com.aspose.ms.System.IO.EndOfStreamException- Source stream is too short.com.aspose.ms.System.IO.InvalidDataException- Wrong bytes found while decoding.com.aspose.ms.System.NotSupportedException- This LZ4 version is not supported.
-
extract
public final void extract(OutputStream destination)
Extracts the archive to the stream provided.
OutputStream httpResponseStream = null; try (Lz4Archive archive = new Lz4Archive("archive.lz4")) { archive.extract(httpResponseStream); }- Specified by:
extractin interfaceIArchiveFileEntry- Parameters:
destination- destination stream- Throws:
com.aspose.ms.System.ArgumentException-destinationdoes not support writing.com.aspose.ms.System.IO.EndOfStreamException- Source stream is too short.com.aspose.ms.System.IO.InvalidDataException- Wrong bytes found while decoding.com.aspose.ms.System.NotSupportedException- This LZ4 version is not supported.com.aspose.ms.System.InvalidOperationException- The archive is prepared for composition.
-
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. -or- path is prefixed with, or contains, only a colon character (:).com.aspose.ms.System.IO.IOException- The directory specified by path is a file. -or- The network name is not known.com.aspose.ms.System.IO.EndOfStreamException- Source stream is too short.com.aspose.ms.System.IO.InvalidDataException- Wrong bytes found while initialize decoding.com.aspose.ms.System.InvalidOperationException- The archive is prepared for composition.
-
open
public final InputStream open()
Opens the archive for extraction and provides a stream with archive content.
Extracts the archive and copies extracted content to file stream.
try (Lz4Archive archive = new Lz4Archive("archive.lz4")) { try (FileOutputStream extracted = new FileOutputStream("data.bin")) { InputStream unpacked = archive.open(); byte[] b = new byte[8192]; int bytesRead; while (0 < (bytesRead = unpacked.read(b, 0, b.length))) { extracted.write(b, 0, bytesRead); } } } catch (IOException ex) { }Read from the stream to get the original content of a file. See examples section.
- Returns:
- the stream that represents the contents of the archive
- Throws:
com.aspose.ms.System.IO.EndOfStreamException- Source stream is too short.com.aspose.ms.System.IO.InvalidDataException- Wrong bytes found while initialize decoding.com.aspose.ms.System.InvalidOperationException- The archive is prepared for composition.
-
save
public final void save(OutputStream output)
Saves lz4 archive to the stream provided.
try (FileOutputStream lz4File = new FileOutputStream("archive.lz4")) { try (Lz4Archive archive = new Lz4Archive()) { archive.setSource("data.bin"); archive.save(lz4File); } } catch (IOException ex) { }- Parameters:
output- Destination stream.- Throws:
com.aspose.ms.System.ArgumentNullException-outputis null.com.aspose.ms.System.ArgumentException-outputis not writable.com.aspose.ms.System.InvalidOperationException- The archive is prepared for extraction. - or - Source was not supplied.
-
save
public final void save(File destination)
Saves lz4 archive to destination file provided.
try (Lz4Archive archive = new Lz4Archive()) { archive.setSource(new File("data.bin")); archive.save(new File("archive.lz4")); }- Parameters:
destination- 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.com.aspose.ms.System.InvalidOperationException- The archive is prepared for extraction.
-
save
public final void save(String destinationFileName)
Saves archive to the destination file provided.
try (Lz4Archive archive = new Lz4Archive()) { archive.setSource("data.bin"); archive.save("archive.lz4"); }- 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 accesscom.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.com.aspose.ms.System.InvalidOperationException- The archive is prepared for extraction.
-
setSource
public final void setSource(InputStream source)
Sets the content to be compressed within the archive.
try (Lz4Archive archive = new Lz4Archive()) { archive.setSource(new ByteArrayInputStream(new byte[] { 0x00, (byte) 0xFF })); archive.save("archive.lz4"); }- Parameters:
source- The input stream for the archive.- Throws:
com.aspose.ms.System.InvalidOperationException- The archive is prepared for extraction.
-
setSource
public final void setSource(File fileInfo)
Sets the content to be compressed within the archive.
Open an archive from a stream and extract it to a
MemoryStreamtry (Lz4Archive archive = new Lz4Archive()) { archive.setSource(new File("data.bin")); archive.save("archive.lz4"); }- Parameters:
fileInfo- The reference to a file to be compressed.- Throws:
com.aspose.ms.System.InvalidOperationException- The archive is prepared for extraction.
-
setSource
public final void setSource(TarArchive tarArchive)
Sets the content to be compressed within the archive.
try (TarArchive tarArchive = new TarArchive()) { tarArchive.createEntry("first.bin", "data1.bin"); tarArchive.createEntry("second.bin", "data2.bin"); try (Lz4Archive lz4Archive = new Lz4Archive()) { lz4Archive.setSource(tarArchive); lz4Archive.save("archive.tar.lz4"); } }Use this method to compose joint tar.lz4 archive.
- Parameters:
tarArchive- Tar archive to be compressed.
-
setSource
public final void setSource(TarArchive tarArchive, TarFormat format)
Sets the content to be compressed within the archive.
try (TarArchive tarArchive = new TarArchive()) { tarArchive.createEntry("first.bin", "data1.bin"); tarArchive.createEntry("second.bin", "data2.bin"); try (Lz4Archive lz4Archive = new Lz4Archive()) { lz4Archive.setSource(tarArchive); lz4Archive.save("archive.tar.lz4"); } }Use this method to compose joint tar.lz4 archive.
- Parameters:
tarArchive- Tar archive to be compressed.format- Defines tar header format.
-
setSource
public final void setSource(String path)
Sets the content to be compressed within the archive.
Open an archive from file by path and extract it to a
MemoryStreamtry (Lz4Archive archive = new Lz4Archive()) { archive.setSource("data.bin"); archive.save("archive.lz4"); }- Parameters:
path- Path to 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 accesscom.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.InvalidOperationException- This archive is prepared for extraction.
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceIArchive
-
-