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

@Deprecated
public static String encode(String s) 

Source Link

Document

Translates a string into x-www-form-urlencoded format.

Usage

From source file:Main.java

/**
 * Encode user and password for URL.<br>
 * <br>/*from   ww w.  j av a2 s. c  o m*/
 * If user is empty you get an empty string.<br>
 * If password is empty you get {@code user@}.
 * 
 * @param user
 *            user
 * @param password
 *            password
 * 
 * @return URL encoded string with format {@code user:password@}
 */
public static String encodeAuth(String user, String password) {
    StringBuilder auth = new StringBuilder();

    if (user != null && !user.trim().equals("")) {
        auth.append(URLEncoder.encode(user));

        if (password != null && !password.trim().equals("")) {
            auth.append(":");
            auth.append(URLEncoder.encode(password));
        }

        auth.append("@");
    }

    return auth.toString();
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static String encodeSubscriptionURL(final String url) {
    if (url.startsWith("feed/")) {
        return "feed/" + URLEncoder.encode(url.substring(5));
    } else {/* w  ww  .  jav  a 2s.com*/
        return url;
    }
}

From source file:Main.java

public static int findProcessId(String command) {
    int procId = -1;

    try {/*from  w w  w. ja v  a2 s. c o  m*/
        procId = findProcessIdWithPidOf(command);

        if (procId == -1)
            procId = findProcessIdWithPS(command);
    } catch (Exception e) {
        try {
            procId = findProcessIdWithPS(command);
        } catch (Exception e2) {
            Log.e(TAG, "Unable to get proc id for command: " + URLEncoder.encode(command), e2);
        }
    }

    return procId;
}

From source file:Main.java

/**
 * Convert to String an url that received as parameter.
 *
 * @param str the str//  w  w w  .  jav a2s  .  com
 * @return String
 */
public static String toStringUrlEncoded(String str) {
    return str == null ? null : URLEncoder.encode(str);
}

From source file:Main.java

/**
 * Convert to String a double value that received as parameter.
 *
 * @param doub the doub//from w  ww.  j  av  a  2 s.  c o m
 * @return String
 */
public static String toStringDouble(Double doub) {
    return doub == null ? null : URLEncoder.encode(Double.toString(doub).replace(',', '.'));
}

From source file:Main.java

/**
 * Convert to String a boolean value that received as parameter.
 *
 * @param bool the bool/*from  ww w  .  j av  a  2 s .  com*/
 * @return String
 */
public static String toStringBoolean(Boolean bool) {
    return bool == null ? null : URLEncoder.encode(Boolean.toString(bool));
}

From source file:Main.java

/**
 * Convert to String an integer value that received as parameter.
 *
 * @param inte the inte/*from w  ww.ja va2  s  .  c o  m*/
 * @return String
 */
public static String toStringInteger(Integer inte) {
    return inte == null ? null : URLEncoder.encode(Integer.toString(inte));
}

From source file:Main.java

private static int findProcessIdCmd(String command) {
    int procId = -1;

    try {/*w w w .  jav a  2  s . c  o  m*/
        procId = findProcessIdWithPidOf(command);

        if (procId == -1)
            procId = findProcessIdWithPS(command);
    } catch (Exception e) {
        try {
            procId = findProcessIdWithPS(command);
        } catch (Exception e2) {
            Log.e(TAG, "Unable to get proc id for command: " + URLEncoder.encode(command), e2);
        }
    }

    return procId;
}

From source file:Main.java

public static int findProcessId(String command) {
    int procId = -1;

    try {//w w  w  .ja va  2s . co m
        procId = findProcessIdWithPidOf(command);

        if (procId == -1) {
            procId = findProcessIdWithPS(command);
        }
    } catch (Exception e) {
        try {
            procId = findProcessIdWithPS(command);
        } catch (Exception e2) {
            Log.e(TAG, "Unable to get proc id for command: " + URLEncoder.encode(command), e2);
        }
    }

    return procId;
}

From source file:Main.java

public static String getResizedUrl(String url, int width, int height) {
    StringBuilder sb = new StringBuilder(
            "https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy");
    sb.append("?container=focus");
    sb.append("&resize_w=").append(width);
    sb.append("&resize_h=").append(height);
    sb.append("&url=").append(URLEncoder.encode(url));
    sb.append("&refresh=31536000");
    return sb.toString();
}