ICU-3301 update with code review comments
X-SVN-Rev: 15508
This commit is contained in:
parent
12e3c5a61c
commit
729257694c
@ -8,9 +8,11 @@ package com.ibm.icu.impl;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
import com.ibm.icu.util.VersionInfo;
|
||||
|
||||
@ -151,7 +153,7 @@ public class ICUResourceBundleReader implements ICUBinary.Authenticate{
|
||||
if(DEBUG) System.out.println("The bytes avialable in stream after reading the header: " + bs.available());
|
||||
|
||||
data = readData(bs);
|
||||
|
||||
|
||||
stream.close();
|
||||
}catch(IOException ex){
|
||||
throw new RuntimeException("Data file "+ resolvedName+ " is corrupt.", ex);
|
||||
@ -188,19 +190,39 @@ public class ICUResourceBundleReader implements ICUBinary.Authenticate{
|
||||
|
||||
int length = indexes[URES_INDEX_BUNDLE_TOP]*4;
|
||||
if(DEBUG) System.out.println("The number of bytes in the bundle: "+length);
|
||||
|
||||
byte[] data = new byte[length];
|
||||
ds.readFully(data);
|
||||
return ByteBuffer.wrap(data);
|
||||
|
||||
if(stream instanceof FileInputStream){
|
||||
FileChannel channel = ((FileInputStream)stream).getChannel();
|
||||
ByteBuffer val = channel.map(FileChannel.MapMode.READ_ONLY,0,length);
|
||||
return val;
|
||||
}else{
|
||||
byte[] data = new byte[length];
|
||||
ds.readFully(data);
|
||||
return ByteBuffer.wrap(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the full name of the resource with suffix.
|
||||
* If the
|
||||
* @param baseName
|
||||
* @param localeName
|
||||
* @return
|
||||
*/
|
||||
public static String getFullName(String baseName, String localeName){
|
||||
baseName = baseName.replace('.','/');
|
||||
if(baseName.charAt(baseName.length()-1)!= '/'){
|
||||
return baseName+"/"+localeName+ICU_RESOURCE_SUFFIX;
|
||||
if(baseName.indexOf('.')==-1){
|
||||
if(baseName.charAt(baseName.length()-1)!= '/'){
|
||||
return baseName+"/"+localeName+ICU_RESOURCE_SUFFIX;
|
||||
}else{
|
||||
return baseName+localeName+ICU_RESOURCE_SUFFIX;
|
||||
}
|
||||
}else{
|
||||
return baseName+localeName+ICU_RESOURCE_SUFFIX;
|
||||
baseName = baseName.replace('.','/');
|
||||
if(localeName.length()==0){
|
||||
return baseName+ICU_RESOURCE_SUFFIX;
|
||||
}else{
|
||||
return baseName+"_"+localeName+ICU_RESOURCE_SUFFIX;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,9 +35,41 @@ import com.ibm.icu.util.ULocale;
|
||||
* More on resource bundle concepts and syntax can be found in the
|
||||
* <a href="http://oss.software.ibm.com/icu/userguide/ResourceManagement.html">Users Guide</a>.
|
||||
* <P>
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* The packaging of ICU *.res files can be of two types
|
||||
* ICU4C:
|
||||
* <code>
|
||||
* root.res
|
||||
* |
|
||||
* --------
|
||||
* | |
|
||||
* fr.res en.res
|
||||
* |
|
||||
* --------
|
||||
* | |
|
||||
* fr_CA.res fr_FR.res
|
||||
* </code>
|
||||
* JAVA/JDK:
|
||||
* <code>
|
||||
* LocaleElements.res
|
||||
* |
|
||||
* -------------------
|
||||
* | |
|
||||
* LocaleElements_fr.res LocaleElements_en.res
|
||||
* |
|
||||
* ---------------------------
|
||||
* | |
|
||||
* LocaleElements_fr_CA.res LocaleElements_fr_FR.res
|
||||
* </code>
|
||||
* Depending on the organization of your resources, the syntax to getBundleInstance will change.
|
||||
* To open ICU style organization use:
|
||||
* <code>
|
||||
* UResourceBundle bundle = UResourceBundle.getBundleInstance("com/ibm/icu/impl/data/icudt30b", "en_US");
|
||||
* </code>
|
||||
* To open Java/JDK style organization use:
|
||||
* <code>
|
||||
* UResourceBundle bundle = UResourceBundle.getBundleInstance("com.ibm.icu.impl.data.LocaleElements", "en_US");
|
||||
* </code>
|
||||
* @draft ICU 3.0
|
||||
* @author ram
|
||||
*/
|
||||
@ -348,7 +380,14 @@ public abstract class UResourceBundle extends ResourceBundle{
|
||||
String fullName = ICUResourceBundleReader.getFullName(baseName, localeName);
|
||||
cacheKey.setKeyValues(root, fullName, defaultLocale);
|
||||
UResourceBundle b = loadFromCache(cacheKey);
|
||||
final String rootLocale = "root";
|
||||
// here we assume that java type resource bundle organization
|
||||
// is required then the base name contains '.' else
|
||||
// the resource organization is of ICU type
|
||||
// so clients can instantiate resources of the type
|
||||
// com.mycompany.data.MyLocaleElements_en.res and
|
||||
// com.mycompany.data.MyLocaleElements.res
|
||||
//
|
||||
final String rootLocale = (baseName.indexOf('.')==-1) ? "root" : "";
|
||||
final String defaultID = ULocale.getDefault().toString();
|
||||
if(localeName.equals("")){
|
||||
localeName = rootLocale;
|
||||
|
Loading…
Reference in New Issue
Block a user