private static BreakIterator createBreakInstance(ULocale locale, int kind) {
BreakIterator iter = null;
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BRKITR_BASE_NAME, locale);
//
// Get the binary rules. These are needed for both normal RulesBasedBreakIterators
// and for Dictionary iterators.
//
InputStream ruleStream = null;
try {
String typeKey = KIND_NAMES[kind];
String brkfname = rb.getStringWithFallback("boundaries/" + typeKey);
String rulesFileName = ICUResourceBundle.ICU_BUNDLE +ICUResourceBundle.ICU_BRKITR_NAME+ "/" + brkfname;
ruleStream = ICUData.getStream(rulesFileName);
}
catch (Exception e) {
throw new MissingResourceException(e.toString(),"","");
}
//
// Check whether a dictionary exists, and create a DBBI iterator is
// one does.
//
if (DICTIONARY_POSSIBLE[kind]) {
// This type of break iterator could potentially use a dictionary.
//
try {
//ICUResourceBundle dictRes = (ICUResourceBundle)rb.getObject("BreakDictionaryData");
//byte[] dictBytes = null;
//dictBytes = dictRes.getBinary(dictBytes);
//TODO: Hard code this for now! fix it once CompactTrieDictionary is ported
if(locale.equals("th")){
String fileName = "data/th.brk";
InputStream is = ICUData.getStream(fileName);
iter = new DictionaryBasedBreakIterator(ruleStream, is);
}
} catch (MissingResourceException e) {
// Couldn't find a dictionary.
// This is normal, and will occur whenever creating a word or line
// break iterator for a locale that does not have a BreakDictionaryData
// resource - meaning for all but Thai.
// Fall through to creating a normal RulebasedBreakIterator.
} catch (IOException e) {
Assert.fail(e);
}
}
if (iter == null) {
//
// Create a normal RuleBasedBreakIterator.
// We have determined that this is not supposed to be a dictionary iterator.
//
try {
iter = RuleBasedBreakIterator.getInstanceFromCompiledRules(ruleStream);
}
catch (IOException e) {
// Shouldn't be possible to get here.
// If it happens, the compiled rules are probably corrupted in some way.
Assert.fail(e);
}
}
// TODO: Determine valid and actual locale correctly.
ULocale uloc = ULocale.forLocale(rb.getLocale());
iter.setLocale(uloc, uloc);
return iter;
}