private static boolean inEncoding(char high,char low,String encoding){
  boolean isInEncoding;
  try {
    char cArray[]=new char[2];
    cArray[0]=high;
    cArray[1]=low;
    String s=new String(cArray);
    byte[] bArray=s.getBytes(encoding);
    isInEncoding=inEncoding(high,bArray);
  }
 catch (  Exception e) {
    isInEncoding=false;
  }
  return isInEncoding;
}

private static boolean inEncoding ( char high , char low , String encoding ) { boolean isInEncoding ; try { char cArray [ ] = new char [ 2 ] ; cArray [ 0 ] = high ; cArray [ 1 ] = low ; String s = new String ( cArray ) ; byte [ ] bArray = s . getBytes ( encoding ) ; isInEncoding = inEncoding ( high , bArray ) ; } catch ( Exception e ) { isInEncoding = false ; } return isInEncoding ; }
this is heart of the code that determines if a given high / low surrogate pair forms a character that is in the given encoding . this method is probably expensive , and the answer should be cached . < p > this method is not a public api , and should only be used internally within the serializer .
