public String convertToJavaString ( String input , boolean useUnicode ) { int length = input . length ( ) ; StringBuilder result = new StringBuilder ( length + 4 ) ; for ( int i = 0 ; i < length ; i ++ ) { escapeAndAppendTo ( input . charAt ( i ) , useUnicode , result ) ; } return result . toString ( ) ; }
Escapes control characters with a preceding backslash . Optionally encodes special chars as unicode escape sequence . The resulting string is safe to be put into a Java string literal between the quotes .