< prev index next >

src/java.base/share/classes/java/nio/charset/Charset.java

Print this page




 264  * between sequences of sixteen-bit UTF-16 code units (that is, sequences
 265  * of chars) and sequences of bytes. </p>
 266  *
 267  *
 268  * @author Mark Reinhold
 269  * @author JSR-51 Expert Group
 270  * @since 1.4
 271  *
 272  * @see CharsetDecoder
 273  * @see CharsetEncoder
 274  * @see java.nio.charset.spi.CharsetProvider
 275  * @see java.lang.Character
 276  */
 277 
 278 public abstract class Charset
 279     implements Comparable<Charset>
 280 {
 281 
 282     /* -- Static methods -- */
 283 
 284     private static volatile String bugLevel;
 285 
 286     static boolean atBugLevel(String bl) {              // package-private
 287         String level = bugLevel;
 288         if (level == null) {
 289             if (!VM.isBooted())
 290                 return false;
 291             bugLevel = level = GetPropertyAction
 292                     .privilegedGetProperty("sun.nio.cs.bugLevel", "");
 293         }
 294         return level.equals(bl);
 295     }
 296 
 297     /**
 298      * Checks that the given string is a legal charset name. </p>
 299      *
 300      * @param  s
 301      *         A purported charset name
 302      *
 303      * @throws  IllegalCharsetNameException
 304      *          If the given name is not a legal charset name
 305      */
 306     private static void checkName(String s) {
 307         int n = s.length();
 308         if (n == 0 && !atBugLevel("1.4")) {
 309             throw new IllegalCharsetNameException(s);
 310         }
 311         for (int i = 0; i < n; i++) {
 312             char c = s.charAt(i);
 313             if (c >= 'A' && c <= 'Z') continue;
 314             if (c >= 'a' && c <= 'z') continue;
 315             if (c >= '0' && c <= '9') continue;
 316             if (c == '-' && i != 0) continue;
 317             if (c == '+' && i != 0) continue;
 318             if (c == ':' && i != 0) continue;
 319             if (c == '_' && i != 0) continue;
 320             if (c == '.' && i != 0) continue;
 321             throw new IllegalCharsetNameException(s);
 322         }
 323     }
 324 
 325     /* The standard set of charsets */
 326     private static final CharsetProvider standardProvider = new StandardCharsets();
 327 
 328     private static final String[] zeroAliases = new String[0];




 264  * between sequences of sixteen-bit UTF-16 code units (that is, sequences
 265  * of chars) and sequences of bytes. </p>
 266  *
 267  *
 268  * @author Mark Reinhold
 269  * @author JSR-51 Expert Group
 270  * @since 1.4
 271  *
 272  * @see CharsetDecoder
 273  * @see CharsetEncoder
 274  * @see java.nio.charset.spi.CharsetProvider
 275  * @see java.lang.Character
 276  */
 277 
 278 public abstract class Charset
 279     implements Comparable<Charset>
 280 {
 281 
 282     /* -- Static methods -- */
 283 













 284     /**
 285      * Checks that the given string is a legal charset name. </p>
 286      *
 287      * @param  s
 288      *         A purported charset name
 289      *
 290      * @throws  IllegalCharsetNameException
 291      *          If the given name is not a legal charset name
 292      */
 293     private static void checkName(String s) {
 294         int n = s.length();
 295         if (n == 0) {
 296             throw new IllegalCharsetNameException(s);
 297         }
 298         for (int i = 0; i < n; i++) {
 299             char c = s.charAt(i);
 300             if (c >= 'A' && c <= 'Z') continue;
 301             if (c >= 'a' && c <= 'z') continue;
 302             if (c >= '0' && c <= '9') continue;
 303             if (c == '-' && i != 0) continue;
 304             if (c == '+' && i != 0) continue;
 305             if (c == ':' && i != 0) continue;
 306             if (c == '_' && i != 0) continue;
 307             if (c == '.' && i != 0) continue;
 308             throw new IllegalCharsetNameException(s);
 309         }
 310     }
 311 
 312     /* The standard set of charsets */
 313     private static final CharsetProvider standardProvider = new StandardCharsets();
 314 
 315     private static final String[] zeroAliases = new String[0];


< prev index next >