Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 监视Zip4J extractAll()方法进度监视器_Java_Progress Bar_Monitoring_Zip4j - Fatal编程技术网

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

Java 监视Zip4J extractAll()方法进度监视器,java,progress-bar,monitoring,zip4j,Java,Progress Bar,Monitoring,Zip4j,我正在使用Zip4J提取zip文件,我能够做到这一点。但是,我想使用Zip4J中提供的进度监视器,但无法成功使用它。 文档只说它应该在线程模式下运行。我这样做了,我的控制台卡在命令行上。带有进度监视器的extractAll()的任何工作示例 public String unzipFile(String sourceFilePath, String extractionPath) { String extractionDirectory = ""; FileHead

我正在使用Zip4J提取zip文件,我能够做到这一点。但是,我想使用Zip4J中提供的进度监视器,但无法成功使用它。 文档只说它应该在线程模式下运行。我这样做了,我的控制台卡在命令行上。带有进度监视器的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;
    }
publicstringunzipfile(stringsourcefilepath,stringextractionpath){
String extractionDirectory=“”;
FileHeader FileHeader=null;
if(FileUtility.isPathExist(sourceFilePath)和&FileUtility.isPathExist(extractionPath)){
试一试{
ZipFile ZipFile=新ZipFile(sourceFilePath);
LOG.info(“文件提取已启动”);
List fileHeaderList=zipFile.getFileHeaders();
如果(fileHeaderList.size()>0)
fileHeader=(fileHeader)fileHeaderList.get(0);
if(fileHeader!=null)
extractionDirectory=splitFileName(fileHeader.getFileName());
长期总百分比=235;
long startTime=System.currentTimeMillis();
zipFile.extractAll(extractionPath);
LOG.info(“文件提取完成”);
System.out.println();
}捕获(ZipException e){
LOG.error(“提取异常->\n”+e.getMessage());
}
}否则{
LOG.error(“源路径或提取路径不存在”);
}
返回extractionDirectory;
}

在项目的测试用例中显示了如何使用ProgressMonitor

项目的测试用例展示了如何使用ProgressMonitor

不知道,如果您添加了足够的文件,并且实际上有一个进度可供查看,那么它就可以正常工作。为此我加了一些很胖的

@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);
}
@测试
public void TestExtractAllDeflateAndNoEncyptionExtractSuccessfully()引发IOException{
ZipFile ZipFile=新ZipFile(生成的ZipFile);
List toAdd=Arrays.asList(
getTestFileFromResources(“sample_text1.txt”),
getTestFileFromResources(“sample\u text\u large.txt”),
getTestFileFromResources(“orctural.pdf”),
getTestFileFromResources(“automata theory.pdf简介”),
getTestFileFromResources(“thomas.pdf”)
);
添加文件(toAdd);
setRunInThread(true);
提取所有(outputFolder.getPath());
ProgressMonitor mon=zipFile.getProgressMonitor();
while(mon.getState()==忙){
System.out.println(zipFile.getProgressMonitor().getPercentDone());
试一试{
睡眠(10);
}捕捉(中断异常e){
抛出新的运行时异常(e);
}
}
ZipFileVerifier.verifyFolderContentsSameAsSourceFiles(outputFolder);
验证NumberOfFilesInOutputFolder(outputFolder,5);
}

不知道,如果您添加了足够多的文件,并且实际上有一个进度可以查看,那么它就可以正常工作。为此我加了一些很胖的

@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);
}
@测试
public void TestExtractAllDeflateAndNoEncyptionExtractSuccessfully()引发IOException{
ZipFile ZipFile=新ZipFile(生成的ZipFile);
List toAdd=Arrays.asList(
getTestFileFromResources(“sample_text1.txt”),
getTestFileFromResources(“sample\u text\u large.txt”),
getTestFileFromResources(“orctural.pdf”),
getTestFileFromResources(“automata theory.pdf简介”),
getTestFileFromResources(“thomas.pdf”)
);
添加文件(toAdd);
setRunInThread(true);
提取所有(outputFolder.getPath());
ProgressMonitor mon=zipFile.getProgressMonitor();
while(mon.getState()==忙){
System.out.println(zipFile.getProgressMonitor().getPercentDone());
试一试{
睡眠(10);
}捕捉(中断异常e){
抛出新的运行时异常(e);
}
}
ZipFileVerifier.verifyFolderContentsSameAsSourceFiles(outputFolder);
验证NumberOfFilesInOutputFolder(outputFolder,5);
}

我无法获得任何用于extractAll()的示例以及显示提取进度的示例。你能提供任何这样的例子或代码片段吗。我试着跟随,但到目前为止还不能。我无法得到任何用于extractAll()和显示提取进度的示例。你能提供任何这样的例子或代码片段吗。我试着跟随,但现在无法。谢谢你的回复。是的,这对我有用。但是,在任务完成后,默认情况下,这不会从线程中产生。当我在eclipse中运行控制台时,控制台显示,程序仍在运行。如何在线程中完成任务后中止?我建议您调试这个东西。我也得这么做,看我加了一张照片。当我通过制作一个可运行的jar来运行java-jar时,控制台上出现了堆异常。那么,这是否意味着线程正在内部运行并使系统保持繁忙状态?工作完成后如何停止线程,如图所示。对不起,我不知道。可能是由代码引起的或隐藏在组件中的任何内容。另外,我的素描不是为了节省生产。谢谢你的回复。是的,这对我有用。但是,在任务完成后,默认情况下,这不会从线程中产生。当我在eclipse中运行控制台时,控制台显示,程序仍在运行。如何在线程中完成任务后中止?我建议您调试这个东西。我也得这么做,看我加了一张照片。当我通过制作一个可运行的jar来运行java-jar时,控制台上出现了堆异常。那么,这是否意味着线程正在内部运行并使系统保持繁忙状态?工作完成后如何停止线程,如图所示。对不起,我不知道。可能是由代码引起的或隐藏在组件中的任何内容。肌萎缩侧索硬化