Java Code Examples for net.lingala.zip4j.progress.ProgressMonitor#getPercentDone()

The following examples show how to use net.lingala.zip4j.progress.ProgressMonitor#getPercentDone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddFilesToZipIT.java    From zip4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddFolderWithProgressMonitor() throws IOException, InterruptedException {
  ZipFile zipFile = new ZipFile(generatedZipFile, PASSWORD);
  ProgressMonitor progressMonitor = zipFile.getProgressMonitor();
  boolean percentBetweenZeroAndHundred = false;
  boolean fileNameSet = false;

  zipFile.setRunInThread(true);
  zipFile.addFolder(TestUtils.getTestFileFromResources(""),
      createZipParameters(EncryptionMethod.AES, AesKeyStrength.KEY_STRENGTH_256));

  while (!progressMonitor.getState().equals(ProgressMonitor.State.READY)) {
    int percentDone = progressMonitor.getPercentDone();
    String fileName = progressMonitor.getFileName();

    if (percentDone > 0 && percentDone < 100) {
      percentBetweenZeroAndHundred = true;
    }

    if (fileName != null) {
      fileNameSet = true;
    }

    Thread.sleep(10);
  }

  assertThat(progressMonitor.getResult()).isEqualTo(ProgressMonitor.Result.SUCCESS);
  assertThat(progressMonitor.getState().equals(ProgressMonitor.State.READY));
  assertThat(progressMonitor.getException()).isNull();
  assertThat(percentBetweenZeroAndHundred).isTrue();
  assertThat(fileNameSet).isTrue();
  ZipFileVerifier.verifyZipFileByExtractingAllFiles(generatedZipFile, PASSWORD, outputFolder, 13);
}
 
Example 2
Source File: AddFilesToZipIT.java    From zip4j with Apache License 2.0 4 votes vote down vote up
@Test
public void testAddFileWithProgressMonitor() throws IOException, InterruptedException {
  ZipFile zipFile = new ZipFile(generatedZipFile, PASSWORD);
  ProgressMonitor progressMonitor = zipFile.getProgressMonitor();
  boolean percentBetweenZeroAndHundred = false;
  boolean fileNameSet = false;
  boolean taskNameSet = false;

  zipFile.setRunInThread(true);
  zipFile.addFile(TestUtils.getTestFileFromResources("file_PDF_1MB.pdf"),
      createZipParameters(EncryptionMethod.AES, AesKeyStrength.KEY_STRENGTH_256));

  while (!progressMonitor.getState().equals(ProgressMonitor.State.READY)) {
    int percentDone = progressMonitor.getPercentDone();
    String fileName = progressMonitor.getFileName();

    if (percentDone > 0 && percentDone < 100) {
      percentBetweenZeroAndHundred = true;
    }

    if (fileName != null) {
      assertThat(fileName).contains("file_PDF_1MB.pdf");
      fileNameSet = true;
    }

    Thread.sleep(10);

    if (!progressMonitor.getCurrentTask().equals(ProgressMonitor.Task.NONE)) {
      assertThat(progressMonitor.getCurrentTask()).isEqualTo(ProgressMonitor.Task.ADD_ENTRY);
      taskNameSet = true;
    }
  }

  assertThat(progressMonitor.getResult()).isEqualTo(ProgressMonitor.Result.SUCCESS);
  assertThat(progressMonitor.getState().equals(ProgressMonitor.State.READY));
  assertThat(progressMonitor.getException()).isNull();
  assertThat(percentBetweenZeroAndHundred).isTrue();
  assertThat(fileNameSet).isTrue();
  assertThat(taskNameSet).isTrue();

  ZipFileVerifier.verifyZipFileByExtractingAllFiles(generatedZipFile, PASSWORD, outputFolder, 1);
}
 
Example 3
Source File: AddFilesToZipIT.java    From zip4j with Apache License 2.0 4 votes vote down vote up
@Test
public void testAddFilesWithProgressMonitor() throws IOException, InterruptedException {
  ZipFile zipFile = new ZipFile(generatedZipFile, PASSWORD);
  ProgressMonitor progressMonitor = zipFile.getProgressMonitor();
  boolean percentBetweenZeroAndHundred = false;
  boolean fileNameSet = false;
  boolean taskNameSet = false;

  List<File> filesToAdd = new ArrayList<>(FILES_TO_ADD);
  filesToAdd.add(TestUtils.getTestFileFromResources("file_PDF_1MB.pdf"));
  zipFile.setRunInThread(true);
  zipFile.addFiles(filesToAdd, createZipParameters(EncryptionMethod.AES, AesKeyStrength.KEY_STRENGTH_256));

  while (!progressMonitor.getState().equals(ProgressMonitor.State.READY)) {
    int percentDone = progressMonitor.getPercentDone();
    String fileName = progressMonitor.getFileName();

    if (percentDone > 0 && percentDone < 100) {
      percentBetweenZeroAndHundred = true;
    }

    if (fileName != null) {
      fileNameSet = true;
    }

    Thread.sleep(10);

    if (!progressMonitor.getCurrentTask().equals(ProgressMonitor.Task.NONE)) {
      assertThat(progressMonitor.getCurrentTask()).isEqualTo(ProgressMonitor.Task.ADD_ENTRY);
      taskNameSet = true;
    }
  }

  assertThat(progressMonitor.getResult()).isEqualTo(ProgressMonitor.Result.SUCCESS);
  assertThat(progressMonitor.getState().equals(ProgressMonitor.State.READY));
  assertThat(progressMonitor.getException()).isNull();
  assertThat(percentBetweenZeroAndHundred).isTrue();
  assertThat(fileNameSet).isTrue();
  assertThat(taskNameSet).isTrue();

  ZipFileVerifier.verifyZipFileByExtractingAllFiles(generatedZipFile, PASSWORD, outputFolder, 4);
}
 
Example 4
Source File: RenameFilesInZipIT.java    From zip4j with Apache License 2.0 4 votes vote down vote up
@Test
public void testRenameWithMapProgressMonitor() throws IOException, InterruptedException {
  TestUtils.copyFileToFolder(getTestFileFromResources("file_PDF_1MB.pdf"), temporaryFolder.getRoot(), 100);

  ZipFile zipFile = new ZipFile(generatedZipFile, PASSWORD);
  ZipParameters zipParameters = buildZipParameters(CompressionMethod.DEFLATE, true, EncryptionMethod.AES);
  zipParameters.setIncludeRootFolder(false);
  zipFile.addFolder(temporaryFolder.getRoot(), zipParameters);

  Map<String, String> fileNamesMap = new HashMap<>();
  fileNamesMap.put("1.pdf", "1_new.pdf");
  fileNamesMap.put("25.pdf", "25_new.pdf");

  zipFile.setRunInThread(true);
  ProgressMonitor progressMonitor = zipFile.getProgressMonitor();

  zipFile.renameFiles(fileNamesMap);

  boolean percentBetweenZeroAndHundred = false;
  boolean fileNameSet = true;
  while (!progressMonitor.getState().equals(ProgressMonitor.State.READY)) {
    int percentDone = progressMonitor.getPercentDone();
    String fileName = progressMonitor.getFileName();

    if (percentDone > 0 && percentDone < 100) {
      percentBetweenZeroAndHundred = true;
    }

    if (fileName != null) {
      fileNameSet = true;
    }

    Thread.sleep(10);
  }

  assertThat(progressMonitor.getResult()).isEqualTo(ProgressMonitor.Result.SUCCESS);
  assertThat(progressMonitor.getState().equals(ProgressMonitor.State.READY));
  assertThat(progressMonitor.getException()).isNull();
  assertThat(percentBetweenZeroAndHundred).isTrue();
  assertThat(fileNameSet).isTrue();

  ZipFileVerifier.verifyZipFileByExtractingAllFiles(generatedZipFile, PASSWORD, outputFolder, 100, false);
  verifyFileNamesChanged(zipFile, fileNamesMap, false);
}