Class SevenZipArchiveEntry
- java.lang.Object
-
- com.aspose.zip.SevenZipArchiveEntry
-
- All Implemented Interfaces:
IArchiveFileEntry
- Direct Known Subclasses:
SevenZipArchiveEntryEncrypted,SevenZipArchiveEntryPlain
public abstract class SevenZipArchiveEntry extends Object implements IArchiveFileEntry
Represents a single file within 7z archive.
Cast an
SevenZipArchiveEntryinstance toSevenZipArchiveEntryEncryptedto determine whether the entry encrypted or not.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidextract(OutputStream destination)Extracts the entry to the stream provided.voidextract(OutputStream destination, String password)Extracts the entry to the stream provided.Fileextract(String path)Extracts the entry to the filesystem by the path provided.Fileextract(String path, String password)Extracts the entry to the filesystem by the path provided.longgetCompressedSize()Gets the size of the compressed file.Event<ProgressEventArgs>getCompressionProgressed()Gets an event that is raised when a portion of raw stream compressed.SevenZipCompressionSettingsgetCompressionSettings()Gets settings for compression or decompression.LonggetLength()Gets length.DategetModificationTime()Gets last modified date and time.StringgetName()Gets the name of the entry within the archive.longgetUncompressedSize()Gets the size of the original file.booleanisDirectory()Gets a value indicating whether the entry represents a directory.InputStreamopen()Opens the entry for extraction and provides a stream with entry content.InputStreamopen(String password)Opens the entry for extraction and provides a stream with entry content.voidsetCompressionProgressed(Event<ProgressEventArgs> value)Sets an event that is raised when a portion of raw stream compressed.
-
-
-
Method Detail
-
getName
public final String getName()
Gets the name of the entry within the archive.
- Specified by:
getNamein interfaceIArchiveFileEntry- Returns:
- the name of the entry within the archive
-
getModificationTime
public final Date getModificationTime()
Gets last modified date and time.
- Returns:
- last modified date and time
-
getUncompressedSize
public final long getUncompressedSize()
Gets the size of the original file.
- Returns:
- the size of the original file
-
getLength
public final Long getLength()
Gets length.- Specified by:
getLengthin interfaceIArchiveFileEntry- Returns:
- length
-
getCompressedSize
public final long getCompressedSize()
Gets the size of the compressed file.
- Returns:
- the size of the compressed file
-
isDirectory
public final boolean isDirectory()
Gets a value indicating whether the entry represents a directory.
- Returns:
- a value indicating whether the entry represents a directory
-
getCompressionSettings
public final SevenZipCompressionSettings getCompressionSettings()
Gets settings for compression or decompression.
- Returns:
- settings for compression or decompression
-
getCompressionProgressed
public final Event<ProgressEventArgs> getCompressionProgressed()
Gets an event that is raised when a portion of raw stream compressed.
archive.getEntries().get(0).setCompressionProgressed(new Event<ProgressEventArgs>() { public void invoke(Object sender, ProgressEventArgs progressEventArgs) { int percent = (int) ((100 * (long) progressEventArgs.getProceededBytes()) / entrySourceFile.length()); } });Event sender is an
SevenZipArchiveEntryinstance.Does not invoke in solid mode and in multithreaded mode for LZMA2 entries.
- Returns:
- an event that is raised when a portion of raw stream compressed
-
setCompressionProgressed
public final void setCompressionProgressed(Event<ProgressEventArgs> value)
Sets an event that is raised when a portion of raw stream compressed.
archive.getEntries().get(0).setCompressionProgressed(new Event<ProgressEventArgs>() { public void invoke(Object sender, ProgressEventArgs progressEventArgs) { int percent = (int) ((100 * (long) progressEventArgs.getProceededBytes()) / entrySourceFile.length()); } });Event sender is an
SevenZipArchiveEntryinstance.Does not invoke in solid mode and in multithreaded mode for LZMA2 entries.
- Parameters:
value- an event that is raised when a portion of raw stream compressed
-
extract
public final File extract(String path)
Extracts the entry to the filesystem by the path provided.
try (SevenZipArchive archive = new SevenZipArchive("archive.7z")) { archive.getEntries().get(0).extract("data.bin"); }- Specified by:
extractin interfaceIArchiveFileEntry- Parameters:
path- the path to destination file. If the file already exists, it will be overwritten- 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- The archive is corrupted.
-
extract
public final File extract(String path, String password)
Extracts the entry to the filesystem by the path provided.
try (SevenZipArchive archive = new SevenZipArchive("archive.7z")) { archive.getEntries().get(0).extract("data.bin"); }- Parameters:
path- the path to destination file. If the file already exists, it will be overwrittenpassword- optional password for decryption- 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- The archive is corrupted.
-
extract
public final void extract(OutputStream destination)
Extracts the entry to the stream provided.
Extract an entry of zip archive with password.
try (SevenZipArchive archive = new SevenZipArchive("archive.7z")) { archive.getEntries().get(0).extract(httpResponseStream); }- Specified by:
extractin interfaceIArchiveFileEntry- Parameters:
destination- destination stream. Must be writable- Throws:
com.aspose.ms.System.ArgumentException-destinationdoes not support writing.com.aspose.ms.System.InvalidOperationException- The archive is not opened for extraction. - or - This entry is a directory.com.aspose.ms.System.IO.InvalidDataException- Wrong data within the entry.
-
extract
public final void extract(OutputStream destination, String password)
Extracts the entry to the stream provided.
Extract an entry of zip archive with password.
try (SevenZipArchive archive = new SevenZipArchive("archive.7z")) { archive.getEntries().get(0).extract(httpResponseStream); }- Parameters:
destination- destination stream. Must be writablepassword- optional password for decryption- Throws:
com.aspose.ms.System.ArgumentException-destinationdoes not support writing.com.aspose.ms.System.InvalidOperationException- The archive is not opened for extraction. - or - This entry is a directory.com.aspose.ms.System.IO.InvalidDataException- Wrong data within the entry.
-
open
public final InputStream open()
Opens the entry for extraction and provides a stream with entry content.
Usage:SevenZipArchive archive = new SevenZipArchive("archive.7z"); SevenZipArchiveEntry entry = archive.getEntries().get(0); try (FileOutputStream fileStream = new FileOutputStream("data.bin")) { try (InputStream decompressed = entry.open()) { byte[] buffer = new byte[8192]; int bytesRead; while (0 < (bytesRead = decompressed.read(buffer, 0, buffer.length))) { fileStream.write(buffer, 0, bytesRead); } } } catch (IOException ex) { }Read from the stream to get the original content of the file. See examples section.
- Returns:
- the stream that represents the contents of the entry
- Throws:
com.aspose.ms.System.InvalidOperationException- The archive is not opened for extraction. - or - This entry is a directory.com.aspose.ms.System.IO.InvalidDataException- Wrong data within the entry.
-
open
public final InputStream open(String password)
Opens the entry for extraction and provides a stream with entry content.
Usage:SevenZipArchive archive = new SevenZipArchive("archive.7z"); SevenZipArchiveEntry entry = archive.getEntries().get(0); try (FileOutputStream fileStream = new FileOutputStream("data.bin")) { try (InputStream decompressed = entry.open()) { byte[] buffer = new byte[8192]; int bytesRead; while (0 < (bytesRead = decompressed.read(buffer, 0, buffer.length))) { fileStream.write(buffer, 0, bytesRead); } } } catch (IOException ex) { }Read from the stream to get the original content of the file. See examples section.
- Parameters:
password- optional password for decryption- Returns:
- the stream that represents the contents of the entry
- Throws:
com.aspose.ms.System.InvalidOperationException- The archive is not opened for extraction. - or - This entry is a directory.com.aspose.ms.System.IO.InvalidDataException- Wrong data within the entry.
-
-