use of java.util.PropertyResourceBundle in project imageio-ext by geosolutions-it.
the class I18N method getString.
static String getString(String key) {
PropertyResourceBundle bundle = null;
try {
InputStream stream = clazz.getResourceAsStream("properties");
bundle = new PropertyResourceBundle(stream);
} catch (Throwable e) {
// Chain the exception.
throw new RuntimeException(e);
}
return (String) bundle.handleGetObject(key);
}
use of java.util.PropertyResourceBundle in project Nucleus by NucleusPowered.
the class UTF8Control method newBundle.
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException {
// The below is a copy of the default implementation.
String bundleName = toBundleName(baseName, locale);
String resourceName = toResourceName(bundleName, "properties");
ResourceBundle bundle = null;
InputStream stream = null;
if (reload) {
URL url = loader.getResource(resourceName);
if (url != null) {
URLConnection connection = url.openConnection();
if (connection != null) {
connection.setUseCaches(false);
stream = connection.getInputStream();
}
}
} else {
stream = loader.getResourceAsStream(resourceName);
}
if (stream != null) {
try {
// Only this line is changed to make it to read properties files as UTF-8.
bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
} finally {
stream.close();
}
}
return bundle;
}
use of java.util.PropertyResourceBundle in project Minigames by AddstarMC.
the class UTF8Control method newBundle.
@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IOException {
// The below is a copy of the default implementation.
String bundleName = toBundleName(baseName, locale);
String resourceName = toResourceName(bundleName, "properties");
ResourceBundle bundle = null;
InputStream stream = null;
if (reload) {
URL url = loader.getResource(resourceName);
if (url != null) {
URLConnection connection = url.openConnection();
if (connection != null) {
connection.setUseCaches(false);
stream = connection.getInputStream();
}
}
} else {
stream = loader.getResourceAsStream(resourceName);
}
if (stream != null) {
try {
// Only this line is changed to make it to read properties files as UTF-8.
bundle = new PropertyResourceBundle(new InputStreamReader(stream, StandardCharsets.UTF_8));
} finally {
stream.close();
}
}
return bundle;
}
use of java.util.PropertyResourceBundle in project es6draft by anba.
the class PropertiesReaderControl method newBundle.
@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IOException {
if ("java.properties".equals(format)) {
String bundleName = toBundleName(baseName, locale);
String resourceName = toResourceName(bundleName, "properties");
InputStream stream = getInputStream(loader, resourceName, reload);
if (stream == null) {
return null;
}
try (Reader reader = new InputStreamReader(stream, charset)) {
return new PropertyResourceBundle(reader);
}
}
throw new IllegalArgumentException("unknown format: " + format);
}
use of java.util.PropertyResourceBundle in project jmeter by apache.
the class ResourceKeyUsageTest method checkResourceReferences.
// Check that calls to getResString use a valid property key name
@Test
public void checkResourceReferences() throws Exception {
String resourceName = "/org/apache/jmeter/resources/messages.properties";
PropertyResourceBundle messagePRB = getRAS(resourceName);
assertNotNull("Resource bundle " + resourceName + " was not found", resourceName);
List<String> failures = new ArrayList<>();
PackageTest.findFile(srcFiledir, null, new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
final File file = new File(dir, name);
// Look for calls to JMeterUtils.getResString()
final Pattern pat = Pattern.compile(".*getResString\\(\"([^\"]+)\"\\).*");
if (name.endsWith(".java")) {
BufferedReader fileReader = null;
try {
fileReader = new BufferedReader(new FileReader(file));
String s;
while ((s = fileReader.readLine()) != null) {
if (s.matches("\\s*//.*")) {
// leading comment
continue;
}
Matcher m = pat.matcher(s);
if (m.matches()) {
final String key = m.group(1);
// Resource keys cannot contain spaces, and are forced to lower case
// $NON-NLS-1$ // $NON-NLS-2$
String resKey = key.replace(' ', '_');
resKey = resKey.toLowerCase(java.util.Locale.ENGLISH);
if (!key.equals(resKey)) {
System.out.println(file + ": non-standard message key: '" + key + "'");
}
try {
messagePRB.getString(resKey);
} catch (MissingResourceException e) {
failures.add(file + ": missing message key: '" + key + "'");
}
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
JOrphanUtils.closeQuietly(fileReader);
}
}
return file.isDirectory();
}
});
if (failures.isEmpty()) {
return;
}
fail(String.join("\n", failures));
}
Aggregations