@@ -172,23 +172,23 @@ public static String[] getResourceListing(Class clazz, String path) throws IOExc
172172 /* A JAR path */
173173 String jarPath = dirURL .getPath ().substring (5 , dirURL .getPath ().indexOf (
174174 "!" )); // strip out only the JAR file
175- JarFile jar = new JarFile (URLDecoder .decode (jarPath , "UTF-8" ));
176- Enumeration <JarEntry > entries = jar .entries (); // gives ALL entries in jar
177- Set <String > result = new HashSet <String >(); // avoid duplicates in case it is a subdirectory
178- while (entries .hasMoreElements ()) {
179- String name = entries .nextElement ().getName ();
180- if (name .startsWith (path )) { // filter according to the path
181- String entry = name .substring (path .length ());
182- int checkSubdir = entry .indexOf ("/" );
183- if (checkSubdir >= 0 ) {
184- // if it is a subdirectory, we just return the directory name
185- entry = entry .substring (0 , checkSubdir );
175+ try (JarFile jar = new JarFile (URLDecoder .decode (jarPath , "UTF-8" ))) {
176+ Enumeration <JarEntry > entries = jar .entries (); // gives ALL entries in jar
177+ Set <String > result = new HashSet <String >(); // avoid duplicates in case it is a subdirectory
178+ while (entries .hasMoreElements ()) {
179+ String name = entries .nextElement ().getName ();
180+ if (name .startsWith (path )) { // filter according to the path
181+ String entry = name .substring (path .length ());
182+ int checkSubdir = entry .indexOf ("/" );
183+ if (checkSubdir >= 0 ) {
184+ // if it is a subdirectory, we just return the directory name
185+ entry = entry .substring (0 , checkSubdir );
186+ }
187+ result .add (entry );
186188 }
187- result .add (entry );
188189 }
190+ return result .toArray (new String [result .size ()]);
189191 }
190- return result .toArray (new String [result .size ()]);
191- }
192192
193193 throw new UnsupportedOperationException ("Cannot list files for URL "
194194 + dirURL );
0 commit comments