ArchiveEntry

Inheritance: java.lang.Object

All Implemented Interfaces: com.aspose.zip.IArchiveFileEntry

public abstract class ArchiveEntry implements IArchiveFileEntry

Represents single file within archive.

Cast an ArchiveEntry instance to ArchiveEntryEncrypted to determine whether the entry encrypted or not.

Methods

MethodDescription
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.
getComment()Gets comment of the entry within archive.
getCompressedSize()Gets size of compressed file.
getCompressionProgressed()Gets an event that is raised when a portion of raw stream compressed.
getCompressionSettings()Gets settings for compression or decompression.
getExtractionProgressed()Gets an event that is raised when a portion of raw stream extracted.
getLength()Gets length.
getModificationTime()Gets last modified date and time.
getName()Gets name of the entry within archive.
getUncompressedSize()Gets size of original file.
isDirectory()Gets a value indicating whether the entry represents directory.
open()Opens the entry for extraction and provides a stream with decompressed entry content.
open(String password)Opens the entry for extraction and provides a stream with decompressed entry content.
setCompressionProgressed(Event<ProgressEventArgs> value)Sets an event that is raised when a portion of raw stream compressed.
setExtractionProgressed(Event<ProgressEventArgs> value)Sets an event that is raised when a portion of raw stream extracted.
setModificationTime(Date value)Sets last modified date and time.

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 (FileInputStream zipFile = new FileInputStream("archive.zip")) {
        try (Archive archive = new Archive(zipFile)) {
            archive.getEntries().get(0).extract(outputStream, "p@s$");
        }
    } catch (IOException ex) {
    }
 

Parameters:

ParameterTypeDescription
destinationjava.io.OutputStreamDestination stream. Must be writable.

extract(OutputStream destination, String password)

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:

ParameterTypeDescription
destinationjava.io.OutputStreamDestination stream. Must be writable.
passwordjava.lang.StringOptional password for decryption.

extract(String path)

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) {
    }
 

Parameters:

ParameterTypeDescription
pathjava.lang.StringThe path to destination file. If the file already exists, it will be overwritten.

Returns: java.io.File - The file info of composed file.

extract(String path, String password)

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:

ParameterTypeDescription
pathjava.lang.StringThe path to destination file. If the file already exists, it will be overwritten.
passwordjava.lang.StringOptional password for decryption.

Returns: java.io.File - The file info of composed file.

getComment()

public final String getComment()

Gets comment of the entry within archive.

Returns: java.lang.String - comment of the entry within archive.

getCompressedSize()

public final long getCompressedSize()

Gets size of compressed file.

Returns: long - size of compressed file.

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 ArchiveEntry instance.

Returns: Event - an event that is raised when a portion of raw stream compressed.

getCompressionSettings()

public final CompressionSettings getCompressionSettings()

Gets settings for compression or decompression.

Returns: CompressionSettings - settings for compression or decompression.

getExtractionProgressed()

public final Event<ProgressEventArgs> getExtractionProgressed()

Gets an event that is raised when a portion of raw stream 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());
        }
    });
 

Event sender is an ArchiveEntry instance.

Returns: Event - an event that is raised when a portion of raw stream extracted.

getLength()

public final Long getLength()

Gets length.

Returns: java.lang.Long - length.

getModificationTime()

public final Date getModificationTime()

Gets last modified date and time.

Returns: java.util.Date - last modified date and time.

getName()

public final String getName()

Gets name of the entry within archive.

Returns: java.lang.String - name of the entry within archive.

getUncompressedSize()

public final long getUncompressedSize()

Gets size of original file.

Returns: long - size of original file.

isDirectory()

public final boolean isDirectory()

Gets a value indicating whether the entry represents directory.

Returns: boolean - a value indicating whether the entry represents directory.

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 original content of file.

Returns: java.io.InputStream - The stream that represents the contents of the entry.

open(String password)

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 original content of file. See examples section.

Parameters:

ParameterTypeDescription
passwordjava.lang.StringOptional password for decryption.

Returns: java.io.InputStream - The stream that represents the contents of the entry.

setCompressionProgressed(Event<ProgressEventArgs> value)

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 ArchiveEntry instance.

Parameters:

ParameterTypeDescription
valuecom.aspose.zip.Event<com.aspose.zip.ProgressEventArgs>an event that is raised when a portion of raw stream compressed.

setExtractionProgressed(Event<ProgressEventArgs> value)

public final void setExtractionProgressed(Event<ProgressEventArgs> value)

Sets an event that is raised when a portion of raw stream 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());
        }
    });
 

Event sender is an ArchiveEntry instance.

Parameters:

ParameterTypeDescription
valuecom.aspose.zip.Event<com.aspose.zip.ProgressEventArgs>an event that is raised when a portion of raw stream extracted.

setModificationTime(Date value)

public final void setModificationTime(Date value)

Sets last modified date and time.

Parameters:

ParameterTypeDescription
valuejava.util.Datelast modified date and time.