예제 #1
0
 private static void warnUnsupportedCharset(String csn) {
   if (warnUnsupportedCharset) {
     // Use sun.misc.MessageUtils rather than the Logging API or
     // System.err since this method may be called during VM
     // initialization before either is available.
     MessageUtils.err(
         "WARNING: Default charset " + csn + " not supported, using ISO-8859-1 instead");
     warnUnsupportedCharset = false;
   }
 }
예제 #2
0
 static byte[] encode(char[] ca, int off, int len) {
   String csn = Charset.defaultCharset().name();
   try {
     // use charset name encode() variant which provides caching.
     return encode(csn, ca, off, len);
   } catch (UnsupportedEncodingException x) {
     warnUnsupportedCharset(csn);
   }
   try {
     return encode("ISO-8859-1", ca, off, len);
   } catch (UnsupportedEncodingException x) {
     // If this code is hit during VM initialization, MessageUtils is
     // the only way we will be able to get any kind of error message.
     MessageUtils.err("ISO-8859-1 charset not available: " + x.toString());
     // If we can not find ISO-8859-1 (a required encoding) then things
     // are seriously wrong with the installation.
     System.exit(1);
     return null;
   }
 }
예제 #3
0
  static char[] decode(byte[] ba, int off, int len) {

    String csn = Converters.getDefaultEncodingName();

    try {

      return decode(csn, ba, off, len);

    } catch (UnsupportedEncodingException x) {

      Converters.resetDefaultEncodingName();

      warnUnsupportedCharset(csn);
    }

    try {

      return decode("ISO-8859-1", ba, off, len);

    } catch (UnsupportedEncodingException x) {

      // If this code is hit during VM initialization, MessageUtils is

      // the only way we will be able to get any kind of error message.

      MessageUtils.err("ISO-8859-1 charset not available: " + x.toString());

      // If we can not find ISO-8859-1 (a required encoding) then things

      // are seriously wrong with the installation.

      System.exit(1);

      return null;
    }
  }