首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >监视Zip4J extractAll()方法进度监视器

监视Zip4J extractAll()方法进度监视器
EN

Stack Overflow用户
提问于 2019-09-30 13:35:38
回答 2查看 422关注 0票数 0

我正在使用Zip4J解压压缩文件,我能够做到这一点。但是,我想使用Zip4J中提供进度监视器,但不能成功使用它。文档只说它应该运行在线程模式true中。我这样做了,我的控制台在命令行上停留在这个位置。带有进度监视器的extractAll()的任何工作示例。

代码语言:javascript
复制
public String unzipFile(String sourceFilePath, String extractionPath) {
        String extractionDirectory = "";
        FileHeader fileHeader = null;
        if (FileUtility.isPathExist(sourceFilePath) && FileUtility.isPathExist(extractionPath)) {
            try {
                ZipFile zipFile = new ZipFile(sourceFilePath);
                LOG.info("File Extraction started");
                List<FileHeader> fileHeaderList = zipFile.getFileHeaders();
                if (fileHeaderList.size() > 0)
                    fileHeader = (FileHeader) fileHeaderList.get(0);
                if (fileHeader != null)
                    extractionDirectory = splitFileName(fileHeader.getFileName());
                long totalPercentage = 235;
                long startTime = System.currentTimeMillis();
                zipFile.extractAll(extractionPath);
                LOG.info("File Extraction completed.");
                System.out.println();
            } catch (ZipException e) {
                LOG.error("Extraction Exception ->\n" + e.getMessage());
            }
        } else {
            LOG.error("Either source path or extraction path is not exist.");
        }
        return extractionDirectory;
    }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-09-30 21:54:51

不知道,如果你添加了足够多的文件,就可以正常工作,实际上有一个进度要看。为此,我添加了一些非常胖的。

代码语言:javascript
复制
@Test
public void testExtractAllDeflateAndNoEncryptionExtractsSuccessfully() throws IOException {
    ZipFile zipFile = new ZipFile(generatedZipFile);

     List<File> toAdd = Arrays.asList(
            getTestFileFromResources("sample_text1.txt"),
            getTestFileFromResources("sample_text_large.txt"),
            getTestFileFromResources("OrccTutorial.pdf"),
             getTestFileFromResources("introduction-to-automata-theory.pdf"),
             getTestFileFromResources("thomas.pdf")
    );
    zipFile.addFiles(toAdd);

    zipFile.setRunInThread(true);

    zipFile.extractAll(outputFolder.getPath());

    ProgressMonitor mon = zipFile.getProgressMonitor();
    while (mon.getState() == BUSY) {
        System.out.println(zipFile.getProgressMonitor().getPercentDone());
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    ZipFileVerifier.verifyFolderContentsSameAsSourceFiles(outputFolder);
    verifyNumberOfFilesInOutputFolder(outputFolder, 5);
}
票数 1
EN

Stack Overflow用户

发布于 2019-09-30 14:25:54

项目测试用例中的testAddFilesWithProgressMonitor.java展示了如何使用ProgressMonitor。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58161993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档