code: public static String percentEncode(String source) throws AuthException {
      try {
        return URLEncoder.encode(source, "UTF-8")
            .replace("+", "%20")
            .replace("*", "%2A")
            .replace("%7E", "~");
      } catch (UnsupportedEncodingException ex) {
        throw new AuthException("cannot encode value '" + source + "'", ex);
      }
    }
docs: Returns an encoded string.
  
  @see <a href="http://tools.ietf.org/html/rfc5849#section-3.6">3.6. Percent Encoding</a>
  
  @param source source string for encoding
  @return encoded string
  @throws AuthException if the named encoding is not supported