ICU-3404 let there be exceptions

X-SVN-Rev: 13791
This commit is contained in:
Ram Viswanadha 2003-11-20 19:32:49 +00:00
parent 4fd05d4fc6
commit 5538a4c0b7
2 changed files with 49 additions and 41 deletions

View file

@ -5,13 +5,14 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/util/ICUListResourceBundleTest.java,v $
* $Date: 2003/11/20 01:41:01 $
* $Revision: 1.8 $
* $Date: 2003/11/20 19:32:49 $
* $Revision: 1.9 $
*
*******************************************************************************
*/
package com.ibm.icu.dev.test.util;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import com.ibm.icu.dev.test.TestFmwk;
@ -302,20 +303,25 @@ public final class ICUListResourceBundleTest extends TestFmwk
}else{
errln("Did not get the expected bundle.");
}
/*
ResourceBundle bundle1 = ICULocaleData.getResourceBundle("com.ibm.icu.impl.data","LocaleElements","de__PHONEBOOK");
if(bundle instanceof ICUListResourceBundle){
ICUListResourceBundle ilrb = (ICUListResourceBundle) bundle1;
String key = (String) ilrb.getObjectWithFallback("collations/collation/default");
if(!key.equals("phonebook")){
errln("Did not get the expected result from getObjectWithFallback method.");
}
}else{
errln("Did not get the expected bundle.");
}
*/
try{
ResourceBundle bundle1 = ICULocaleData.getResourceBundle("com.ibm.icu.impl.data","LocaleElements","de__PHONEBOOK");
if(bundle instanceof ICUListResourceBundle){
ICUListResourceBundle ilrb = (ICUListResourceBundle) bundle1;
String key = (String) ilrb.getObjectWithFallback("collations/collation/default");
if(!key.equals("phonebook")){
errln("Did not get the expected result from getObjectWithFallback method.");
}
}else{
errln("Did not get the expected bundle.");
}
errln("Did not get the expected exception.");
}catch(MissingResourceException ex){
logln("got the expected exception");
}
}
}

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/ICUListResourceBundle.java,v $
* $Date: 2003/11/20 01:41:23 $
* $Revision: 1.15 $
* $Date: 2003/11/20 19:31:07 $
* $Revision: 1.16 $
*
*******************************************************************************
*/
@ -64,18 +64,21 @@ public class ICUListResourceBundle extends ListResourceBundle {
*/
protected Object[][] getContents(){
// we replace any redirected values with real values in a cloned array
if (realContents == null) {
realContents = contents;
for (int i = 0; i < contents.length; ++i) {
Object newValue = getRedirectedResource((String)contents[i][0],contents[i][1], -1);
if (newValue != null) {
if (realContents == contents) {
realContents = (Object[][])contents.clone();
try{
if (realContents == null) {
realContents = contents;
for (int i = 0; i < contents.length; ++i) {
Object newValue = getRedirectedResource((String)contents[i][0],contents[i][1], -1);
if (newValue != null) {
if (realContents == contents) {
realContents = (Object[][])contents.clone();
}
realContents[i] = new Object[] { contents[i][0], newValue };
}
realContents[i] = new Object[] { contents[i][0], newValue };
}
}
}catch (Exception e){
throw new MissingResourceException("Internal Program error: " + e.toString(), this.getClass().getName(),"");
}
return realContents;
@ -85,7 +88,8 @@ public class ICUListResourceBundle extends ListResourceBundle {
* Return null if value is already in existing contents array, otherwise fetch the
* real value and return it.
*/
private Object getRedirectedResource(String key, Object value, int index) {
private Object getRedirectedResource(String key, Object value, int index)
throws Exception{
if (value instanceof Object[][]) {
Object[][] aValue = (Object[][])value;
@ -118,7 +122,7 @@ public class ICUListResourceBundle extends ListResourceBundle {
return value;
}
private static byte[] readToEOS(InputStream stream) {
private static byte[] readToEOS(InputStream stream) throws Exception{
ArrayList vec = new ArrayList();
int count = 0;
@ -129,17 +133,15 @@ public class ICUListResourceBundle extends ListResourceBundle {
pos = 0;
length = length >= MAXLENGTH ? MAXLENGTH : length * 2;
byte[] buffer = new byte[length];
try {
do {
int n = stream.read(buffer, pos, length - pos);
if (n == -1) {
break;
}
pos += n;
} while (pos < length);
}
catch (IOException e) {
}
do {
int n = stream.read(buffer, pos, length - pos);
if (n == -1) {
break;
}
pos += n;
} while (pos < length);
vec.add(buffer);
count += pos;
} while (pos == length);
@ -229,7 +231,7 @@ public class ICUListResourceBundle extends ListResourceBundle {
}
private interface RedirectedResource{
public Object getResource(Object obj);
public Object getResource(Object obj) throws Exception;
}
public static class ResourceBinary implements RedirectedResource{
@ -238,7 +240,7 @@ public class ICUListResourceBundle extends ListResourceBundle {
public ResourceBinary(String name){
resName=name;
}
public Object getResource(Object obj){
public Object getResource(Object obj) throws Exception{
if(expanded==null){
InputStream stream = obj.getClass().getResourceAsStream(resName);
if(stream!=null){