ICU-5886 fix loading under security manager

X-SVN-Rev: 22588
This commit is contained in:
Steven R. Loomis 2007-08-31 01:02:05 +00:00
parent b5fe986e6c
commit 0e5530bc47

View File

@ -7,14 +7,21 @@
package com.ibm.icu.impl.duration.impl; package com.ibm.icu.impl.duration.impl;
import java.util.*;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.zip.DataFormatException;
import java.io.OutputStreamWriter; import com.ibm.icu.impl.ICUData;
/** /**
* A PeriodFormatterDataService that serves PeriodFormatterData * A PeriodFormatterDataService that serves PeriodFormatterData
@ -49,11 +56,8 @@ public class ResourceBasedPeriodFormatterDataService
*/ */
private ResourceBasedPeriodFormatterDataService() { private ResourceBasedPeriodFormatterDataService() {
List localeNames = new ArrayList(); // of String List localeNames = new ArrayList(); // of String
InputStream is = ICUData.getRequiredStream(getClass(), PATH + "index.txt");
try { try {
InputStream is = getClass().getResourceAsStream(PATH + "index.txt");
if (is == null) {
System.err.println("could not load index.txt");
} else {
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String string = null; String string = null;
while (null != (string = br.readLine())) { while (null != (string = br.readLine())) {
@ -64,9 +68,8 @@ public class ResourceBasedPeriodFormatterDataService
localeNames.add(string); localeNames.add(string);
} }
} }
} catch (IOException e) {
catch (Exception e) { System.err.println("IO Error reading index.txt ");
System.err.println(e.getMessage());
} }
availableLocales = Collections.unmodifiableList(localeNames); availableLocales = Collections.unmodifiableList(localeNames);
} }
@ -94,7 +97,7 @@ public class ResourceBasedPeriodFormatterDataService
if (ln != null) { if (ln != null) {
String name = PATH + "pfd_" + ln + ".xml"; String name = PATH + "pfd_" + ln + ".xml";
try { try {
InputStream is = getClass().getResourceAsStream(name); InputStream is = ICUData.getStream(getClass(), name);
if (is == null) { if (is == null) {
throw new MissingResourceException("no resource named " + name,name,""); throw new MissingResourceException("no resource named " + name,name,"");
} else { } else {