Example usage for java.net URLEncoder encode

List of usage examples for java.net URLEncoder encode

Introduction

In this page you can find the example usage for java.net URLEncoder encode.

Prototype

public static String encode(String s, Charset charset) 

Source Link

Document

Translates a string into application/x-www-form-urlencoded format using a specific java.nio.charset.Charset Charset .

Usage

From source file:Main.java

public static String utf8Encode(String str) {
    if (!isEmpty(str) && str.getBytes().length != str.length()) {
        try {/*w ww  . j ava2  s.c  om*/
            return URLEncoder.encode(str, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UnsupportedEncodingException occurred. ", e);
        }
    }
    return str;
}

From source file:Main.java

public static String encodeUnicodeString(String source) {
    try {/*from  w w  w.  ja va2 s .co  m*/
        source = URLEncoder.encode(source, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    }
    return source;
}

From source file:Main.java

public static String urlEncode(String text) {
    try {//w  ww.j a  v  a 2  s  .  c o  m
        text = URLEncoder.encode(text, "UTF-8");
    } catch (Exception ex) {
        log(ex);
    }

    return text;
}

From source file:Main.java

public static final String urlEncode(String url) {
    try {//w w  w  .  jav  a2 s. c  o m
        return URLEncoder.encode(url, charset.toString());
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return url;
}

From source file:Main.java

public static String urlEncode(String msg) {
    if (TextUtils.isEmpty(msg)) {
        return null;
    }/* ww  w  .j a v a2 s. c om*/
    try {
        return URLEncoder.encode(msg, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

private static String encode(String input) {
    if (input == null) {
        return "";
    }/*from   w  w w.  jav a  2 s.  c o  m*/

    try {
        return URLEncoder.encode(input, "utf-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return input;
}

From source file:Main.java

public static String urlEncode(String input, String charset) {
    try {/*from  ww  w . j  a  va2  s.c o  m*/
        return URLEncoder.encode(input, charset);
    } catch (UnsupportedEncodingException e) {
        return input;
    }
}

From source file:Main.java

public static String getFilePath(File dirPath, String fileName) {
    try {//from   w  w w  .j  a  v a 2 s.  c o m
        String filePath = dirPath.getAbsolutePath() + File.separator
                + URLEncoder.encode(fileName.replace("*", ""), "UTF-8");
        return filePath;
    } catch (final UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return null;

}

From source file:Main.java

private static String urlEncode(String str) {
    try {//from w  ww.j  ava  2 s  .c o  m
        //return URLEncoder.encode(str, ENCODE).replace("%2F", "/"); by wmh
        return URLEncoder.encode(str, ENCODE).replace("%2F", "/").replace("+", " ");
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}

From source file:Main.java

public static String toURLEncoded(String paramString) {
    if (paramString == null || paramString.equals("")) {
        return "";
    }/*from   w w w. j ava  2  s .  c  o  m*/
    try {
        String str = new String(paramString.getBytes(), "UTF-8");
        str = URLEncoder.encode(str, "UTF-8");
        return str;
    } catch (Exception localException) {
        //            Log.i("--","toURLEncoded error:"+paramString, localException);  
    }

    return "";
}