URLUtil { @Nullable public static Pair<String, String> splitJarUrl(@NotNull String url) { int pivot = url.indexOf(JAR_SEPARATOR); if (pivot < 0) return null; String resourcePath = url.substring(pivot + 2); String jarPath = url.substring(0, pivot); if (StringUtil.startsWithConcatenation(jarPath, JAR_PROTOCOL, ":")) { jarPath = jarPath.substring(JAR_PROTOCOL.length() + 1); } if (jarPath.startsWith(FILE_PROTOCOL)) { jarPath = jarPath.substring(FILE_PROTOCOL.length()); if (jarPath.startsWith(SCHEME_SEPARATOR)) { jarPath = jarPath.substring(SCHEME_SEPARATOR.length()); } else if (StringUtil.startsWithChar(jarPath, ':')) { jarPath = jarPath.substring(1); } } return Pair.create(jarPath, resourcePath); } private  URLUtil(); @NotNull static InputStream openStream(@NotNull URL url); @NotNull static InputStream openResourceStream(@NotNull URL url); @Nullable static Pair<String, String> splitJarUrl(@NotNull String url); @NotNull static String unescapePercentSequences(@NotNull String s); static boolean containsScheme(@NotNull String url); static boolean isDataUri(@NotNull String value); @Nullable static byte[] getBytesFromDataUri(@NotNull String dataUrl); @NotNull static String parseHostFromSshUrl(@NotNull String sshUrl); static final String SCHEME_SEPARATOR; static final String FILE_PROTOCOL; static final String HTTP_PROTOCOL; static final String JAR_PROTOCOL; static final String JAR_SEPARATOR; static final Pattern DATA_URI_PATTERN; static final Pattern URL_PATTERN; }
@Test public void testJarUrlSplitter() { assertNull(URLUtil.splitJarUrl("/path/to/jar.jar/resource.xml")); assertNull(URLUtil.splitJarUrl("/path/to/jar.jar!resource.xml")); assertPair(URLUtil.splitJarUrl("/path/to/jar.jar!/resource.xml"), "/path/to/jar.jar", "resource.xml"); assertPair(URLUtil.splitJarUrl("file:/path/to/jar.jar!/resource.xml"), "/path/to/jar.jar", "resource.xml"); assertPair(URLUtil.splitJarUrl("file: assertPair(URLUtil.splitJarUrl("jar:/path/to/jar.jar!/resource.xml"), "/path/to/jar.jar", "resource.xml"); assertPair(URLUtil.splitJarUrl("jar:file:/path/to/jar.jar!/resource.xml"), "/path/to/jar.jar", "resource.xml"); assertPair(URLUtil.splitJarUrl("jar:file: }