是否存在嵌套存档的有效java.net.uri?

是否存在嵌套存档的有效java.net.uri?,java,jar,uri,archive,nio2,Java,Jar,Uri,Archive,Nio2,通过使用jar:,可以读取基本上重命名为.zip文件(.ear、.war、.jar等)的归档格式,尽管这可能是不明智的 例如,当uri变量的计算结果为单个顶级存档时,例如当uri等于jar时,以下代码运行良好:file:///Users/justingarrick/Desktop/test/my_war.war!/ private FileSystem createZipFileSystem(Path path) throws IOException { URI uri = URI.cr

通过使用
jar:
,可以读取基本上重命名为.zip文件(.ear、.war、.jar等)的归档格式,尽管这可能是不明智的

例如,当
uri
变量的计算结果为单个顶级存档时,例如当
uri
等于
jar时,以下代码运行良好:file:///Users/justingarrick/Desktop/test/my_war.war!/

private FileSystem createZipFileSystem(Path path) throws IOException {
    URI uri = URI.create("jar:" + path.toUri().toString());
    FileSystem fs;

    try {
        fs = FileSystems.getFileSystem(uri);
    } catch (FileSystemNotFoundException e) {
        fs = FileSystems.newFileSystem(uri, new HashMap<>());
    }

    return fs;
}
专用文件系统createZipFileSystem(路径路径)引发IOException{
URI=URI.create(“jar:+path.toUri().toString());
文件系统fs;
试一试{
fs=FileSystems.getFileSystem(uri);
}捕获(FileSystemNotFounde异常){
fs=FileSystems.newFileSystem(uri,newHashMap());
}
返回fs;
}
但是,当URI包含嵌套存档时,
getFileSystem
newFileSystem
调用会失败,并出现
IllegalArgumentException
,例如当
URI
等于
jar:jar:file:///Users/justingarrick/Desktop/test/my_war.war!/一些罐子/(一个.war中的.jar)


嵌套存档文件是否有有效的
java.net.URI
方案?

正如Jonas Berlin在上面的评论中所述,答案是。从:


从内存来看,答案是否定的。Java在转义
方面仍然存在未修复的错误在URI中(尝试在目录名的末尾添加一个bang,然后将其添加到类路径中),因此我的直觉反应是,要让它以您想要的方式工作,您需要做一些工作。从java源代码(java.net.JarURLConnection)中,答案也是否定的:`int separator=spec.indexOf(!/“”);           /*            * 提醒:我们不处理嵌套的JAR URL*/`
/* get the specs for a given url out of the cache, and compute and
 * cache them if they're not there.
 */
private void parseSpecs(URL url) throws MalformedURLException {
    String spec = url.getFile();

    int separator = spec.indexOf("!/");
    /*
     * REMIND: we don't handle nested JAR URLs
     */
    if (separator == -1) {
        throw new MalformedURLException("no !/ found in url spec:" + spec);
    }

    jarFileURL = new URL(spec.substring(0, separator++));
    entryName = null;

    /* if ! is the last letter of the innerURL, entryName is null */
    if (++separator != spec.length()) {
        entryName = spec.substring(separator, spec.length());
        entryName = ParseUtil.decode (entryName);
    }
}