use of java.util.PropertyResourceBundle in project j2objc by google.
the class PropertyResourceBundleTest method test_ConstructorLjava_io_Reader.
/**
* @throws IOException
* {@link java.util.PropertyResourceBundle#PropertyResourceBundle(java.io.Reader)}
* @since 1.6
*/
@SuppressWarnings("nls")
public void test_ConstructorLjava_io_Reader() throws IOException {
Charset charset = Charset.forName("ISO-8859-1");
String content = "p1=one\nfeature=good_feature";
CharBuffer cbuffer = charset.decode(ByteBuffer.wrap(content.getBytes("ISO-8859-1")));
char[] chars = new char[cbuffer.limit()];
cbuffer.get(chars);
prb = new PropertyResourceBundle(new CharArrayReader(chars));
assertEquals(2, prb.keySet().size());
assertEquals("one", prb.getString("p1"));
assertEquals("good_feature", prb.getString("feature"));
charset = Charset.forName("UTF-8");
cbuffer = charset.decode(ByteBuffer.wrap(content.getBytes("UTF-8")));
chars = new char[cbuffer.limit()];
cbuffer.get(chars);
prb = new PropertyResourceBundle(new CharArrayReader(chars));
assertEquals(2, prb.keySet().size());
assertEquals("one", prb.getString("p1"));
assertEquals("good_feature", prb.getString("feature"));
try {
new PropertyResourceBundle((Reader) null);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
}
use of java.util.PropertyResourceBundle in project CitizensAPI by CitizensDev.
the class Translator method getDefaultResourceBundle.
private static ResourceBundle getDefaultResourceBundle(File resourceDirectory, String fileName) {
if (Translator.defaultBundle != null)
return Translator.defaultBundle;
resourceDirectory.mkdirs();
File bundleFile = new File(resourceDirectory, fileName);
if (!bundleFile.exists()) {
try {
bundleFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
Translator.populateDefaults(bundleFile);
FileInputStream stream = null;
try {
stream = new FileInputStream(bundleFile);
Translator.defaultBundle = new PropertyResourceBundle(stream);
} catch (Exception e) {
e.printStackTrace();
Translator.defaultBundle = Translator.getFallbackResourceBundle();
} finally {
Closeables.closeQuietly(stream);
}
return Translator.defaultBundle;
}
use of java.util.PropertyResourceBundle in project jadx by skylot.
the class NLS method load.
private static void load(LangLocale locale) {
ResourceBundle bundle;
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
String resName = String.format("i18n/Messages_%s.properties", locale.get());
URL bundleUrl = classLoader.getResource(resName);
if (bundleUrl == null) {
throw new JadxRuntimeException("Locale resource not found: " + resName);
}
try (Reader reader = new InputStreamReader(bundleUrl.openStream(), StandardCharsets.UTF_8)) {
bundle = new PropertyResourceBundle(reader);
} catch (IOException e) {
throw new JadxRuntimeException("Failed to load " + resName, e);
}
LANG_LOCALES_MAP.put(locale, bundle);
}
use of java.util.PropertyResourceBundle in project dbeaver by serge-rider.
the class SQLTemplateStore method readIncludedTemplates.
private void readIncludedTemplates(String contributorId, Collection<TemplatePersistenceData> templates, String file, String translations) throws IOException {
if (file != null) {
Bundle plugin = Platform.getBundle(contributorId);
URL url = FileLocator.find(plugin, Path.fromOSString(file), null);
if (url != null) {
ResourceBundle bundle = null;
if (translations != null) {
URL bundleURL = FileLocator.find(plugin, Path.fromOSString(translations), null);
if (bundleURL != null) {
InputStream bundleStream = bundleURL.openStream();
try {
bundle = new PropertyResourceBundle(bundleStream);
} finally {
ContentUtils.close(bundleStream);
}
}
}
InputStream stream = new BufferedInputStream(url.openStream());
try {
TemplateReaderWriter reader = new TemplateReaderWriter();
TemplatePersistenceData[] datas = reader.read(stream, bundle);
for (TemplatePersistenceData data : datas) {
if (data.isCustom()) {
if (data.getId() == null)
log.error("No template id specified");
else
log.error("Template " + data.getTemplate().getName() + " deleted");
} else if (validateTemplate(data.getTemplate())) {
templates.add(data);
}
}
} finally {
ContentUtils.close(stream);
}
}
}
}
use of java.util.PropertyResourceBundle in project dbeaver by dbeaver.
the class SQLTemplateStore method readIncludedTemplates.
private void readIncludedTemplates(String contributorId, Collection<TemplatePersistenceData> templates, String file, String translations) throws IOException {
if (file != null) {
Bundle plugin = Platform.getBundle(contributorId);
URL url = FileLocator.find(plugin, Path.fromOSString(file), null);
if (url != null) {
ResourceBundle bundle = null;
if (translations != null) {
URL bundleURL = FileLocator.find(plugin, Path.fromOSString(translations), null);
if (bundleURL != null) {
InputStream bundleStream = bundleURL.openStream();
try {
bundle = new PropertyResourceBundle(bundleStream);
} finally {
ContentUtils.close(bundleStream);
}
}
}
InputStream stream = new BufferedInputStream(url.openStream());
try {
TemplateReaderWriter reader = new TemplateReaderWriter();
TemplatePersistenceData[] datas = reader.read(stream, bundle);
for (TemplatePersistenceData data : datas) {
if (data.isCustom()) {
if (data.getId() == null)
log.error("No template id specified");
else
log.error("Template " + data.getTemplate().getName() + " deleted");
} else if (validateTemplate(data.getTemplate())) {
templates.add(data);
}
}
} finally {
ContentUtils.close(stream);
}
}
}
}
Aggregations