public static String escape(String string, char escape, boolean isPath)
   {
      try
      {
         BitSet validChars = isPath ? URISaveEx : URISave;
         byte[] bytes = string.getBytes("utf-8");
         StringBuffer out = new StringBuffer(bytes.length);
         for (int i = 0; i < bytes.length; i++)
         {
            int c = bytes[i] & 0xff;
            if (validChars.get(c) && c != escape)
            {
               out.append((char)c);
            }
            else
            {
               out.append(escape);
               out.append(hexTable[(c >> 4) & 0x0f]);
               out.append(hexTable[(c) & 0x0f]);
            }
         }
         return out.toString();
      }
      catch (Exception exc)
      {
         throw new InternalError(exc.toString());
      }
   }
public static String escape ( String string , char escape , boolean isPath ) { try { BitSet validChars = isPath ? URISaveEx : URISave ; byte [ ] bytes = string . getBytes ( "utf-8" ) ; StringBuffer out = new StringBuffer ( bytes . length ) ; for ( int i = 0 ; i < bytes . length ; i ++ ) { int c = bytes [ i ] & 0xff ; if ( validChars . get ( c ) && c != escape ) { out . append ( ( char ) c ) ; } else { out . append ( escape ) ; out . append ( hexTable [ ( c > > 4 ) & 0x0f ] ) ; out . append ( hexTable [ ( c ) & 0x0f ] ) ; } } return out . toString ( ) ; } catch ( Exception exc ) { throw new InternalError ( exc . toString ( ) ) ; } }
Escapes string using escape symbol.

@param string string
@param escape escape symbol
@param isPath if the string is path

@return escaped string