ArchiveLoadOptions

Inheritance: java.lang.Object

public class ArchiveLoadOptions

Options with which archive is loaded from compressed file.

Constructors

ConstructorDescription
ArchiveLoadOptions()

Methods

MethodDescription
getDecryptionPassword()Gets the password to decrypt entries.
getEncoding()Gets the encoding for entries’ names.
getEntryExtractionProgressed()Gets the delegate invoked when some bytes have been extracted.
getEntryListed()Gets the delegate invoked when an entry listed within table of content.
setDecryptionPassword(String value)Sets the password to decrypt entries.
setEncoding(Charset value)Sets the encoding for entries’ names.
setEntryExtractionProgressed(Event<ProgressEventArgs> value)Sets the delegate invoked when some bytes have been extracted.
setEntryListed(Event<EntryEventArgs> value)Sets the delegate invoked when an entry listed within table of content.

ArchiveLoadOptions()

public ArchiveLoadOptions()

getDecryptionPassword()

public final String getDecryptionPassword()

Gets the password to decrypt entries.

You can provide decryption password once on archive extraction.


    try (FileInputStream fs = new FileInputStream("encrypted_archive.zip")) {
        try (FileOutputStream extracted = new FileOutputStream("extracted.bin")) {
            ArchiveLoadOptions options = new ArchiveLoadOptions();
            options.setDecryptionPassword("p@s$");
            try (Archive archive = new Archive(fs, options)) {
                try (InputStream decompressed = archive.getEntries().get(0).open()) {
                    byte[] b = new byte[8192];
                    int bytesRead;
                    while (0 < (bytesRead = decompressed.read(b, 0, b.length)))
                        extracted.write(b, 0, bytesRead);
                }
                archive.getEntries().get(0).extract("first.bin", "first_pass");
                archive.getEntries().get(1).extract("second.bin", "second_pass");
            }
        }
    } catch (IOException ex) {
    }
 

Returns: java.lang.String - the password to decrypt entries.

getEncoding()

public final Charset getEncoding()

Gets the encoding for entries’ names.

Entry name composed using specified encoding regardless of zip file properties.


    try (FileInputStream fs = new FileInputStream("archive.zip")) {
        ArchiveLoadOptions options = new ArchiveLoadOptions();
        options.setEncoding(Charset.forName("MS932"));
        try (Archive archive = new Archive(fs, options)) {
            String name = archive.getEntries().get(0).getName();
        }
    } catch (IOException ex) {
    }
 

Returns: java.nio.charset.Charset - the encoding for entries’ names.

getEntryExtractionProgressed()

public final Event<ProgressEventArgs> getEntryExtractionProgressed()

Gets the delegate invoked when some bytes have been extracted.


    ArchiveLoadOptions options = new ArchiveLoadOptions();
    options.setEntryExtractionProgressed(new Event<ProgressEventArgs>() {
        public void invoke(Object sender, ProgressEventArgs progressEventArgs) {
            int percent = (int) ((100 * progressEventArgs.getProceededBytes()) / ((ArchiveEntry) sender).getUncompressedSize());
        }
    });
    Archive archive = new Archive("archive.zip", options);
 

Event sender is the ArchiveEntry instance which extraction is progressed.

Returns: Event - the delegate invoked when some bytes have been extracted.

getEntryListed()

public final Event<EntryEventArgs> getEntryListed()

Gets the delegate invoked when an entry listed within table of content.


    ArchiveLoadOptions options = new ArchiveLoadOptions();
    options.setEntryListed(new Event<EntryEventArgs>() {
        public void invoke(Object sender, EntryEventArgs entryEventArgs) {
            System.out.println(entryEventArgs.getEntry().getName());
        }
    });
    Archive archive = new Archive("archive.zip", options);
 

Returns: Event - the delegate invoked when an entry listed within table of content.

setDecryptionPassword(String value)

public final void setDecryptionPassword(String value)

Sets the password to decrypt entries.

You can provide decryption password once on archive extraction.


    try (FileInputStream fs = new FileInputStream("encrypted_archive.zip")) {
        try (FileOutputStream extracted = new FileOutputStream("extracted.bin")) {
            ArchiveLoadOptions options = new ArchiveLoadOptions();
            options.setDecryptionPassword("p@s$");
            try (Archive archive = new Archive(fs, options)) {
                try (InputStream decompressed = archive.getEntries().get(0).open()) {
                    byte[] b = new byte[8192];
                    int bytesRead;
                    while (0 < (bytesRead = decompressed.read(b, 0, b.length)))
                        extracted.write(b, 0, bytesRead);
                }
                archive.getEntries().get(0).extract("first.bin", "first_pass");
                archive.getEntries().get(1).extract("second.bin", "second_pass");
            }
        }
    } catch (IOException ex) {
    }
 

Parameters:

ParameterTypeDescription
valuejava.lang.Stringthe password to decrypt entries.

setEncoding(Charset value)

public final void setEncoding(Charset value)

Sets the encoding for entries’ names.

Entry name composed using specified encoding regardless of zip file properties.


    try (FileInputStream fs = new FileInputStream("archive.zip")) {
        ArchiveLoadOptions options = new ArchiveLoadOptions();
        options.setEncoding(Charset.forName("MS932"));
        try (Archive archive = new Archive(fs, options)) {
            String name = archive.getEntries().get(0).getName();
        }
    } catch (IOException ex) {
    }
 

Parameters:

ParameterTypeDescription
valuejava.nio.charset.Charsetthe encoding for entries’ names.

setEntryExtractionProgressed(Event<ProgressEventArgs> value)

public final void setEntryExtractionProgressed(Event<ProgressEventArgs> value)

Sets the delegate invoked when some bytes have been extracted.


    ArchiveLoadOptions options = new ArchiveLoadOptions();
    options.setEntryExtractionProgressed(new Event<ProgressEventArgs>() {
        public void invoke(Object sender, ProgressEventArgs progressEventArgs) {
            int percent = (int) ((100 * progressEventArgs.getProceededBytes()) / ((ArchiveEntry) sender).getUncompressedSize());
        }
    });
    Archive archive = new Archive("archive.zip", options);
 

Event sender is the ArchiveEntry instance which extraction is progressed.

Parameters:

ParameterTypeDescription
valuecom.aspose.zip.Event<com.aspose.zip.ProgressEventArgs>the delegate invoked when some bytes have been extracted.

setEntryListed(Event<EntryEventArgs> value)

public final void setEntryListed(Event<EntryEventArgs> value)

Sets the delegate invoked when an entry listed within table of content.


    ArchiveLoadOptions options = new ArchiveLoadOptions();
    options.setEntryListed(new Event<EntryEventArgs>() {
        public void invoke(Object sender, EntryEventArgs entryEventArgs) {
            System.out.println(entryEventArgs.getEntry().getName());
        }
    });
    Archive archive = new Archive("archive.zip", options);
 

Parameters:

ParameterTypeDescription
valuecom.aspose.zip.Event<com.aspose.zip.EntryEventArgs>the delegate invoked when an entry listed within table of content.