code: protected static String correctToUtf8(String inputString) {
          final StringBuilder result = new StringBuilder(inputString.length());
          final StringCharacterIterator it = new StringCharacterIterator(inputString);
          char ch = it.current();
          boolean modified = false;
          while (ch != CharacterIterator.DONE) {
              if (Character.isISOControl(ch)) {
              	if (ch == '\r' || ch == '\n') {
                      result.append(ch);
              	} else {
  		            modified = true;
  		            result.append(String.format("0x%x", (int) ch));
              	}
              } else {
                  result.append(ch);
              }
              ch = it.next();
          }
  
          if (!modified) return inputString;
  
          return result.toString();
      }
docs: Make sure the string contains valid UTF-8 characters
  @param inputString
  @return escaped String