FileDocCategorySizeDatePackage
CharsetProviderICU.javaAPI DocAndroid 1.5 API4003Wed May 06 22:41:04 BST 2009com.ibm.icu4jni.charset

CharsetProviderICU

public final class CharsetProviderICU extends CharsetProvider
Copyright (C) 1996-2005, International Business Machines Corporation and * others. All Rights Reserved. *

Fields Summary
Constructors Summary
public CharsetProviderICU()
Constructs a CharsetProviderICU object

stable
ICU 2.4

    
Methods Summary
public final java.nio.charset.CharsetcharsetForName(java.lang.String charsetName)
Constructs a charset for the given charset name

param
charsetName charset name
return
charset objet for the given charset name
stable
ICU 2.4

        // get the canonical name    
        String icuCanonicalName = NativeConverter.getICUCanonicalName(charsetName);      

        // create the converter object and return it
        if(icuCanonicalName==null || icuCanonicalName.length()==0){
            // this would make the Charset API to throw 
            // unsupported encoding exception
            return null;
        }
        
        // BEGIN android-added
        try{
            long cn = NativeConverter.openConverter(icuCanonicalName);
            NativeConverter.closeConverter(cn);
        }catch (RuntimeException re) {
            // unsupported encoding. let the charset api throw an 
            // UnsupportedEncodingException
            return null;
        }
        // END android-added
        
        return getCharset(icuCanonicalName);
    
public final java.util.Iteratorcharsets()
Returns an iterator for the available charsets

return
Iterator the charset name iterator
stable
ICU 2.4

          String[] charsets = NativeConverter.getAvailable();
          Iterator iter = new CharsetIterator(charsets);
          return iter;
    
private final java.nio.charset.CharsetgetCharset(java.lang.String icuCanonicalName)

       String[] aliases = (String[])NativeConverter.getAliases(icuCanonicalName);    
       String canonicalName = NativeConverter.getJavaCanonicalName(icuCanonicalName);
       return (new CharsetICU(canonicalName,icuCanonicalName, aliases));  
    
public final voidputCharsets(java.util.Map map)
Adds an entry to the given map whose key is the charset's canonical name and whose value is the charset itself.

param
map a map to receive charset objects and names
stable
ICU 2.4

        // Get the available converter canonical names and aliases    
        String[] charsets = NativeConverter.getAvailable();        
        for(int i=0; i<charsets.length;i++){           
            // store the charsets and aliases in a Map    
            if (!map.containsKey(charsets[i])){
                map.put(charsets[i], charsetForName(charsets[i]));
            }
        }