use of java.util.MissingResourceException in project robovm by robovm.
the class ResourceBundleTest method test_getBundle_getClassName.
public void test_getBundle_getClassName() {
// Regression test for Harmony-1759
Locale locale = Locale.GERMAN;
String nonExistentBundle = "Non-ExistentBundle";
try {
ResourceBundle.getBundle(nonExistentBundle, locale, this.getClass().getClassLoader());
fail("MissingResourceException expected!");
} catch (MissingResourceException e) {
assertEquals(nonExistentBundle + "_" + locale, e.getClassName());
}
try {
ResourceBundle.getBundle(nonExistentBundle, locale);
fail("MissingResourceException expected!");
} catch (MissingResourceException e) {
assertEquals(nonExistentBundle + "_" + locale, e.getClassName());
}
locale = Locale.getDefault();
try {
ResourceBundle.getBundle(nonExistentBundle);
fail("MissingResourceException expected!");
} catch (MissingResourceException e) {
assertEquals(nonExistentBundle + "_" + locale, e.getClassName());
}
}
use of java.util.MissingResourceException in project ceylon-compiler by ceylon.
the class JavapTask method getMessage.
public String getMessage(Locale locale, String key, Object... args) {
if (bundles == null) {
// could make this a HashMap<Locale,SoftReference<ResourceBundle>>
// and for efficiency, keep a hard reference to the bundle for the task
// locale
bundles = new HashMap<Locale, ResourceBundle>();
}
if (locale == null)
locale = Locale.getDefault();
ResourceBundle b = bundles.get(locale);
if (b == null) {
try {
b = ResourceBundle.getBundle("com.sun.tools.javap.resources.javap", locale);
bundles.put(locale, b);
} catch (MissingResourceException e) {
throw new InternalError("Cannot find javap resource bundle for locale " + locale);
}
}
try {
return MessageFormat.format(b.getString(key), args);
} catch (MissingResourceException e) {
throw new InternalError(e, key);
}
}
use of java.util.MissingResourceException in project ddf by codice.
the class GeoNamesWebService method getCountryCode.
@Override
public Optional<String> getCountryCode(String locationWkt, int radius) {
notNull(locationWkt, "argument locationWkt may not be null");
Point wktCenterPoint = createPointFromWkt(locationWkt);
String urlStr = String.format("%s://%s/countryCode?lat=%f&lng=%f&radius=%d&type=JSON&username=%s", GEONAMES_PROTOCOL, GEONAMES_API_ADDRESS, wktCenterPoint.getY(), wktCenterPoint.getX(), radius, USERNAME);
Object result = query(urlStr);
if (result instanceof JSONObject) {
JSONObject jsonResult = (JSONObject) result;
Object countryCode = jsonResult.get(GEONAMES_COUNTRYCODE);
if (countryCode != null) {
String alpha2CountryCode = (String) countryCode;
if (StringUtils.isNotEmpty(alpha2CountryCode)) {
try {
String alpha3CountryCode = new Locale(Locale.ENGLISH.getLanguage(), alpha2CountryCode).getISO3Country();
return Optional.of(alpha3CountryCode);
} catch (MissingResourceException e) {
LOGGER.debug("Failed to convert country code {} to alpha-3 format. Returning " + "empty value", alpha2CountryCode);
}
}
}
}
return Optional.empty();
}
use of java.util.MissingResourceException in project jdk8u_jdk by JetBrains.
the class Resources method initializeMessages.
/**
* Initializes all non-final public static fields in the given class with
* messages from a {@link ResourceBundle}.
*
* @param clazz the class containing the fields
*/
public static void initializeMessages(Class<?> clazz, String rbName) {
ResourceBundle rb = null;
try {
rb = ResourceBundle.getBundle(rbName);
} catch (MissingResourceException mre) {
// fall through, handled later
}
for (Field field : clazz.getFields()) {
if (isWritableField(field)) {
String key = field.getName();
String message = getMessage(rb, key);
int mnemonicInt = findMnemonicInt(message);
message = removeMnemonicAmpersand(message);
message = replaceWithPlatformLineFeed(message);
setFieldValue(field, message);
MNEMONIC_LOOKUP.put(message, mnemonicInt);
}
}
}
use of java.util.MissingResourceException in project jdk8u_jdk by JetBrains.
the class BreakDictionary method readDictionaryFile.
private void readDictionaryFile(final String dictionaryName) throws IOException, MissingResourceException {
BufferedInputStream in;
try {
in = AccessController.doPrivileged(new PrivilegedExceptionAction<BufferedInputStream>() {
@Override
public BufferedInputStream run() throws Exception {
return new BufferedInputStream(getClass().getResourceAsStream("/sun/text/resources/" + dictionaryName));
}
});
} catch (PrivilegedActionException e) {
throw new InternalError(e.toString(), e);
}
byte[] buf = new byte[8];
if (in.read(buf) != 8) {
throw new MissingResourceException("Wrong data length", dictionaryName, "");
}
// check version
int version = RuleBasedBreakIterator.getInt(buf, 0);
if (version != supportedVersion) {
throw new MissingResourceException("Dictionary version(" + version + ") is unsupported", dictionaryName, "");
}
// get data size
int len = RuleBasedBreakIterator.getInt(buf, 4);
buf = new byte[len];
if (in.read(buf) != len) {
throw new MissingResourceException("Wrong data length", dictionaryName, "");
}
// close the stream
in.close();
int l;
int offset = 0;
// read in the column map for BMP characteres (this is serialized in
// its internal form: an index array followed by a data array)
l = RuleBasedBreakIterator.getInt(buf, offset);
offset += 4;
short[] temp = new short[l];
for (int i = 0; i < l; i++, offset += 2) {
temp[i] = RuleBasedBreakIterator.getShort(buf, offset);
}
l = RuleBasedBreakIterator.getInt(buf, offset);
offset += 4;
byte[] temp2 = new byte[l];
for (int i = 0; i < l; i++, offset++) {
temp2[i] = buf[offset];
}
columnMap = new CompactByteArray(temp, temp2);
// read in numCols and numColGroups
numCols = RuleBasedBreakIterator.getInt(buf, offset);
offset += 4;
numColGroups = RuleBasedBreakIterator.getInt(buf, offset);
offset += 4;
// read in the row-number index
l = RuleBasedBreakIterator.getInt(buf, offset);
offset += 4;
rowIndex = new short[l];
for (int i = 0; i < l; i++, offset += 2) {
rowIndex[i] = RuleBasedBreakIterator.getShort(buf, offset);
}
// load in the populated-cells bitmap: index first, then bitmap list
l = RuleBasedBreakIterator.getInt(buf, offset);
offset += 4;
rowIndexFlagsIndex = new short[l];
for (int i = 0; i < l; i++, offset += 2) {
rowIndexFlagsIndex[i] = RuleBasedBreakIterator.getShort(buf, offset);
}
l = RuleBasedBreakIterator.getInt(buf, offset);
offset += 4;
rowIndexFlags = new int[l];
for (int i = 0; i < l; i++, offset += 4) {
rowIndexFlags[i] = RuleBasedBreakIterator.getInt(buf, offset);
}
// load in the row-shift index
l = RuleBasedBreakIterator.getInt(buf, offset);
offset += 4;
rowIndexShifts = new byte[l];
for (int i = 0; i < l; i++, offset++) {
rowIndexShifts[i] = buf[offset];
}
// load in the actual state table
l = RuleBasedBreakIterator.getInt(buf, offset);
offset += 4;
table = new short[l];
for (int i = 0; i < l; i++, offset += 2) {
table[i] = RuleBasedBreakIterator.getShort(buf, offset);
}
// finally, prepare the column map for supplementary characters
l = RuleBasedBreakIterator.getInt(buf, offset);
offset += 4;
int[] temp3 = new int[l];
for (int i = 0; i < l; i++, offset += 4) {
temp3[i] = RuleBasedBreakIterator.getInt(buf, offset);
}
supplementaryCharColumnMap = new SupplementaryCharacterData(temp3);
}
Aggregations