Here you can find the source of encodeUTF8(String input, boolean keepSpaces)
Parameter | Description |
---|---|
input | Input |
keepSpaces | <code>true</code> if spaces should be preserved, <code>false</code> otherwise |
null
if input was null
public static String encodeUTF8(String input, boolean keepSpaces)
//package com.java2s; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class Main { public static final String UTF_8 = "UTF-8"; /**/* w ww . jav a2 s .c om*/ * Encode input using UTF-8 * * @param input Input * @return Input encoded using UTF-8 or <code>null</code> if input was null */ public static String encodeUTF8(String input) { return encodeUTF8(input, false); } /** * Encod input as UTF-8 while converting %20 (space) to a space * * @param input Input * @param keepSpaces <code>true</code> if spaces should be preserved, <code>false</code> otherwise * @return Input encoded using UTF-8 or <code>null</code> if input was null */ public static String encodeUTF8(String input, boolean keepSpaces) { if (input == null) { return null; } String encodedInput; try { encodedInput = URLEncoder.encode(input, UTF_8); } catch (UnsupportedEncodingException e) { return input; } if (keepSpaces) { encodedInput = encodedInput.replaceAll("[+]", " "); } return encodedInput; } }