public static String htmlEscapeHex(String input) {
      if (input == null) {
         return null;
      }
      StringBuilder escaped = new StringBuilder(input.length() * 2);
      for (int i = 0; i < input.length(); i++) {
         char character = input.charAt(i);
         if (characterEntityReferences.isMappedToReference(character)) {
            escaped.append(HtmlCharacterEntityReferences.HEX_REFERENCE_START);
            escaped.append(Integer.toString(character, 16));
            escaped.append(HtmlCharacterEntityReferences.REFERENCE_END);
         }
         else {
            escaped.append(character);
         }
      }
      return escaped.toString();
   }