Class ArchiveEntry
- java.lang.Object
-
- com.aspose.zip.ArchiveEntry
-
- All Implemented Interfaces:
IArchiveFileEntry
- Direct Known Subclasses:
ArchiveEntryEncrypted,ArchiveEntryPlain
public abstract class ArchiveEntry extends Object implements IArchiveFileEntry
Represents single file within archive.
Cast an
ArchiveEntryinstance toArchiveEntryEncryptedto 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.StringgetComment()Gets comment of the entry within archive.longgetCompressedSize()Gets size of the compressed file.Event<ProgressEventArgs>getCompressionProgressed()Gets an event that is raised when a portion of raw stream compressed.CompressionSettingsgetCompressionSettings()Gets settings for compression or decompression.InputStreamgetDataSource()Source for the entry if the entry was added to the archive, not extracted.Event<ProgressCancelEventArgs>getExtractionProgressed()Gets an event that is raised when a portion of raw stream extracted.LonggetLength()Gets length.DategetModificationTime()Gets last modified date and time.StringgetName()Gets name of the entry within the archive.longgetUncompressedSize()Gets 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 decompressed entry content.InputStreamopen(String password)Opens the entry for extraction and provides a stream with decompressed entry content.voidsetCompressionProgressed(Event<ProgressEventArgs> value)Sets an event that is raised when a portion of raw stream compressed.voidsetExtractionProgressed(Event<ProgressCancelEventArgs> value)Sets an event that is raised when a portion of raw stream extracted.voidsetModificationTime(Date value)Sets last modified date and time.
-
-
-
Method Detail
-
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
ArchiveEntryinstance.- 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
ArchiveEntryinstance.- Parameters:
value- an event that is raised when a portion of raw stream compressed
-
getExtractionProgressed
public final Event<ProgressCancelEventArgs> getExtractionProgressed()
Gets an event that is raised when a portion of raw stream extracted.
In this sample event handler is used for calculation the share of proceeded size in percents.
In this sample event handler is used for cancellation after the first hundred of Mb of entry was extracted.archive.getEntries().get(0).setExtractionProgressed(new Event<ProgressEventArgs>() { public void invoke(Object sender, ProgressEventArgs progressEventArgs) { int percent = (int) ((100 * (long) progressEventArgs.getProceededBytes()) / ((ArchiveEntry) sender).getUncompressedSize()); } });a.getEntries().get(0).setExtractionProgressed( (s, e) -> { if (e.getProceededBytes() > 100000000) e.setCancel(true); } );Event sender is an
ArchiveEntryinstance. It is possible to cancel extraction.- Returns:
- an event that is raised when a portion of raw stream extracted.
-
setExtractionProgressed
public final void setExtractionProgressed(Event<ProgressCancelEventArgs> value)
Sets an event that is raised when a portion of raw stream extracted.
In this sample event handler is used for calculation the share of proceeded size in percents.
In this sample event handler is used for cancellation after the first hundred of Mb of entry was extracted.archive.getEntries().get(0).setExtractionProgressed(new Event<ProgressEventArgs>() { public void invoke(Object sender, ProgressEventArgs progressEventArgs) { int percent = (int) ((100 * (long) progressEventArgs.getProceededBytes()) / ((ArchiveEntry) sender).getUncompressedSize()); } });a.getEntries().get(0).setExtractionProgressed( (s, e) -> { if (e.getProceededBytes() > 100000000) e.setCancel(true); } );Event sender is an
ArchiveEntryinstance. It is possible to cancel extraction.- Parameters:
value- an event that is raised when a portion of raw stream extracted.
-
getCompressedSize
public final long getCompressedSize()
Gets size of the compressed file.
- Returns:
- size of the compressed file
-
getName
public final String getName()
Gets name of the entry within the archive.
- Specified by:
getNamein interfaceIArchiveFileEntry- Returns:
- name of the entry within the archive
-
getComment
public final String getComment()
Gets comment of the entry within archive.
- Returns:
- comment of the entry within archive
-
getUncompressedSize
public final long getUncompressedSize()
Gets size of the original file.
- Returns:
- size of the original file
-
getModificationTime
public final Date getModificationTime()
Gets last modified date and time.
- Returns:
- last modified date and time
-
setModificationTime
public final void setModificationTime(Date value)
Sets last modified date and time.
- Parameters:
value- last modified date and time
-
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.
-
getDataSource
public final InputStream getDataSource()
Source for the entry if the entry was added to the archive, not extracted.
Before assigned, the source is null. This source may be assigned within
Archive.savemethod in some cases.- Returns:
- the source for the entry
-
getCompressionSettings
public final CompressionSettings getCompressionSettings()
Gets settings for compression or decompression.
- Returns:
- settings for compression or decompression.
-
getLength
public final Long getLength()
Gets length.- Specified by:
getLengthin interfaceIArchiveFileEntry- Returns:
- length
-
open
public final InputStream open()
Opens the entry for extraction and provides a stream with decompressed entry content.
Usage: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);Read from the stream to get the original content of the file.
- Returns:
- The stream that represents the contents of the entry.
- Throws:
com.aspose.ms.System.InvalidOperationException- The archive is in an incorrect state.
-
open
public final InputStream open(String password)
Opens the entry for extraction and provides a stream with decompressed entry content.
Usage: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);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 in an incorrect state.
-
extract
public final File extract(String path)
Extracts the entry to the filesystem by the path provided.
Extract two entries of ZIP archive, each with own password
try (FileInputStream zipFile = new FileInputStream("archive.zip")) { try (Archive archive = new Archive(zipFile)) { archive.getEntries().get(0).extract("first.bin", "first_pass"); archive.getEntries().get(1).extract("second.bin", "second_pass"); } } catch (IOException ex) { }- 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- CRC or MAC verification failed for the entry.
-
extract
public final File extract(String path, String password)
Extracts the entry to the filesystem by the path provided.
Extract two entries of ZIP archive, each with own password
try (FileInputStream zipFile = new FileInputStream("archive.zip")) { try (Archive archive = new Archive(zipFile)) { archive.getEntries().get(0).extract("first.bin", "first_pass"); archive.getEntries().get(1).extract("second.bin", "second_pass"); } } catch (IOException ex) { }- Parameters:
path- The path to destination file. If the file already exists, it will be overwritten.password- 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- CRC or MAC verification failed for the entry.
-
extract
public final void extract(OutputStream destination)
Extracts the entry to the stream provided.
Extract an entry of zip archive with password.
try (FileInputStream zipFile = new FileInputStream("archive.zip")) { try (Archive archive = new Archive(zipFile)) { archive.getEntries().get(0).extract(outputStream, "p@s$"); } } catch (IOException ex) { }- Specified by:
extractin interfaceIArchiveFileEntry- Parameters:
destination- Destination stream. Must be writable.- Throws:
com.aspose.ms.System.IO.InvalidDataException- CRC or MAC verification failed for the entry.com.aspose.ms.System.ArgumentException-destinationdoes not support writing.
-
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 (FileInputStream zipFile = new FileInputStream("archive.zip")) { try (Archive archive = new Archive(zipFile)) { archive.getEntries().get(0).extract(outputStream, "p@s$"); } } catch (IOException ex) { }- Parameters:
destination- Destination stream. Must be writable.password- Optional password for decryption.- Throws:
com.aspose.ms.System.IO.InvalidDataException- CRC or MAC verification failed for the entry.com.aspose.ms.System.ArgumentException-destinationdoes not support writing.
-
-