code: private static boolean inEncoding(char ch, byte[] data) {
          final boolean isInEncoding;
          // If the string written out as data is not in the encoding,
          // the output is not specified according to the documentation
          // on the String.getBytes(encoding) method,
          // but we do our best here.        
          if (data==null || data.length == 0) {
              isInEncoding = false;
          }
          else {
              if (data[0] == 0)
                  isInEncoding = false;
              else if (data[0] == '?' && ch != '?')
                  isInEncoding = false;
              /*
               * else if (isJapanese) {
               *   // isJapanese is really 
               *   //   (    "EUC-JP".equals(javaName) 
               *   //    ||  "EUC_JP".equals(javaName)
               *  //     ||  "SJIS".equals(javaName)   )
               * 
               *   // Work around some bugs in JRE for Japanese
               *   if(data[0] == 0x21)
               *     isInEncoding = false;
               *   else if (ch == 0xA5)
               *     isInEncoding = false;
               *   else
               *     isInEncoding = true;
               * }
               */ 
                  
              else {
                  // We don't know for sure, but it looks like it is in the encoding
                  isInEncoding = true; 
              }
          }
          return isInEncoding;
      }
docs: This method is the core of determining if character
  is in the encoding. The method is not foolproof, because
  s.getBytes(encoding) has specified behavior only if the
  characters are in the specified encoding. However this
  method tries it's best.
  @param ch the char that was converted using getBytes, or
  the first char of a high/low pair that was converted.
  @param data the bytes written out by the call to s.getBytes(encoding);
  @return true if the character is in the encoding.