Class ArchiveLoadOptions
- java.lang.Object
-
- com.aspose.zip.ArchiveLoadOptions
-
public class ArchiveLoadOptions extends Object
Options with which archive is loaded from a compressed file.
-
-
Constructor Summary
Constructors Constructor Description ArchiveLoadOptions()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetDecryptionPassword()Gets the password to decrypt entries.CharsetgetEncoding()Gets the encoding for entries' names.Event<ProgressCancelEventArgs>getEntryExtractionProgressed()Gets an event that is raised when some bytes have been extracted.Event<EntryEventArgs>getEntryListed()Gets an event that is raised when an entry listed within table of content.booleangetSkipChecksumVerification()Gets a value indicating whether checksum verification of ZIP entries be skipped and mismatch ignored.voidsetCancellationFlag(CancellationFlag value)Sets a cancellation flag used to cancel the extraction operation.voidsetDecryptionPassword(String value)Sets the password to decrypt entries.voidsetEncoding(Charset value)Sets the encoding for entries' names.voidsetEntryExtractionProgressed(Event<ProgressCancelEventArgs> value)Sets an event that is raised when some bytes have been extracted.voidsetEntryListed(Event<EntryEventArgs> value)Sets an event that is raised when an entry listed within table of content.voidsetSkipChecksumVerification(boolean value)Sets a value indicating whether checksum verification of ZIP entries be skipped and mismatch ignored.
-
-
-
Method Detail
-
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:
- the password to decrypt entries
- See Also:
ArchiveEntry.open(String)
-
setDecryptionPassword
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:
value- the password to decrypt entries- See Also:
ArchiveEntry.open(String)
-
getEntryListed
public final Event<EntryEventArgs> getEntryListed()
Gets an event that is raised 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:
- an event that is raised when an entry listed within table of content
-
setEntryListed
public final void setEntryListed(Event<EntryEventArgs> value)
Sets an event that is raised 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:
value- an event that is raised when an entry listed within table of content
-
getEntryExtractionProgressed
public final Event<ProgressCancelEventArgs> getEntryExtractionProgressed()
Gets an event that is raised when some bytes have been extracted.
Track the progress of an entry extraction.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);Cancel an entry extraction after a certain time.
long startTime = System.nanoTime(); ArchiveLoadOptions options = new ArchiveLoadOptions(); options.setEntryExtractionProgressed((s, e) -> { if ((System.nanoTime() - startTime) / 1_000_000 > 1000) e.setCancel(true); }); try (Archive a = new Archive("big.zip", options)) { a.getEntries().get(0).extract("first.bin"); }Event sender is the
ArchiveEntryinstance which extraction is progressed.- Returns:
- an event that is raised when some bytes have been extracted
-
setEntryExtractionProgressed
public final void setEntryExtractionProgressed(Event<ProgressCancelEventArgs> value)
Sets an event that is raised when some bytes have been extracted.
Track the progress of an entry extraction.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);Cancel an entry extraction after a certain time.
long startTime = System.nanoTime(); ArchiveLoadOptions options = new ArchiveLoadOptions(); options.setEntryExtractionProgressed((s, e) -> { if ((System.nanoTime() - startTime) / 1_000_000 > 1000) e.setCancel(true); }); try (Archive a = new Archive("big.zip", options)) { a.getEntries().get(0).extract("first.bin"); }Event sender is the
ArchiveEntryinstance which extraction is progressed.- Parameters:
value- an event that is raised when some bytes have been extracted
-
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:
- the encoding for entries' names
-
setEncoding
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:
value- the encoding for entries' names
-
getSkipChecksumVerification
public final boolean getSkipChecksumVerification()
Gets a value indicating whether checksum verification of ZIP entries be skipped and mismatch ignored. Default is false.
- Returns:
- a value indicating whether checksum verification of ZIP entries be skipped and mismatch ignored
-
setSkipChecksumVerification
public final void setSkipChecksumVerification(boolean value)
Sets a value indicating whether checksum verification of ZIP entries be skipped and mismatch ignored. Default is false.
- Parameters:
value- a value indicating whether checksum verification of ZIP entries be skipped and mismatch ignored
-
setCancellationFlag
public void setCancellationFlag(CancellationFlag value)
Sets a cancellation flag used to cancel the extraction operation.
Cancel ZIP archive extraction after a certain time.
Cancellation mostly results in some data not being extracted.try (CancellationFlag cf = new CancellationFlag()) { cf.cancelAfter(TimeUnit.SECONDS.toMillis(60)); ArchiveLoadOptions options = new ArchiveLoadOptions(); options.setCancellationFlag(cf); try (Archive a = new Archive("big.zip", options)) { try { a.getEntries().get(0).extract("data.bin"); } catch (OperationCanceledException e) { System.out.println("Extraction was cancelled after 60 seconds"); } } }- Parameters:
value- a cancellation flag used to cancel the extraction operation.
-
-