URLUtils { public static boolean isDirectoryURL(URL url) { boolean isDirectory = false; if (url != null) { String protocol = url.getProtocol(); try { if (ProtocolConstants.JAR.equals(protocol)) { JarFile jarFile = JarUtils.toJarFile(url); final String relativePath = JarUtils.resolveRelativePath(url); if (StringUtils.EMPTY.equals(relativePath)) { isDirectory = true; } else { JarEntry jarEntry = jarFile.getJarEntry(relativePath); isDirectory = jarEntry != null && jarEntry.isDirectory(); } } else if (ProtocolConstants.FILE.equals(protocol)) { File classPathFile = new File(url.toURI()); isDirectory = classPathFile.isDirectory(); } } catch (Exception e) { isDirectory = false; } } return isDirectory; }  static String resolveRelativePath(URL archiveFileURL); static File resolveArchiveFile(URL archiveFileURL, String archiveFileExtensionName); @Nonnull static Map<String, List<String>> resolveParametersMap(String url); static String resolvePath(final String path); static String encode(String value, String encoding); static String encode(String value); static String decode(String value); static String decode(String value, String encoding); static boolean isDirectoryURL(URL url); static boolean isJarURL(URL url); static String buildURI(String... paths);  }
@Test public void testIsDirectoryURL() throws Exception { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL resourceURL = ClassLoaderUtils.getClassResource(classLoader, StringUtils.class); Assert.assertFalse(URLUtils.isDirectoryURL(resourceURL)); String externalForm = null; externalForm = StringUtils.substringBeforeLast(resourceURL.toExternalForm(), StringUtils.class.getSimpleName() + ".class"); resourceURL = new URL(externalForm); Assert.assertTrue(URLUtils.isDirectoryURL(resourceURL)); resourceURL = ClassLoaderUtils.getClassResource(classLoader, String.class); Assert.assertFalse(URLUtils.isDirectoryURL(resourceURL)); resourceURL = ClassLoaderUtils.getClassResource(classLoader, getClass()); Assert.assertFalse(URLUtils.isDirectoryURL(resourceURL)); externalForm = StringUtils.substringBeforeLast(resourceURL.toExternalForm(), getClass().getSimpleName() + ".class"); resourceURL = new URL(externalForm); Assert.assertTrue(URLUtils.isDirectoryURL(resourceURL)); }