code: public static String escapeForJava( String string )
    {
      String result;
      StringBuffer resultBuffer = null;
      for( int i = 0, length = string.length(); i < length; i++ )
      {
        char ch = string.charAt( i );
        String escape = escapeForJava( ch );
        if( escape != null )
        {
          if( resultBuffer == null )
          {
            resultBuffer = new StringBuffer( string );
            resultBuffer.setLength( i );
          }
          resultBuffer.append( escape );
        }
        else if( resultBuffer != null )
        {
          resultBuffer.append( ch );
        }
      }
      result = (resultBuffer != null) ? resultBuffer.toString() : string;
      return result;
    }
docs: Escape any special characters in the string, using the Java escape syntax.
  For example any tabs become \t, newlines become \n etc.
  
  @return the escaped string. Returns the original string unchanged if it
  contains no special characters.