static public FSEntryResource create ( String name , ClassLoader classLoader , String resourceName ) throws Exception { URL url = classLoader . getResource ( resourceName ) ; if ( "jar" . equals ( url . getProtocol ( ) ) ) { String path = url . getPath ( ) ; if ( path . startsWith ( "file:" ) ) { int bangIndex = path . indexOf ( ' ' ) ; if ( bangIndex >= 0 ) { String jarFileName = path . substring ( "file:" . length ( ) , bangIndex ) ; String resourceNameFile = path . substring ( bangIndex + 2 ) ; String resourceNameDir = resourceNameFile ; if ( false == resourceNameDir . endsWith ( "/" ) ) { resourceNameDir = resourceNameFile + "/" ; } JarFile jarFile = new JarFile ( URLDecoder . decode ( jarFileName , "UTF-8" ) ) ; Enumeration < JarEntry > entries = jarFile . entries ( ) ; while ( entries . hasMoreElements ( ) ) { JarEntry jarEntry = entries . nextElement ( ) ; String entryName = jarEntry . getName ( ) ; if ( entryName . equals ( resourceNameFile ) || entryName . equals ( resourceNameDir ) ) { // Compute name if required if ( null == name ) { name = nameFromJarEntry ( jarEntry ) ; } return new FSEntryResource ( name , jarFile , jarEntry ) ; } } } } throw new Exception ( "Unable to find resource: " + resourceName ) ; } else if ( "file" . equals ( url . getProtocol ( ) ) ) { File file = new File ( url . getFile ( ) ) ; if ( null == name ) { name = file . getName ( ) ; } return new FSEntryResource ( name , file ) ; } else { throw new Exception ( "Unable to create resource entry for protocol: " + url . getProtocol ( ) ) ; } }
Creates an instance of FSEntryResource to represent an entry based on the resource specified by the classLoader and resource name . This resource can be a file or a directory . Furthermore this resource can be located on file system or inside a JAR file .