List of usage examples for java.net URLEncoder encode
public static String encode(String s, Charset charset)
From source file:Main.java
public static String encode(String s) { if (s == null) { return ""; }//from w w w. j a va2s .c o m try { return URLEncoder.encode(s, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~") .replace("#", "%23"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:Main.java
public static String encodeStr(String s) { String s1;//from w w w .j a v a 2 s. c o m try { s1 = URLEncoder.encode(s, "UTF-8"); } catch (UnsupportedEncodingException unsupportedencodingexception) { unsupportedencodingexception.printStackTrace(); return null; } catch (Exception exception) { exception.printStackTrace(); return null; } return s1; }
From source file:Main.java
/** * Hides the irritating declared exception. *//*from w w w. ja va2 s . c o m*/ public static String encode(String value) { try { return URLEncoder.encode(value, "utf-8"); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } }
From source file:Main.java
public static String encodeString(String str) { if (str == null) { return null; }//from w w w. j a va2s . c o m try { str = URLEncoder.encode(str, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return str; }
From source file:Main.java
public static String urlEncode(String content, String charsetName) { try {//from w w w . j ava 2 s . c om return URLEncoder.encode(content, charsetName); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String urlEncode(String key) { String result = key;/*from w w w. ja va 2 s . c o m*/ try { result = URLEncoder.encode(key, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return result; }
From source file:Main.java
private static String percentEncode(String s) throws UnsupportedEncodingException { if (s == null) { return ""; }/*from w w w . j av a2s. c o m*/ return URLEncoder.encode(s, "UTF-8") // OAuth encodes some characters differently: .replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); }
From source file:Main.java
public static String encodeString(String toEncode) { String toReturn = ""; try {/*from w ww . jav a 2 s. c om*/ toReturn = URLEncoder.encode(toEncode, "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return toReturn; }
From source file:Main.java
/** * url Encode/* w w w . j a va2 s .c o m*/ * * @param content * @return */ public static String getUrlEncodeString(String content) { String content_ = content; try { content_ = URLEncoder.encode(content, "utf-8").replace("+", "%20"); } catch (Exception e) { content_ = content; } return content_; }
From source file:Main.java
public static String getUrlEncodeString(String key, String value) { String encodeStr = ""; try {//from w w w. j av a 2 s . com encodeStr = URLEncoder.encode(key, "UTF-8") + "=" + URLEncoder.encode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { Log.e("Encode Error", e.getMessage()); } return encodeStr; }