gpt4 book ai didi

java - 监控 Zip4J extractAll() 方法进度监视器

转载 作者:行者123 更新时间:2023-12-02 01:18:32 25 4
gpt4 key购买 nike

enter image description here我正在使用 Zip4J 来提取 zip 文件,并且我能够做到这一点。但是,我想使用 Zip4J 中提供的进度监视器,但无法成功使用它。文档只说它应该在线程模式下运行 true。我做到了,我的控制台在命令行上停留在这个位置。带进度监视器的 extractAll() 的任何工作示例。

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;
}

最佳答案

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

@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);
}

关于java - 监控 Zip4J extractAll() 方法进度监视器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58161993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com