Java URL Encode encode(String value, String charset)

Here you can find the source of encode(String value, String charset)

Description

encode

License

Apache License

Declaration

public static String encode(String value, String charset) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

import java.net.URLEncoder;

public class Main {
    public static final String DEFAULT_CHARSET = "UTF-8";

    public static String encode(String value) {
        return encode(value, DEFAULT_CHARSET);
    }/*from  www .  j  a  va 2 s. co  m*/

    public static String encode(String value, String charset) {
        String result = null;
        if (!isEmpty(value)) {
            try {
                result = URLEncoder.encode(value, charset);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return result;
    }

    private static boolean isEmpty(final String str) {
        return str == null || str.length() == 0;
    }
}

Related

  1. encode(String toBeEncoded, String charSet, String defaultReturnValue)
  2. encode(String value)
  3. encode(String value)
  4. encode(String value)
  5. encode(String value)
  6. encode(String value, String encoding)
  7. encodeArray(final String[] val)
  8. encodeForUrl(final String s)
  9. encodeSrcUrl(String fullUri)