SevenZipArchiveEntry
Inheritance: java.lang.Object
All Implemented Interfaces: com.aspose.zip.IArchiveFileEntry
public abstract class SevenZipArchiveEntry implements IArchiveFileEntry
Represents a single file within 7z archive.
Cast an SevenZipArchiveEntry instance to SevenZipArchiveEntryEncrypted to determine whether the entry encrypted or not.
Methods
| Method | Description |
|---|---|
| extract(OutputStream destination) | Extracts the entry to the stream provided. |
| extract(OutputStream destination, String password) | Extracts the entry to the stream provided. |
| extract(String path) | Extracts the entry to the filesystem by the path provided. |
| extract(String path, String password) | Extracts the entry to the filesystem by the path provided. |
| getCompressedSize() | Gets the size of the compressed file. |
| getCompressionProgressed() | Gets an event that is raised when a portion of raw stream compressed. |
| getCompressionSettings() | Gets settings for compression or decompression. |
| getLength() | Gets length. |
| getModificationTime() | Gets last modified date and time. |
| getName() | Gets the name of the entry within the archive. |
| getUncompressedSize() | Gets the size of the original file. |
| isDirectory() | Gets a value indicating whether the entry represents a directory. |
| open() | Opens the entry for extraction and provides a stream with entry content. |
| open(String password) | Opens the entry for extraction and provides a stream with entry content. |
| setCompressionProgressed(Event<ProgressEventArgs> value) | Sets an event that is raised when a portion of raw stream compressed. |
extract(OutputStream destination)
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);
}
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| destination | java.io.OutputStream | destination stream. Must be writable |
### extract(OutputStream destination, String password) {#extract-java.io.OutputStream-java.lang.String-}
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:**
| Parameter | Type | Description |
| --- | --- | --- |
| destination | java.io.OutputStream | destination stream. Must be writable |
| password | java.lang.String | optional password for decryption |
### extract(String path) {#extract-java.lang.String-}
```
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");
}
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| path | java.lang.String | the path to destination file. If the file already exists, it will be overwritten |
**Returns:**
java.io.File - the file info of the extracted file
### extract(String path, String password) {#extract-java.lang.String-java.lang.String-}
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:**
| Parameter | Type | Description |
| --- | --- | --- |
| path | java.lang.String | the path to destination file. If the file already exists, it will be overwritten |
| password | java.lang.String | optional password for decryption |
**Returns:**
java.io.File - the file info of the extracted file
### getCompressedSize() {#getCompressedSize--}
```
public final long getCompressedSize()
```
Gets the size of the compressed file.
**Returns:**
long - the size of the compressed file
### getCompressionProgressed() {#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 [SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) instance.
Does not invoke in solid mode and in multithreaded mode for LZMA2 entries.
**Returns:**
[Event](../../com.aspose.zip/event) - an event that is raised when a portion of raw stream compressed
### getCompressionSettings() {#getCompressionSettings--}
public final SevenZipCompressionSettings getCompressionSettings()
Gets settings for compression or decompression.
**Returns:**
[SevenZipCompressionSettings](../../com.aspose.zip/sevenzipcompressionsettings) - settings for compression or decompression
### getLength() {#getLength--}
public final Long getLength()
Gets length.
**Returns:**
java.lang.Long - length
### getModificationTime() {#getModificationTime--}
public final Date getModificationTime()
Gets last modified date and time.
**Returns:**
java.util.Date - last modified date and time
### getName() {#getName--}
public final String getName()
Gets the name of the entry within the archive.
**Returns:**
java.lang.String - the name of the entry within the archive
### getUncompressedSize() {#getUncompressedSize--}
public final long getUncompressedSize()
Gets the size of the original file.
**Returns:**
long - the size of the original file
### isDirectory() {#isDirectory--}
public final boolean isDirectory()
Gets a value indicating whether the entry represents a directory.
**Returns:**
boolean - a value indicating whether the entry represents a directory
### open() {#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:**
java.io.InputStream - the stream that represents the contents of the entry
### open(String password) {#open-java.lang.String-}
```
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:**
| Parameter | Type | Description |
| --- | --- | --- |
| password | java.lang.String | optional password for decryption |
**Returns:**
java.io.InputStream - the stream that represents the contents of the entry
### setCompressionProgressed(Event<ProgressEventArgs> value) {#setCompressionProgressed-com.aspose.zip.Event-com.aspose.zip.ProgressEventArgs--}
public final void setCompressionProgressed(Event
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 [SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) instance.
Does not invoke in solid mode and in multithreaded mode for LZMA2 entries.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| value | com.aspose.zip.Event<com.aspose.zip.ProgressEventArgs> | an event that is raised when a portion of raw stream compressed |