Skip to content

Instantly share code, notes, and snippets.

@matheusmoreira
Created February 22, 2011 00:13
Show Gist options
  • Save matheusmoreira/837971 to your computer and use it in GitHub Desktop.
Save matheusmoreira/837971 to your computer and use it in GitHub Desktop.
jar.getNextJarEntry() never seems to return anything other than null
// I18n.java
// Excerpt for question on StackOverflow
// http://stackoverflow.com/questions/5061554/how-do-i-access-the-content-of-folders-inside-a-jar-file
/**
* Private implementation method.
* @return a list containing the locales implemented by the resource bundles
*/
private static List<Locale> getLocaleListFromJar() {
List<Locale> locales = new ArrayList<Locale>();
try {
URL packageUrl = I18n.class.getProtectionDomain().getCodeSource().getLocation();
JarInputStream jar = new JarInputStream(packageUrl.openStream());
while (true) {
JarEntry entry = jar.getNextJarEntry();
if (entry == null) {
break;
}
String name = entry.getName();
if (resourceBundlePattern.matcher(name).matches()) {
addLocaleFromResourceBundle(name, locales);
}
}
} catch (Exception e) {
System.err.println(e);
return getLocaleListFromFile(); // File based implementation in case resources are not in jar
}
return locales;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment