Here you can find the source of quote(String str, StringBuffer out)
public static StringBuffer quote(String str, StringBuffer out)
//package com.java2s; public class Main { /**/*w w w . jav a2s .c om*/ */ public static StringBuffer quote(String str, StringBuffer out) { if (out == null) { out = new StringBuffer(); } out.append('"'); int len = str.length(); for (int i = 0; i < len; i++) { char c = str.charAt(i); switch (c) { case '"': case '\\': out.append('\\'); out.append(c); break; case '\r': out.append("\\r"); break; case '\n': out.append("\\n"); break; default: out.append(c); break; } } out.append('"'); return out; } }