Review (Updated) : 4884238 : Constants for Standard Charsets - correction !!!

Ulf Zibis Ulf.Zibis at gmx.de
Tue Apr 19 14:05:54 UTC 2011


package sun.nio.cs;
public class FastCharsetProvider extends CharsetProvider {

     ...

     private Charset lookup(String charsetName) {

         String csn = canonicalize(toLower(charsetName));

         // Check cache first
         Charset cs = cache.get(csn);
         if (cs != null)
             return cs;

         StandardCharset: {
             switch (charsetName) {
                 case US_ASCII : cs = StandardCharset(US_ASCII); break;
                 case ISO_8859_1 : cs = StandardCharset(ISO_8859_1); break;
                 case UTF_8 : cs = StandardCharset(UTF_8); break;
                 case UTF_16 : cs = StandardCharset(UTF_16); break;
                 case UTF_16BE : cs = StandardCharset(UTF_16BE); break;
                 case UTF_16LE : cs = StandardCharset(UTF_16LE); break;
                 default : break StandardCharset;
             }
             cache.put(csn, cs);
             return cs;
         }

         // Do we even support this charset?
         String cln = classMap.get(csn);
         if (cln == null)
             return null;

         // Instantiate the charset and cache it
         ...
     }

     final class StandardCharset extends Charset {
         final String name;

         newDecoder() {
             switch (charsetName) {
                 case US_ASCII : return new US_ASCII.Decoder();
                 case ISO_8859_1 : return new ISO_8859_1.Decoder();
                 case UTF_8 : return new UTF_8.Decoder();
                 case UTF_16 : return new UTF_16.Decoder();
                 case UTF_16BE : return new UTF_16BE.Decoder();
                 case UTF_16LE : return new UTF_16LE.Decoder();
                 default : return Charset.defaultCharset().newDecoder();
             }
         }
         newEncoder() { ... }
         ...

     }

}

-Ulf




More information about the core-libs-dev mailing list