Try with resources

This commit is contained in:
Draycia committed 2022-02-18 22:29:46 -08:00
1 parent 6cad3c3173
commit c0d2d83941
1 file changed
+22 -20
@@ -141,32 +141,34 @@ public final class CarbonMessageSource implements IMessageSource<Audience, Strin
}
}));
Files.walk(localeDirectory).filter(Files::isRegularFile).forEach(path -> {
final String localeString = path.getFileName().toString().substring("messages-".length()).replace(".properties", "");
final @Nullable Locale locale = Translator.parseLocale(localeString.replace("nb_NO", "no_NO"));
try (final Stream<Path> paths = Files.walk(localeDirectory)) {
paths.filter(Files::isRegularFile).forEach(path -> {
final String localeString = path.getFileName().toString().substring("messages-".length()).replace(".properties", "");
final @Nullable Locale locale = Translator.parseLocale(localeString.replace("nb_NO", "no_NO"));
if (locale == null) {
this.logger.warn("Unknown locale '{}'?", localeString);
return;
}
if (locale == null) {
this.logger.warn("Unknown locale '{}'?", localeString);
return;
}
if (this.locales.containsKey(locale)) {
return;
}
if (this.locales.containsKey(locale)) {
return;
}
this.logger.info("Found locale {} ({}) in: {}", locale.getDisplayName(), locale, path);
this.logger.info("Found locale {} ({}) in: {}", locale.getDisplayName(), locale, path);
final Properties properties = new Properties();
final Properties properties = new Properties();
try {
this.loadProperties(properties, localeDirectory, path);
this.locales.put(locale, properties);
try {
this.loadProperties(properties, localeDirectory, path);
this.locales.put(locale, properties);
this.logger.info("Successfully loaded locale {} ({})", locale.getDisplayName(), locale);
} catch (final IOException ex) {
this.logger.warn("Unable to load locale {} ({}) from source: {}", locale.getDisplayName(), locale, path, ex);
}
});
this.logger.info("Successfully loaded locale {} ({})", locale.getDisplayName(), locale);
} catch (final IOException ex) {
this.logger.warn("Unable to load locale {} ({}) from source: {}", locale.getDisplayName(), locale, path, ex);
}
});
}
}
@Override