Here you can find the source of quote(CharSequence str)
public static String quote(CharSequence str)
//package com.java2s; //License from project: Apache License public class Main { public static String quote(CharSequence str) { if (str == null) return "null"; int len = str.length(); StringBuilder buf = new StringBuilder(len + 10); buf.append("\""); for (int i = 0; i < len; i++) { char c = str.charAt(i); switch (c) { case '\n': case '\r': buf.append(c);//from ww w. j av a 2 s. c o m case '\t': buf.append("\\t"); break; case '\"': buf.append("\\\""); break; case '\\': buf.append("\\\\"); break; default: if (c >= ' ' && c < 65000) { // ASCII buf.append(c); } else { // Unicode buf.append(String.format("\\u%04x", (int) c)); } } } buf.append("\""); return buf.toString(); } }