code: public static void quote(Appendable buffer, String input) {
          if (input == null)
              return;
  
          try {
              buffer.append('"');
              for (int i = 0; i < input.length(); ++i) {
                  char c = input.charAt(i);
                  if (c >= 32) {
                      if (c == '"' || c == '\\')
                          buffer.append('\\');
                      buffer.append(c);
                  } else {
                      char escape = escapes[c];
                      if (escape == 0xFFFF) {
                          // Unicode escape
                          buffer.append('\\').append('u').append('0').append('0');
                          if (c < 0x10)
                              buffer.append('0');
                          buffer.append(Integer.toString(c, 16));
                      } else {
                          buffer.append('\\').append(escape);
                      }
                  }
              }
              buffer.append('"');
          } catch (IOException x) {
              throw new RuntimeException(x);
          }
      }
docs: Quote a string into an Appendable. The characters ", \, \n, \r, \t, \f
  and \b are escaped
  
  @param buffer The Appendable
  @param input  The String to quote.