0

I use zip4j to unzip zip packages which are safed by a password (AES-256). My problem is not, that the code is not working, rather that it doen't throw any error when the password doesn't match with the actual on the .zip.

the .zip has a password with 123 and for zip4j I set the password 123456789. So he is not able to extract all. I expect an Error or any message, that it could not extract. The actual case is, he doesn't extract it but no exception or error message, nothing.

Any Idea how I can check if the extraction was successful?

 protected void unpackZip(String destinationPath, String archivePath) throws InterruptedException {
    int onChange = 0;

    try {
        ZipFile zipFile = new ZipFile( archivePath );

        zipFile.setRunInThread( true );

        if (zipFile.isEncrypted()) {
            zipFile.setPassword( "123456789");
        }

        zipFile.extractAll( destinationPath );

        // http://www.lingala.net/zip4j/forum/index.php?topic=68.0
        ProgressMonitor progressMonitor = zipFile.getProgressMonitor();

        while (progressMonitor.getState() == ProgressMonitor.STATE_BUSY) {
            // To get the percentage done
            if (onChange != progressMonitor.getPercentDone()) {
                onChange = progressMonitor.getPercentDone();
                sendWebStatusUiMessage( "Extracted : " + onChange + "% ", "update" );
            }
            try {
                Thread.sleep( 1000 );
            } catch (Exception e) {

            }


        }
    } catch (ZipException e) {
        e.printStackTrace();
    }

}
NobodyIsPerfect
  • 182
  • 1
  • 12

1 Answers1

0

This answer is a bit late, but just in case it might be useful for anyone:

When running zip4j in thread mode, you have to check for the status of the task execution and exception (if errored), after the while loop.

while (progressMonitor.getState() == ProgressMonitor.STATE_BUSY) {
    // To get the percentage done
    if (onChange != progressMonitor.getPercentDone()) {
        onChange = progressMonitor.getPercentDone();
        sendWebStatusUiMessage( "Extracted : " + onChange + "% ", "update" );
    }
    try {
        Thread.sleep( 1000 );
    } catch (Exception e) {

    }
}

if (progressMonitor.getResult().equals(ProgressMonitor.Result.SUCCESS)) {
  System.out.println("Successfully added folder to zip");
} else if (progressMonitor.getResult().equals(ProgressMonitor.Result.ERROR)) {
  System.out.println("Error occurred. Error message: " + progressMonitor.getException().getMessage());
} else if (progressMonitor.getResult().equals(ProgressMonitor.Result.CANCELLED)) {
  System.out.println("Task cancelled");
}