This commit is contained in:
jendib 2013-08-26 22:03:14 +02:00
parent 6e3d2ea972
commit ac3580fb4a

View File

@ -54,28 +54,33 @@ public class ResourceUtil {
// Extract the JAR path // Extract the JAR path
String jarPath = dirUrl.getPath().substring(5, dirUrl.getPath().indexOf("!")); String jarPath = dirUrl.getPath().substring(5, dirUrl.getPath().indexOf("!"));
JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
Enumeration<JarEntry> entries = jar.entries();
Set<String> fileSet = new HashSet<String>(); Set<String> fileSet = new HashSet<String>();
while (entries.hasMoreElements()) {
// Filter according to the path
String entryName = entries.nextElement().getName();
if (!entryName.startsWith(path)) {
continue;
}
String name = entryName.substring(path.length());
if (!"".equals(name)) {
// If it is a subdirectory, just return the directory name
int checkSubdir = name.indexOf("/");
if (checkSubdir >= 0) {
name = name.substring(0, checkSubdir);
}
if (filter == null || filter.accept(null, name)) { try {
fileSet.add(name); Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
// Filter according to the path
String entryName = entries.nextElement().getName();
if (!entryName.startsWith(path)) {
continue;
}
String name = entryName.substring(path.length());
if (!"".equals(name)) {
// If it is a subdirectory, just return the directory name
int checkSubdir = name.indexOf("/");
if (checkSubdir >= 0) {
name = name.substring(0, checkSubdir);
}
if (filter == null || filter.accept(null, name)) {
fileSet.add(name);
}
} }
} }
} finally {
jar.close();
} }
return Lists.newArrayList(fileSet); return Lists.newArrayList(fileSet);
} }