use of java.util.PropertyResourceBundle in project j2objc by google.
the class PropertyResourceBundleTest method test_access$0_Enumeration.
/**
* {@link java.util.PropertyResourceBundle#Enumeration}
*/
public void test_access$0_Enumeration() throws IOException {
class MockResourceBundle extends PropertyResourceBundle {
MockResourceBundle(java.io.InputStream stream) throws IOException {
super(stream);
}
@Override
protected void setParent(ResourceBundle bundle) {
super.setParent(bundle);
}
}
java.io.InputStream localStream = new java.io.ByteArrayInputStream("p3=three\np4=four".getBytes());
MockResourceBundle localPrb = new MockResourceBundle(localStream);
localPrb.setParent(prb);
Enumeration<String> keys = localPrb.getKeys();
Vector<String> contents = new Vector<String>();
while (keys.hasMoreElements()) {
contents.add(keys.nextElement());
}
assertEquals("did not get the right number of properties", 4, contents.size());
assertTrue("did not get the parent property p1", contents.contains("p1"));
assertTrue("did not get the parent property p2", contents.contains("p2"));
assertTrue("did not get the local property p3", contents.contains("p3"));
assertTrue("did not get the local property p4", contents.contains("p4"));
}
use of java.util.PropertyResourceBundle in project j2objc by google.
the class PropertyResourceBundleTest method test_ConstructorLjava_io_InputStream.
/**
* @throws IOException
* java.util.PropertyResourceBundle#PropertyResourceBundle(java.io.InputStream)
*/
@SuppressWarnings("nls")
public void test_ConstructorLjava_io_InputStream() throws IOException {
InputStream propertiesStream = new ByteArrayInputStream("p1=one\ncharset=iso-8859-1".getBytes("ISO-8859-1"));
prb = new PropertyResourceBundle(propertiesStream);
assertEquals(2, prb.keySet().size());
assertEquals("one", prb.getString("p1"));
assertEquals("iso-8859-1", prb.getString("charset"));
propertiesStream = new ByteArrayInputStream("p1=one\ncharset=UTF-8".getBytes("UTF-8"));
prb = new PropertyResourceBundle(propertiesStream);
assertEquals(2, prb.keySet().size());
assertEquals("UTF-8", prb.getString("charset"));
try {
new PropertyResourceBundle((InputStream) null);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
}
use of java.util.PropertyResourceBundle in project java-swing-tips by aterai.
the class Utf8ResourceBundleControl method newBundle.
@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IOException {
ResourceBundle bundle = null;
if ("properties".equals(format)) {
String bundleName = toBundleName(Objects.requireNonNull(baseName, "baseName must not be null"), Objects.requireNonNull(locale, "locale must not be null"));
String resourceName = toResourceName(bundleName, Objects.requireNonNull(format, "format must not be null"));
InputStream stream = null;
ClassLoader cl = Objects.requireNonNull(loader, "loader must not be null");
if (reload) {
URL url = cl.getResource(resourceName);
if (Objects.nonNull(url)) {
URLConnection connection = url.openConnection();
if (Objects.nonNull(connection)) {
connection.setUseCaches(false);
stream = connection.getInputStream();
}
}
} else {
stream = cl.getResourceAsStream(resourceName);
}
if (Objects.nonNull(stream)) {
// BufferedInputStream bis = new BufferedInputStream(stream);
try (Reader r = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
bundle = new PropertyResourceBundle(r);
}
}
}
return bundle;
}
use of java.util.PropertyResourceBundle in project jaffa-framework by jaffa-projects.
the class Variant method loadResource.
private static synchronized PropertyResourceBundle loadResource(String variant) {
PropertyResourceBundle resource = null;
if (c_cache.containsKey(variant))
resource = (PropertyResourceBundle) c_cache.get(variant);
else {
try {
resource = (PropertyResourceBundle) PropertyResourceBundle.getBundle(variant);
c_cache.put(variant, resource);
} catch (MissingResourceException e) {
// Add a null object for the variant into the cache. This will avoid repeated searches for the variant resource.
c_cache.put(variant, null);
}
}
return resource;
}
use of java.util.PropertyResourceBundle in project jaffa-framework by jaffa-projects.
the class Factory method readTestTier.
/**
* Read the tier setting from the middleware_test.properties file
*/
private static Byte readTestTier(String className) {
PropertyResourceBundle prop = null;
try {
prop = (PropertyResourceBundle) PropertyResourceBundle.getBundle(MIDDLEWARE_RESOURCE);
} catch (MissingResourceException e) {
log.warn("Factory Set To Test Mode, But Config File Is Missing!, Mode 2 will be assumed! ", e);
return new Byte(TIER2);
}
try {
String tier = (String) prop.getObject(className);
if (tier == null || "123".indexOf(tier) == -1) {
log.info("Factory Test Mode For Interface '" + className + "' Not Valid. Value is " + tier + ", Mode 2 will be assumed! ");
tier = "" + TIER2;
}
return new Byte(tier);
} catch (MissingResourceException e) {
log.info("Factory Set To Test Mode, But Definition For Interface '" + className + "' not found, Mode 2 will be assumed! ");
return new Byte(TIER2);
}
}
Aggregations