Here you can find the source of percentEncode(String s)
public static String percentEncode(String s)
//package com.java2s; //License from project: Apache License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Main { public static final String ENCODING = "UTF-8"; public static String percentEncode(String s) { if (s == null) { return ""; }/*from w w w . ja v a 2 s. c om*/ try { return URLEncoder.encode(s, ENCODING) // OAuth encodes some characters differently: .replace("+", "%20").replace("*", "%2A") .replace("%7E", "~"); } catch (UnsupportedEncodingException uee) { throw new RuntimeException(uee.getMessage(), uee); } } }