Created
February 22, 2011 00:13
-
-
Save matheusmoreira/837971 to your computer and use it in GitHub Desktop.
jar.getNextJarEntry() never seems to return anything other than null
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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