Example usage for java.io UnsupportedEncodingException getMessage

List of usage examples for java.io UnsupportedEncodingException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.alacoder.lion.common.utils.StringTools.java

public static String urlEncode(String value) {
    if (StringUtils.isEmpty(value)) {
        return "";
    }//from   w  w w.  ja  va 2 s . c  om
    try {
        return URLEncoder.encode(value, LionConstants.DEFAULT_CHARACTER);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.alacoder.lion.common.utils.StringTools.java

public static String urlDecode(String value) {
    if (StringUtils.isBlank(value)) {
        return "";
    }/*from   w  w  w  . ja v  a  2s.c  o  m*/
    try {
        return URLDecoder.decode(value, LionConstants.DEFAULT_CHARACTER);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.weibo.api.motan.util.StringTools.java

public static String urlEncode(String value) {
    if (StringUtils.isEmpty(value)) {
        return "";
    }/*from  ww w.j  a  va2  s  .c  om*/
    try {
        return URLEncoder.encode(value, MotanConstants.DEFAULT_CHARACTER);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.weibo.api.motan.util.StringTools.java

public static String urlDecode(String value) {
    if (StringUtils.isBlank(value)) {
        return "";
    }//from w  w  w . j  a v a 2s.  co  m
    try {
        return URLDecoder.decode(value, MotanConstants.DEFAULT_CHARACTER);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:Main.java

/**
 * Convert string to byte array.//  ww w .jav  a2 s  .c  om
 *
 * @param value Hex string.
 * @return byte array.
 */
public static byte[] hexToBytes(final String value) {
    byte[] buffer = new byte[value.length() / 2];
    int lastValue = -1;
    int index = 0;
    try {
        for (byte ch : value.getBytes("ASCII")) {
            if (ch >= '0' && ch < 'g') {
                if (lastValue == -1) {
                    lastValue = getValue(ch);
                } else if (lastValue != -1) {
                    buffer[index] = (byte) (lastValue << NIBBLE | getValue(ch));
                    lastValue = -1;
                    ++index;
                }
            } else if (lastValue != -1) {
                buffer[index] = getValue(ch);
                lastValue = -1;
                ++index;
            }
        }
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage());
    }
    byte[] tmp = new byte[index];
    System.arraycopy(buffer, 0, tmp, 0, index);
    return tmp;
}

From source file:com.handany.base.generator.FreemarkerUtil.java

public static void outputProcessResult(String outputFile, Template template, Map<String, Object> varMap) {
    String resultString;//ww  w .j a v a2 s  .  co m
    ByteArrayOutputStream baos = null;
    Writer writer = null;

    try {
        baos = new ByteArrayOutputStream();
        writer = new OutputStreamWriter(baos, CHARSET);
        template.process(varMap, writer);
        resultString = new String(baos.toByteArray(), CHARSET);
        FileUtils.writeStringToFile(new File(outputFile), resultString, CHARSET);
    } catch (UnsupportedEncodingException ex) {
        log.error(ex.getMessage(), ex);
    } catch (IOException | TemplateException ex) {
        log.error(ex.getMessage(), ex);
        throw new RuntimeException(ex);
    } finally {
        if (null != baos) {
            try {
                baos.close();
            } catch (IOException ex) {
                log.warn(ex.getMessage(), ex);
            }
        }

        if (null != writer) {
            try {
                writer.close();
            } catch (IOException ex) {
                log.warn(ex.getMessage(), ex);
            }
        }
    }
}

From source file:com.amgems.uwschedule.util.NetUtils.java

/**
 * Builds a HTTP compliant query string from a series of NameValuePairs.
 *///  w ww. j a  v a 2 s  . co  m
public static String toQueryString(List<? extends NameValuePair> postParameterPairs) {
    StringBuilder builder = new StringBuilder();
    boolean firstParameter = true;

    try {
        for (NameValuePair postParameterPair : postParameterPairs) {
            if (!firstParameter)
                builder.append("&");
            firstParameter = false;

            builder.append(URLEncoder.encode(postParameterPair.getName(), NetUtils.CHARSET));
            builder.append("=");
            builder.append(URLEncoder.encode(postParameterPair.getValue(), NetUtils.CHARSET));
        }
    } catch (UnsupportedEncodingException e) {
        Log.e(NetUtils.class.getSimpleName(), e.getMessage());
    }

    return builder.toString();
}

From source file:cn.vlabs.duckling.vwb.ui.servlet.OauthLogoutServlet.java

private static String makeSSOLogoutURL(VWBContext context, String loginUrl) {
    if (!loginUrl.startsWith("http")) {
        String baseURL = context.getBaseURL().replaceAll(context.getBasePath(), "");
        loginUrl = baseURL + loginUrl;/*from w w w . java2s  . c  om*/

    }
    String ssourl = context.getProperty("duckling.umt.logout");
    try {
        return ssourl + "?WebServerURL=" + URLEncoder.encode(loginUrl, "UTF-8") + "&appname="
                + URLEncoder.encode(context.getProperty("duckling.dct.localName", "dct"), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        log.error(e.getMessage());
        return ssourl;
    }
}

From source file:Main.java

public static Map<String, String> splitQuery(String query) {
    Map<String, String> query_pairs = new LinkedHashMap<String, String>();
    try {//  w w  w . j a  v  a2 s.  c om
        String[] pairs = query.split("&");
        for (String pair : pairs) {
            int idx = pair.indexOf("=");
            query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"),
                    URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
        }
    } catch (UnsupportedEncodingException e) {
        query_pairs.put("error", "UnsupportedEncodingException");
        query_pairs.put("error_description", e.getMessage());
    }

    return query_pairs;
}

From source file:com.victorkifer.AndroidTemplates.api.Downloader.java

public static String textDownload(String url, int method, List<NameValuePair> params) throws Exception {
    StringBuilder builder = new StringBuilder();
    try {//w  ww. j a  v a 2  s. com
        HttpResponse httpResponse = null;

        switch (method) {
        case GET:
            httpResponse = makeHttpGetRequest(url, params);
            break;
        case POST:
            httpResponse = makeHttpPostRequest(url, params);
        }

        StatusLine statusLine = httpResponse.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = httpResponse.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content, "utf-8"));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        }
    } catch (UnsupportedEncodingException e) {
        Logger.e(TAG, e.getMessage());
        throw new Exception(AppUtils.getContext().getString(R.string.err_failed_download));
    } catch (ClientProtocolException e) {
        Logger.e(TAG, e.getMessage());
        throw new Exception(AppUtils.getContext().getString(R.string.err_failed_download));
    } catch (IOException e) {
        Logger.e(TAG, e.getMessage());
        throw new Exception(AppUtils.getContext().getString(R.string.err_failed_download));
    }

    Logger.i(TAG, builder.toString());

    return builder.toString();
}