Skip to content

Commit

Permalink
#313 Check for busy state at Abstract zip task level
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-lingala committed May 24, 2021
1 parent c818bfd commit a84daeb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
12 changes: 0 additions & 12 deletions src/main/java/net/lingala/zip4j/ZipFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,6 @@ public void addFiles(List<File> filesToAdd, ZipParameters parameters) throws Zip
throw new ZipException("input parameters are null");
}

if (progressMonitor.getState() == ProgressMonitor.State.BUSY) {
throw new ZipException("invalid operation - Zip4j is in busy state");
}

readZipInfo();

if (zipModel == null) {
Expand Down Expand Up @@ -467,10 +463,6 @@ public void extractAll(String destinationPath, UnzipParameters unzipParameters)
throw new ZipException("Internal error occurred when extracting zip file");
}

if (progressMonitor.getState() == ProgressMonitor.State.BUSY) {
throw new ZipException("invalid operation - Zip4j is in busy state");
}

new ExtractAllFilesTask(zipModel, password, unzipParameters, buildAsyncParameters()).execute(
new ExtractAllFilesTaskParameters(destinationPath, buildConfig()));
}
Expand Down Expand Up @@ -676,10 +668,6 @@ public void extractFile(FileHeader fileHeader, String destinationPath, String ne
throw new ZipException("destination path is empty or null, cannot extract file");
}

if (progressMonitor.getState() == ProgressMonitor.State.BUSY) {
throw new ZipException("invalid operation - Zip4j is in busy state");
}

if (unzipParameters == null) {
unzipParameters = new UnzipParameters();
}
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/net/lingala/zip4j/tasks/AsyncZipTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ public AsyncZipTask(AsyncTaskParameters asyncTaskParameters) {
}

public void execute(T taskParameters) throws ZipException {
progressMonitor.fullReset();
progressMonitor.setState(ProgressMonitor.State.BUSY);
progressMonitor.setCurrentTask(getTask());
if (runInThread && ProgressMonitor.State.BUSY.equals(progressMonitor.getState())) {
throw new ZipException("invalid operation - Zip4j is in busy state");
}

initProgressMonitor();

if (runInThread) {
long totalWorkToBeDone = calculateTotalWork(taskParameters);
Expand Down Expand Up @@ -64,6 +66,12 @@ protected void verifyIfTaskIsCancelled() throws ZipException {
throw new ZipException("Task cancelled", ZipException.Type.TASK_CANCELLED_EXCEPTION);
}

private void initProgressMonitor() {
progressMonitor.fullReset();
progressMonitor.setState(ProgressMonitor.State.BUSY);
progressMonitor.setCurrentTask(getTask());
}

protected abstract void executeTask(T taskParameters, ProgressMonitor progressMonitor) throws IOException;

protected abstract long calculateTotalWork(T taskParameters) throws ZipException;
Expand Down

0 comments on commit a84daeb

Please sign in to comment.