简体   繁体   English

Java无法解压缩apache Web服务器目录中的文件-java.util.zip.ZipError:找不到zip END标头

[英]Java can't unzip files inside apache web server directory - java.util.zip.ZipError: zip END header not found

I am having weird issues with a java application unzipping files on an apache server. 我在将Java应用程序解压缩到apache服务器上的文件时遇到了奇怪的问题。 I have an apache server in which some other applications uploads zip files. 我有一个apache服务器,其中一些其他应用程序上载zip文件。 eg the directory is /var/www/html/fles 例如,目录是/ var / www / html / fles

When I now start my java program to unzip the files it always fails with the following exception below. 现在,当我启动Java程序来解压缩文件时,它总是失败,但以下异常除外。

I also checked the contentType using Files.probeContentType(file) and astonishingly it returns text/plain instead of application/zip I then tested the code in another directory, eg the home dir and there it works flawlessly. 我还使用Files.probeContentType(file)检查了contentType,并惊讶地返回了text/plain而不是application/zip ,然后我在另一个目录(例如主目录)中测试了代码,在那里它可以正常工作。

So it seems it has something do do with the apache config, but I already checked and disabled gzip compression for zip files: I have no clue what else I have to do 因此,似乎它与apache配置有关,但是我已经检查并禁用了zip文件的gzip压缩功能:我不知道我还需要做什么

My deflate.conf: 我的deflate.conf:

<IfModule mod_deflate.c>
        <IfModule mod_filter.c>
                # these are known to be safe with MSIE 6
                AddOutputFilterByType DEFLATE text/html text/plain text/xml

                # everything else may cause problems with MSIE 6
                AddOutputFilterByType DEFLATE text/css
                AddOutputFilterByType DEFLATE application/x-javascript application/javascript $
                AddOutputFilterByType DEFLATE application/rss+xml
                AddOutputFilterByType DEFLATE application/xml

                SetOutputFilter DEFLATE
                SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png|zip)$" no-gzip
        </IfModule>
</IfModule>

The java code for creating a zip Filesystem: The excpetions already happens at the creation of the filesystem: 用于创建zip文件系统的Java代码:创建文件系统时已经发生了一些异常:

 private static FileSystem createZipFileSystem(Path zipFilename,
            boolean create)
            throws IOException {
        // convert the filename to a URI

        final URI uri = URI.create("jar:file:" + zipFilename.toUri().getPath());

        final Map<String, String> env = new HashMap<>();
        if (create) {
            env.put("create", "true");
        }
        return FileSystems.newFileSystem(uri, env);
    }

The exception I get: 我得到的例外:

  java.util.zip.ZipError: zip END header not found
            at com.sun.nio.zipfs.ZipFileSystem.zerror(ZipFileSystem.java:1605)
            at com.sun.nio.zipfs.ZipFileSystem.findEND(ZipFileSystem.java:1021)
            at com.sun.nio.zipfs.ZipFileSystem.initCEN(ZipFileSystem.java:1030)
            at com.sun.nio.zipfs.ZipFileSystem.<init>(ZipFileSystem.java:130)
            at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:117)
            at java.nio.file.FileSystems.newFileSystem(FileSystems.java:326)
            at java.nio.file.FileSystems.newFileSystem(FileSystems.java:276)

我发现问题不是与解压缩有关,而是过了一会儿才意识到我遇到了如下所述的问题: 在写入文件之前触发了Java 7 Watch Service ENTRY_CREATE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM