Example usage for java.io UnsupportedEncodingException toString

List of usage examples for java.io UnsupportedEncodingException toString

Introduction

In this page you can find the example usage for java.io UnsupportedEncodingException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:Main.java

public static String ebcdicToAscii(byte[] e) {
    try {//from  ww w.  ja v a  2 s  . c om
        return new String(ebcdicToAsciiBytes(e, 0, e.length), ENCODING);
    } catch (UnsupportedEncodingException ex) {
        return ex.toString(); // should never happen
    }
}

From source file:Main.java

public static String ebcdicToAscii(byte[] e, int offset, int len) {
    try {//  w w w . j av a  2  s .  c o m
        return new String(ebcdicToAsciiBytes(e, offset, len), ENCODING);
    } catch (UnsupportedEncodingException ex) {
        return ex.toString(); // should never happen
    }
}

From source file:org.anhonesteffort.flock.registration.OwsRegistration.java

protected static String getHrefWithParameters(String href, List<NameValuePair> params) {
    String result = href + "?";
    try {//  ww w. j  a  v  a 2  s. c om

        for (NameValuePair param : params)
            result += param.getName() + "=" + URLEncoder.encode(param.getValue(), HTTP.UTF_8) + "&";

    } catch (UnsupportedEncodingException e) {
        Log.e("OwsRegistrtaion", e.toString());
    }

    return result;
}

From source file:org.verisign.joid.RequestFactory.java

/**
 * Parses a query into a request./*from   ww w .  j ava 2  s. c o m*/
 *
 * @param query the query to parse.
 * @return the parsed request.
 * @throws OpenIdException if the query cannot be parsed into a known
 *  request.
 */
public static Request parse(String query) throws UnsupportedEncodingException, OpenIdException {
    Map map;
    try {
        map = parseQuery(query);
    } catch (UnsupportedEncodingException e) {
        throw new OpenIdException("Error parsing " + query + ": " + e.toString());
    }

    String s = (String) map.get(OPENID_MODE);
    if (ASSOCIATE_MODE.equals(s)) {
        return new AssociationRequest(map, s);
    } else if (CHECKID_IMMEDIATE_MODE.equals(s) || CHECKID_SETUP_MODE.equals(s)) {
        return new AuthenticationRequest(map, s);
    } else if (CHECK_AUTHENTICATION_MODE.equals(s)) {
        return new CheckAuthenticationRequest(map, s);
    } else {
        throw new OpenIdException("Cannot parse request from " + query);
    }
}

From source file:de.nico.asura.tools.JSONParser.java

public static JSONObject getJSONFromUrl(String url) {

    // Make HTTP request
    try {//  ww  w. jav  a2s  .  co m
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();
    }

    catch (UnsupportedEncodingException e) {
        Log.e("UnsupportedEncodingException", e.toString());
    }

    catch (ClientProtocolException e) {
        Log.e("ClientProtocolException", e.toString());
    }

    catch (IOException e) {
        Log.e("IOException", e.toString());
    }

    try {
        InputStreamReader isr = new InputStreamReader(is, "UTF-8");
        BufferedReader reader = new BufferedReader(isr, 8);
        StringBuilder sb = new StringBuilder();
        String line;

        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
    }

    catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    }

    catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // return JSON String
    return jObj;

}

From source file:ru.apertum.qsystem.reports.net.NetUtil.java

public static synchronized HashMap<String, String> getParameters(HttpRequest request) {
    final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
    final HashMap<String, String> res = new HashMap<>();
    final String data;
    if (method.equals("GET")) {
        String[] ss = request.getRequestLine().getUri().split("\\?");
        if (ss.length == 2) {
            try {
                data = URLDecoder.decode(request.getRequestLine().getUri().split("\\?")[1], "utf-8");
            } catch (UnsupportedEncodingException ex) {
                throw new ReportException(ex.toString());
            }//from  w ww . jav  a2 s.  c o  m
        } else {
            data = "";
        }
    } else {
        data = getEntityContent(request);
    }
    String[] ss = data.split("&");
    for (String str : ss) {
        String[] ss1 = str.split("=");
        if (!ss1[0].isEmpty()) {
            res.put(ss1[0], ss1.length == 1 ? "" : ss1[1]);
        }
    }
    return res;
}

From source file:org.apache.activemq.artemis.utils.uri.URISchema.java

public static Map<String, String> parseQuery(String uri, Map<String, String> propertyOverrides)
        throws URISyntaxException {
    try {/*from w ww  . j av  a 2 s  .c o  m*/
        Map<String, String> rc = new HashMap<String, String>();
        if (uri != null && !uri.isEmpty()) {
            String[] parameters = uri.split("&");
            for (int i = 0; i < parameters.length; i++) {
                int p = parameters[i].indexOf("=");
                if (p >= 0) {
                    String name = URLDecoder.decode(parameters[i].substring(0, p), "UTF-8");
                    String value = URLDecoder.decode(parameters[i].substring(p + 1), "UTF-8");
                    rc.put(name, value);
                } else {
                    if (!parameters[i].trim().isEmpty()) {
                        rc.put(parameters[i], null);
                    }
                }
            }
        }

        if (propertyOverrides != null) {
            for (Map.Entry<String, String> entry : propertyOverrides.entrySet()) {
                rc.put(entry.getKey(), entry.getValue());
            }
        }
        return rc;
    } catch (UnsupportedEncodingException e) {
        throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
    }
}

From source file:org.apache.activemq.utils.uri.URISchema.java

public static Map<String, String> parseQuery(String uri, Map<String, String> propertyOverrides)
        throws URISyntaxException {
    try {//from   w  w  w .  j  a  v a2 s  .c o m
        Map<String, String> rc = new HashMap<String, String>();
        if (uri != null && !uri.isEmpty()) {
            String[] parameters = uri.split("&");
            for (int i = 0; i < parameters.length; i++) {
                int p = parameters[i].indexOf("=");
                if (p >= 0) {
                    String name = URLDecoder.decode(parameters[i].substring(0, p), "UTF-8");
                    String value = URLDecoder.decode(parameters[i].substring(p + 1), "UTF-8");
                    rc.put(name, value);
                } else {
                    rc.put(parameters[i], null);
                }
            }
        }

        if (propertyOverrides != null) {
            for (Map.Entry<String, String> entry : propertyOverrides.entrySet()) {
                rc.put(entry.getKey(), entry.getValue());
            }
        }
        return rc;
    } catch (UnsupportedEncodingException e) {
        throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
    }
}

From source file:com.groupme.sdk.util.HttpUtils.java

public static Bundle decodeParams(String query) {
    Bundle params = new Bundle();

    if (query != null && !query.equals("")) {
        String[] parts = query.split("&");

        for (String param : parts) {
            String[] item = param.split("=");

            try {
                params.putString(URLDecoder.decode(item[0], Constants.UTF_8),
                        URLDecoder.decode(item[1], Constants.UTF_8));
            } catch (UnsupportedEncodingException e) {
                Log.e(Constants.LOG_TAG, "Unsupported encoding: " + e.toString());
            }/*from  w  w w. j  a v a 2s  . co  m*/
        }
    }

    return params;
}

From source file:com.groupme.sdk.util.HttpUtils.java

public static String encodeParams(Bundle params) {
    if (params == null || params.isEmpty()) {
        return "";
    }/* w w w  .  j  a va2 s . c  om*/

    StringBuilder sb = new StringBuilder();
    boolean first = true;

    for (String key : params.keySet()) {
        if (first) {
            first = false;
        } else {
            sb.append("&");
        }

        try {
            sb.append(URLEncoder.encode(key, Constants.UTF_8)).append("=")
                    .append(URLEncoder.encode(params.getString(key), Constants.UTF_8));
        } catch (UnsupportedEncodingException e) {
            Log.e(Constants.LOG_TAG, "Unsupported encoding: " + e.toString());
        }
    }

    return sb.toString();
}