Example usage for java.io UnsupportedEncodingException getClass

List of usage examples for java.io UnsupportedEncodingException getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.discovery.darchrow.net.URIUtil.java

/**
 * iso-8859??.//from  ww  w.j  a  v a2  s.  c  om
 * 
 * @param str
 *            
 * @param bianma
 *            ?
 * @return ?<br>
 *         if isNullOrEmpty(str) return ""
 * @deprecated
 */
@Deprecated
public static String decodeLuanMaISO8859(String str, String bianma) {
    if (Validator.isNullOrEmpty(str)) {
        return "";
    }
    //StringUtil.toBytes(value, charsetName)

    try {
        return new String(str.trim().getBytes(CharsetType.ISO_8859_1), bianma);
    } catch (UnsupportedEncodingException e) {
        LOGGER.error(e.getClass().getName(), e);
    }
    return "";
}

From source file:com.discovery.darchrow.lang.StringUtil.java

/**
 * ??byte.//from  ww w.j  a v  a  2  s .  c  o  m
 * 
 * @param value
 *            
 * @param charsetName
 *            ?? charset ??, utf-8, {@link CharsetType}
 * @return  byte 
 * @see String#getBytes(String)
 * @see CharsetType
 */
public static final byte[] toBytes(String value, String charsetName) {
    try {
        return value.getBytes(charsetName);
    } catch (UnsupportedEncodingException e) {
        LOGGER.error(e.getClass().getName(), e);
    }
    return null;
}

From source file:com.sunchenbin.store.feilong.core.lang.StringUtil.java

/**
 * ??byte.//from w  ww .  j a  v  a 2 s . c  om
 * 
 * @param value
 *            
 * @param charsetName
 *            ?? charset ??, utf-8, {@link CharsetType}
 * @return  byte 
 * @see String#getBytes(String)
 * @see CharsetType
 * @since 1.3.0
 */
public static byte[] getBytes(String value, String charsetName) {
    try {
        return value.getBytes(charsetName);
    } catch (UnsupportedEncodingException e) {
        LOGGER.error(e.getClass().getName(), e);
    }
    return ArrayUtils.EMPTY_BYTE_ARRAY;
}

From source file:com.feilong.commons.core.util.StringUtil.java

/**
 * ??byte./*from   w w  w  .  ja va 2s.c o m*/
 * 
 * @param value
 *            
 * @param charsetName
 *            ?? charset ??, utf-8, {@link CharsetType}
 * @return  byte 
 * @see String#getBytes(String)
 * @see CharsetType
 */
public static final byte[] toBytes(String value, String charsetName) {
    try {
        return value.getBytes(charsetName);
    } catch (UnsupportedEncodingException e) {
        log.error(e.getClass().getName(), e);
    }
    return null;
}

From source file:com.feilong.commons.core.util.StringUtil.java

/**
 *  ? HexString ?gdpglc?.//from w  w  w  .  j a  v a2 s.c o m
 * 
 * @param original
 *            
 * @param charsetName
 *             {@link CharsetType}
 * @return the string
 */
public static final String toHexStringUpperCase(String original, String charsetName) {
    try {
        String hexStringUpperCase = ByteUtil.bytesToHexStringUpperCase(original.getBytes(charsetName));
        log.debug("original:{},hexStringUpperCase:{}", original, hexStringUpperCase);
        return hexStringUpperCase;
    } catch (UnsupportedEncodingException e) {
        log.error(e.getClass().getName(), e);
    }
    return null;
}

From source file:com.feilong.commons.core.util.StringUtil.java

/**
 *  ? HexString./*from   w  w  w  . j  a v a2  s  .  co  m*/
 * 
 * @param hexStringUpperCase
 *            the hex string upper case
 * @param charsetName
 *            
 * @return the string
 */
public static final String toOriginal(String hexStringUpperCase, String charsetName) {
    byte[] hexBytesToBytes = ByteUtil.hexBytesToBytes(hexStringUpperCase.getBytes());
    String original = null;
    try {
        original = new String(hexBytesToBytes, charsetName);
    } catch (UnsupportedEncodingException e) {
        log.error(e.getClass().getName(), e);
    }
    log.debug("hexStringUpperCase:{},original:{}", hexStringUpperCase, original);
    return original;
}

From source file:fi.vm.kapa.identification.testservice.TestServiceAuthenticated.java

private String convertASCIItoUTF8(String value) {
    if (value == null || value.isEmpty())
        return value;
    try {/*from w  w  w .  ja  v  a  2 s  .c  o  m*/
        return new String(value.getBytes("ISO-8859-1"), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        logger.error("Caught exception " + e.getClass().getName() + " while converting string: " + value);
        return null;
    }
}

From source file:org.sakaiproject.shortenedurl.impl.BitlyUrlService.java

/**
 * Helper to URL encode a string//w w w.ja  v a  2s.  c o  m
 * @param s    string to encode
 * @return
 */
private String encode(String s) {
    try {
        return URLEncoder.encode(s, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        log.error(e.getClass() + ":" + e.getMessage());
    }
    return null;
}

From source file:edu.cmu.cylab.starslinger.exchange.WebEngine.java

private byte[] doPost(String uri, byte[] requestBody) throws ExchangeException {
    mCancelable = false;/*from  www  .  j  a  va2s  . c  o  m*/

    // sets up parameters
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "utf-8");
    params.setBooleanParameter("http.protocol.expect-continue", false);

    if (mHttpClient == null) {
        mHttpClient = new CheckedHttpClient(params, mCtx);
    }
    HttpPost httppost = new HttpPost(uri);
    BasicResponseHandler responseHandler = new BasicResponseHandler();
    byte[] reqData = null;
    HttpResponse response = null;
    long startTime = SystemClock.elapsedRealtime();
    int statCode = 0;
    String statMsg = "";
    String error = "";

    try {
        // Execute HTTP Post Request
        httppost.addHeader("Content-Type", "application/octet-stream");
        httppost.setEntity(new ByteArrayEntity(requestBody));
        response = mHttpClient.execute(httppost);
        reqData = responseHandler.handleResponse(response).getBytes("8859_1");

    } catch (UnsupportedEncodingException e) {
        error = e.getLocalizedMessage() + " (" + e.getClass().getSimpleName() + ")";
    } catch (HttpResponseException e) {
        // this subclass of java.io.IOException contains useful data for
        // users, do not swallow, handle properly
        e.printStackTrace();
        statCode = e.getStatusCode();
        statMsg = e.getLocalizedMessage();
        error = (String.format(mCtx.getString(R.string.error_HttpCode), statCode) + ", \'" + statMsg + "\'");
    } catch (java.io.IOException e) {
        // just show a simple Internet connection error, so as not to
        // confuse users
        e.printStackTrace();
        error = mCtx.getString(R.string.error_CorrectYourInternetConnection);
    } catch (RuntimeException e) {
        error = e.getLocalizedMessage() + " (" + e.getClass().getSimpleName() + ")";
    } catch (OutOfMemoryError e) {
        error = mCtx.getString(R.string.error_OutOfMemoryError);
    } finally {
        long msDelta = SystemClock.elapsedRealtime() - startTime;
        if (response != null) {
            StatusLine status = response.getStatusLine();
            if (status != null) {
                statCode = status.getStatusCode();
                statMsg = status.getReasonPhrase();
            }
        }
        Log.d(TAG, uri + ", " + requestBody.length + "b sent, " + (reqData != null ? reqData.length : 0)
                + "b recv, " + statCode + " code, " + msDelta + "ms");
    }

    if (!TextUtils.isEmpty(error) || reqData == null) {
        throw new ExchangeException(error);
    }
    return reqData;
}

From source file:wjhk.jupload2.upload.FileUploadThreadHTTP.java

/**
 * Converts the parameters in GET form to post form
 * //from w ww.  j  a  va  2  s .  co m
 * @param url the <code>URL</code> containing the query parameters
 * @return the parameters in a string in the correct form for a POST request
 * @throws JUploadIOException
 */
private final ByteArrayEncoder getFormParamsForPostRequest(final URL url) throws JUploadIOException {

    // Use a string buffer
    // We'll encode the output stream into UTF-8.
    ByteArrayEncoder bae = new ByteArrayEncoderHTTP(this.uploadPolicy, this.connectionHelper.getBoundary());

    // Get the query string
    String query = url.getQuery();

    if (null != query) {
        // Split this into parameters
        HashMap<String, String> requestParameters = new HashMap<String, String>();
        String[] paramPairs = query.split("&");
        String[] oneParamArray;

        // TODO This could be much more simple !

        // Put the parameters correctly to the Hashmap
        for (String param : paramPairs) {
            if (param.contains("=")) {
                oneParamArray = param.split("=");
                if (oneParamArray.length > 1) {
                    // There is a value for this parameter
                    try {
                        // Correction of URL double encoding bug
                        requestParameters.put(oneParamArray[0], URLDecoder.decode(oneParamArray[1], "UTF-8"));
                    } catch (UnsupportedEncodingException e) {
                        throw new JUploadIOException(e.getClass().getName() + ": " + e.getMessage()
                                + " (when trying to decode " + oneParamArray[1] + ")");
                    }
                } else {
                    // There is no value for this parameter
                    requestParameters.put(oneParamArray[0], "");
                }
            }
        }

        // Now add one multipart segment for each
        Set<Map.Entry<String, String>> entrySet = requestParameters.entrySet();
        Map.Entry<String, String> entry;
        Iterator<Map.Entry<String, String>> i = entrySet.iterator();
        while (i.hasNext()) {
            entry = i.next();
            bae.appendTextProperty(entry.getKey(), entry.getValue(), -1);
        }
    }
    // Return the body content
    bae.close();

    return bae;
}