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.sm.message.Header.java

public byte[] toByte() {
    try {/*  w ww  .ja  v a  2 s.  c om*/
        byte[] n = name.getBytes("UTF-8");
        byte[] bytes = new byte[FIRST + n.length];
        int i = 0;
        bytes[i] = release;
        System.arraycopy(ByteBuffer.allocate(8).putLong(version).array(), 0, bytes, i + 1, 8);
        System.arraycopy(ByteBuffer.allocate(8).putLong(nodeId).array(), 0, bytes, i + 9, 8);
        System.arraycopy(n, 0, bytes, i + FIRST, n.length);
        return bytes;
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:org.xbmc.android.jsonrpc.client.AbstractClient.java

/**
 * Synchronously posts the request object to XBMC's JSONRPC API and returns
 * the unserialized response as {@link JSONObject}.
 * /*from   w w w.ja va  2 s  . c o m*/
 * @param entity Request object generated by API class
 * @param errorHandler Error handler in case something goes wrong
 * @return Response as JSONObject
 */
protected JSONObject execute(JSONObject entity, ErrorHandler errorHandler) {

    final HttpClient httpClient = HttpHelper.getHttpClient();
    final HttpPost request = new HttpPost(AudioSyncService.URL);
    InputStream input = null;

    try {
        Log.i(TAG, "POSTING: " + entity.toString());

        request.setEntity(new StringEntity(entity.toString(), "UTF-8"));
        request.addHeader("Content-Type", "application/json");

        final HttpResponse resp = httpClient.execute(request);
        final int status = resp.getStatusLine().getStatusCode();
        if (status != HttpStatus.SC_OK && errorHandler != null) {
            errorHandler.handleError(ErrorHandler.UNEXPECTED_SERVER_RESPONSE,
                    "Unexpected server response " + resp.getStatusLine() + " for " + request.getRequestLine());
        } else {
            input = resp.getEntity().getContent();
            final BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"), 8192);
            final StringBuilder sb = new StringBuilder();
            for (String line = null; (line = reader.readLine()) != null;) {
                sb.append(line).append("\n");
            }
            Log.d(TAG, "RESPONSE: " + sb.toString());

            final JSONTokener tokener = new JSONTokener(sb.toString());
            final JSONObject response = ((JSONObject) tokener.nextValue());
            if (response.has("error") && errorHandler != null) {
                errorHandler.handleError(ErrorHandler.API_ERROR,
                        response.getJSONObject("error").getString("message"));
            } else if (response.has("result")) {
                return response.getJSONObject("result");
            } else {
                if (errorHandler != null) {
                    errorHandler.handleError(ErrorHandler.NO_RESULT_FOUND,
                            "No 'result' element in JSON response.");
                }
                Log.e(TAG, "RESPONSE: " + sb.toString());
            }
        }
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, e.getMessage(), e);
        if (errorHandler != null) {
            errorHandler.handleError(ErrorHandler.UNSUPPORTED_ENCODING, e.getMessage());
        }
    } catch (IllegalStateException e) {
        Log.e(TAG, e.getMessage(), e);
        if (errorHandler != null) {
            errorHandler.handleError(ErrorHandler.ILLEGAL_STATE, e.getMessage());
        }
    } catch (HttpHostConnectException e) {
        Log.e(TAG, e.getMessage(), e);
        if (errorHandler != null) {
            errorHandler.handleError(ErrorHandler.HOST_CONNECTION, e.getMessage());
        }
    } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
        if (errorHandler != null) {
            errorHandler.handleError(ErrorHandler.IO_EXCEPTION, e.getMessage());
        }
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage(), e);
        if (errorHandler != null) {
            errorHandler.handleError(ErrorHandler.JSON_EXCEPTION, e.getMessage());
        }
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
            }
        }
    }
    return null;
}

From source file:com.orange.mmp.bind.JSONClientBinding.java

/**
 *    Sends the request to WebService and return an object built from
 *    JSON response./* w  w  w  .  j  ava2  s .c  o m*/
 *    @return A binding object in a JSONObject, JSONArray or String
 */
public Object getResponse(InputStream postData) throws BindingException {
    StringWriter responseContent = new StringWriter();
    BufferedReader reader = null;
    BufferedWriter writer = null;
    //Get response
    try {
        this.getHttpConnection().init(this.buildURL(), this.timeout);
        if (postData != null)
            this.getHttpConnection().sendData(postData);
        InputStream httpIn = this.getHttpConnection().getData();
        if (httpIn != null) {
            writer = new BufferedWriter(responseContent);
            reader = new BufferedReader(new InputStreamReader(httpIn, Constants.DEFAULT_ENCODING));
            String line = null;
            while ((line = reader.readLine()) != null) {
                writer.write(line);
                writer.newLine();
                writer.flush();
            }
        } else
            return null;

    } catch (UnsupportedEncodingException uee) {
        throw new BindingException("Unsupported encoding from " + this.epr + " : " + uee.getMessage());
    } catch (IOException ioe) {
        throw new BindingException("Failed to get response : " + ioe.getMessage());
    } catch (MMPNetException mne) {
        throw new BindingException("Failed to get response : " + mne.getMessage());
    } finally {
        try {
            if (reader != null)
                reader.close();
            if (writer != null)
                writer.close();
            this.releaseConnection();
        } catch (MMPNetException mne) {
            //Nop, logs in AOP
        } catch (IOException ioe) {
            //Nop, logs in AOP
        }
    }

    //Parse response
    if (responseContent == null)
        throw new BindingException("Failed to parse response : empty result");
    String jsonString = responseContent.toString();
    if (jsonString.length() == 0)
        throw new BindingException("Failed to parse response : empty result");
    try {
        JSONTokener tokener = new JSONTokener(jsonString);
        return tokener.nextValue();
    } catch (JSONException je) {
        throw new BindingException("Failed to parse response : " + je.getMessage());
    }
}

From source file:de.cenote.jasperstarter.Db.java

public JRCsvDataSource getCsvDataSource(Config config) throws JRException {
    JRCsvDataSource ds;/*from ww w . ja v a2s.co m*/
    try {
        ds = new JRCsvDataSource(JRLoader.getInputStream(config.getDataFile()), config.csvCharset);
    } catch (UnsupportedEncodingException ex) {
        throw new IllegalArgumentException("Unknown CSV charset: " + config.csvCharset + ex.getMessage(), ex);
    }

    ds.setUseFirstRowAsHeader(config.getCsvFirstRow());
    if (!config.getCsvFirstRow()) {
        ds.setColumnNames(config.getCsvColumns());
    }

    ds.setRecordDelimiter(StringEscapeUtils.unescapeJava(config.getCsvRecordDel()));
    ds.setFieldDelimiter(config.getCsvFieldDel());

    if (config.isVerbose()) {
        System.out.println("Use first row: " + config.getCsvFirstRow());
        System.out.print("CSV Columns:");
        for (String name : config.getCsvColumns()) {
            System.out.print(" " + name);
        }
        System.out.println("");
        System.out.println("-----------------------");
        System.out.println("Record delimiter literal: " + config.getCsvRecordDel());
        System.out.println("Record delimiter: " + ds.getRecordDelimiter());
        System.out.println("Field delimiter: " + ds.getFieldDelimiter());
        System.out.println("-----------------------");
    }

    return ds;
}

From source file:at.tugraz.ist.akm.webservice.requestprocessor.interceptor.AuthorizationInterceptor.java

private void extractCredentialsFromRequestHeader(Header header, StringBuffer requestUserName,
        StringBuffer requestPassword) {
    String headerValue = header.getValue();
    int idx = headerValue.indexOf(" ");
    if (idx >= 0) {
        String userCredentials;//  w ww.  j a v  a 2  s .  co  m
        try {
            userCredentials = new String(Base64.decode(headerValue.substring(idx + 1), 0), mDefaultEncoding);
            requestUserName.append(getUsernameSubstring(userCredentials));
            requestPassword.append(getPasswordSubstring(userCredentials));
        } catch (UnsupportedEncodingException e) {
            mLog.error("failed to extract string from header: " + e.getMessage());
        }
    }
}

From source file:org.grails.datastore.mapping.redis.engine.RedisPropertyValueIndexer.java

@SuppressWarnings("serial")
private String urlEncode(Object value) {
    try {//from  ww  w . j av  a  2 s .  c  om
        return URLEncoder.encode(value.toString(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new DataAccessException("Cannot encoding Redis key: " + e.getMessage(), e) {
        };
    }
}

From source file:org.wicketstuff.gmap.geocoder.Geocoder.java

/**
 * url-encode a value//from w ww. j ava 2 s . c o m
 *
 * @param value
 * @return
 */
private String urlEncode(final String value) {
    try {
        return URLEncoder.encode(value, "UTF-8");
    } catch (UnsupportedEncodingException ex) {
        throw new RuntimeException(ex.getMessage());
    }
}

From source file:net.duckling.ddl.service.export.impl.ExportAttachSaver.java

public void save(String filename, InputStream in) {
    String newFilename = getNormalFilename(filename);
    int dotIndex = newFilename.lastIndexOf(".");
    dotIndex = (dotIndex <= 0) ? newFilename.length() : dotIndex;
    newFilename = newFilename.substring(0, dotIndex) + "_" + rid + "_" + tid + "_" + LynxConstants.TYPE_FILE
            + newFilename.substring(dotIndex, newFilename.length());
    try {/*  w  ww  .  j  a  v  a2 s .  c  om*/
        newFilename = java.net.URLDecoder.decode(newFilename, "utf8");
        out.putArchiveEntry(new ZipArchiveEntry(path + "/" + newFilename));
        IOUtils.copy(in, out);
        in.close();
        out.closeArchiveEntry();
    } catch (UnsupportedEncodingException e) {
        LOGGER.error("????", e);
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }

}

From source file:net.shopxx.plugin.abcPayment.AbcPaymentPlugin.java

private String generateSign(String message) {
    try {/*ww  w. j  ava  2  s . c o m*/
        PluginConfig pluginConfig = getPluginConfig();
        PrivateKey privateKey = RSAUtils.generatePrivateKey(pluginConfig.getAttribute("key"));
        return Base64.encodeBase64String(RSAUtils.sign("SHA1withRSA", privateKey, message.getBytes("UTF-8")));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:eu.europa.esig.dss.xades.validation.OfflineResolver.java

private String decodeUrl(String documentUri) {
    try {//from w  w  w .j a  v a  2  s  . co  m
        return URLDecoder.decode(documentUri, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        LOG.error("Unable to decode '" + documentUri + "' : " + e.getMessage(), e);
    }
    return documentUri;
}