docs: public static String encodeJavaEntities(String input, String encoding) {
  
          StringBuffer result = new StringBuffer(input.length() * 2);
          CharBuffer buffer = CharBuffer.wrap(input.toCharArray());
          Charset charset = Charset.forName(encoding);
          CharsetEncoder encoder = charset.newEncoder();
          for (int i = 0; i < buffer.length(); i++) {
              int c = buffer.get(i);
              if (c < 128) {
                  // first 128 chars are contained in almost every charset
                  result.append((char)c);
                  // this is intended as performance improvement since
                  // the canEncode() operation appears quite CPU heavy
              } else if (encoder.canEncode((char)c)) {
                  // encoder can encode this char
                  result.append((char)c);
              } else {
                  // append Java entity reference
                  result.append("\\u");
                  String hex = Integer.toHexString(c);
                  int pad = 4 - hex.length();
                  for (int p = 0; p < pad; p++) {
                      result.append('0');
                  }
                  result.append(hex);
              }
          }
          return result.toString();
      }