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:com.loopj.android.AsyncHttpResponseHandler.java

/**
 * Fired when a request fails to complete, override to handle in your own code
 * //from w w  w.j a v  a2s. c  o m
 * @param statusCode
 *          return HTTP status code
 * @param headers
 *          return headers, if any
 * @param responseBody
 *          the response body, if any
 * @param error
 *          the underlying cause of the failure
 */
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
    try {
        String response = responseBody == null ? null : new String(responseBody, getCharset());
        onFailure(statusCode, headers, error, response);
    } catch (UnsupportedEncodingException e) {
        Log.e(LOG_TAG, e.toString());
        onFailure(statusCode, headers, e, null);
    }
}

From source file:org.transdroid.daemon.Synology.SynologyAdapter.java

private void createTask(Log log, String uri) throws DaemonException {
    try {//from   ww  w  .j av  a 2s .co m
        authGet(log, "SYNO.DownloadStation.Task", "1", "DownloadStation/task.cgi",
                "&method=create&uri=" + URLEncoder.encode(uri, "UTF-8")).ensureSuccess(log);
    } catch (UnsupportedEncodingException e) {
        // Never happens
        throw new DaemonException(ExceptionType.UnexpectedResponse, e.toString());
    }
}

From source file:org.chromium.media.MediaDrmBridge.java

/**
 * Cancel a key request for a session Id.
 *
 * @param sessionId Crypto session Id.// w w  w.  j  a  v  a 2 s .  com
 */
@CalledByNative
private void cancelKeyRequest(String sessionId) {
    if (mSessionId == null || !mSessionId.equals(sessionId)) {
        return;
    }
    try {
        final byte[] session = sessionId.getBytes("UTF-8");
        mMediaDrm.removeKeys(session);
    } catch (java.io.UnsupportedEncodingException e) {
        Log.e(TAG, "Cannot cancel key request: " + e.toString());
    }
}

From source file:org.chromium.media.MediaDrmBridge.java

/**
 * Release the MediaDrmBridge object./*from   w  ww. j ava 2s.  co  m*/
 */
@CalledByNative
private void release() {
    if (mMediaCrypto != null) {
        mMediaCrypto.release();
        mMediaCrypto = null;
    }
    if (mSessionId != null) {
        try {
            final byte[] session = mSessionId.getBytes("UTF-8");
            mMediaDrm.closeSession(session);
        } catch (java.io.UnsupportedEncodingException e) {
            Log.e(TAG, "Failed to close session: " + e.toString());
        }
        mSessionId = null;
    }
    if (mMediaDrm != null) {
        mMediaDrm.release();
        mMediaDrm = null;
    }
}

From source file:apimanager.ZohoSupportAPIManager.java

public boolean getThreadContent(JSONObject urlParams, String threadId, String fileToWriteResponse) {
    String authToken = (String) urlParams.get(AUTHTOKEN);
    String portal = (String) urlParams.get(PORTAL);
    String department = (String) urlParams.get(DEPARTMENT);

    String baseURL = null;// w  w w.j  a va  2s .  c  om
    try {
        baseURL = "https://support.zoho.com/api/xml/requests/getthreadinfo?authtoken=" + authToken + "&portal="
                + URLEncoder.encode(portal, ENCODETYPE) + "&department="
                + URLEncoder.encode(department, ENCODETYPE) + "&threadid=" + threadId;

        // https://support.zoho.com/api/xml/requests/getthreadinfo?authtoken=46a5e812261b7f237b5fc440866a43fb&portal=medcsupport&department=MDM%20Plus&threadid=255000004261484
    } catch (UnsupportedEncodingException ex) {
        loggerObj.log(Level.INFO, "baseURL is not formed properly" + ex.toString());
    }

    HttpsClient httpsClient = new HttpsClient();
    String result = httpsClient.OpenHTTPSConnection(baseURL);

    boolean isFileWriteSuccess = FileOperations.writeObjectToFile(result, fileToWriteResponse);
    if (!isFileWriteSuccess) {
        loggerObj.log(Level.INFO,
                "Problem in writing the data from Zoho Support to the file: " + fileToWriteResponse);
        return false;
    }

    return true;
}

From source file:com.gaze.webpaser.StackWidgetService.java

private void getDatafromNetwork() {

    new AsyncTask<String, Void, String>() {

        @Override//from   ww  w . j a v  a 2  s. com
        protected void onPreExecute() {

            super.onPreExecute();
            onStartDataLoading();
        }

        @Override
        protected String doInBackground(String... params) {

            ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();

            try {
                // Set up HTTP post

                // HttpClient is more then less deprecated. Need to change
                // to
                // URLConnection
                HttpClient httpClient = new DefaultHttpClient();

                HttpPost httpPost = new HttpPost(listUrl);
                httpPost.setEntity(new UrlEncodedFormEntity(param));
                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();

                Log.i(LOG_TAG, "finish http");

                // Read content & Log
                inputStream = httpEntity.getContent();
            } catch (UnsupportedEncodingException e1) {
                Log.e("UnsupportedEncodingException", e1.toString());
                e1.printStackTrace();
            } catch (ClientProtocolException e2) {
                Log.e("ClientProtocolException", e2.toString());
                e2.printStackTrace();
            } catch (IllegalStateException e3) {
                Log.e("IllegalStateException", e3.toString());
                e3.printStackTrace();
            } catch (IOException e4) {
                Log.e("IOException", e4.toString());
                e4.printStackTrace();
            }
            // Convert response to string using String Builder
            try {
                BufferedReader bReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"),
                        8);
                StringBuilder sBuilder = new StringBuilder();

                String line = null;
                while ((line = bReader.readLine()) != null) {
                    sBuilder.append(line + "\n");
                }

                inputStream.close();
                result = sBuilder.toString();

                Log.i(LOG_TAG, "finish read stream: " + result);
                if (!isStreamTheTargetJson(result)) {
                    result = "";
                    sBuilder.delete(0, sBuilder.length() - 1);
                }

                // parse json string here
                if (!result.isEmpty()) {
                    if (result.startsWith("<html>"))
                        return "";

                    JSONObject titleJson = new JSONObject(result);
                    JSONArray datajson = titleJson.getJSONArray("data");
                    JSONArray urlQueue = datajson.getJSONArray(0);

                    for (int i = 0; i < urlQueue.length(); i++) {
                        JSONObject item = urlQueue.getJSONObject(i);
                        String url = item.getString("link");
                        String introtext = item.getString("introtext");
                        String title = item.getString("title");
                        String images = item.getString("images");
                        String name = item.getString("name");
                        String time = item.getString("publish_up");
                        if (url != null) {
                            // addToQueue(GlobalData.baseUrl+'/'+url);
                            addToList(url, introtext, title, images, name, time);
                        }
                    }
                }

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

            }
            return result;
        }

        @Override
        protected void onPostExecute(String msg) {
            // mDisplay.append(msg + "\n");
            Log.i(LOG_TAG, msg.toString());
            onFinishDataLoading();

        }

    }.execute();
}

From source file:com.ab.http.AsyncHttpResponseHandler.java

/**
 * Fired when a request returns successfully, override to handle in your own code.
 *
 * @param statusCode   the status code of the response
 * @param headers      return headers, if any
 * @param responseBody the body of the HTTP response from the server
 *//*from   w w w  . ja  va2  s .co m*/
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
    try {
        String response = responseBody == null ? null : new String(responseBody, getCharset());
        onSuccess(statusCode, headers, response);
    } catch (UnsupportedEncodingException e) {
        Log.e(LOG_TAG, e.toString());
        onFailure(statusCode, headers, e, null);
    }
}

From source file:fr.gouv.culture.vitam.eml.PstExtract.java

/**
 * Try to extract the following ://from  w w  w .  ja va 2  s . c o  m
 * 
 * Taken from : http://www.significantproperties.org.uk/email-testingreport.html
 * 
 * message-id (Message-ID), References (References), In-Reply-To (In-Reply-To), Attachment
 * subject (Subject), keywords sent-date (Date), Received-date (in Received last date),
 * Trace-field (Received?)
 * 
 * 
 * From (From), To (To), CC (Cc), BCC (Bcc), Content-Type, Content-Transfer-Encoding
 * 
 * ? DomainKey-Signature, Sender, X-Original-Sender, X-Forwarded-Message-Id,
 * 
 * 1) Core property set
 * 
 * The core property set indicates the minimum amount of information that is considered
 * necessary to establish the authenticity and integrity of the email message
 * 
 * Local-part, Domain-part, Relationship, Subject, Trace-field , Message body with no mark-up,
 * Attachments
 * 
 * 2) Message thread scenario
 * 
 * Email is frequently used as a communication method between two or more people. To understand
 * the context in which a message was created it may be necessary to refer to earlier messages.
 * To identify the thread of a discussion, the following fields should be provided, in addition
 * to the core property set:
 * 
 * Local-part, Domain-part, Relationship, Subject, Trace-field, Message body with no mark-up,
 * Attachments, Message-ID, References
 * 
 * 3) Recommended property set
 * 
 * The recommended property set indicates additional information that should be provided in an
 * ideal scenario, if it is present within the email. The list
 * 
 * Local-part, Domain-part, Domain-literal (if present), Relationship, Subject, Trace-field,
 * Attachments, Message-ID, References, Sent-date, Received date, Display name, In-reply-to,
 * Keywords, Message body & associated mark-up (see table 6 for scenarios)
 * 
 * 
 * 
 * @param emlFile
 * @param filename
 * @param argument
 * @param config
 * @return
 */
public static Element extractInfoPst(File pstFile, VitamArgument argument, ConfigLoader config) {
    System.out.println("Start PST: " + (new Date().toString()));
    PstExtract extract = new PstExtract(pstFile.getAbsolutePath(), argument, config);
    PSTFolder folder = null;
    File oldDir = argument.currentOutputDir;
    try {
        PSTFile pstFile2 = new PSTFile(extract.filename);
        System.out.println(pstFile2.getMessageStore().getDisplayName());
        extract.currentRoot = extract.pstRoot;
        extract.currentRoot.addAttribute(EMAIL_FIELDS.filename.name, pstFile.getPath());
        // XXX FIXME multiple output
        if (argument.currentOutputDir == null) {
            if (config.outputDir != null) {
                argument.currentOutputDir = new File(config.outputDir);
            } else {
                argument.currentOutputDir = new File(pstFile.getParentFile().getAbsolutePath());
            }
        }
        if (config.extractFile) {
            extract.curPath = new File(argument.currentOutputDir, "PST_" + pstFile.getName());
            extract.curPath.mkdirs();
        } else if (extractSeparateXmlFolder) {
            extract.curPath = new File(argument.currentOutputDir, "PST_" + pstFile.getName());
            extract.curPath.mkdirs();
        }
        argument.currentOutputDir = extract.curPath;
        folder = pstFile2.getRootFolder();
    } catch (Exception err) {
        err.printStackTrace();
        argument.currentOutputDir = oldDir;
        return null;
    }
    if (extractSeparateXmlFolder) {
        try {
            extract.writer = new XMLWriter(System.out, StaticValues.defaultOutputFormat);
        } catch (UnsupportedEncodingException e1) {
            System.err.println(StaticValues.LBL.error_writer.get() + e1.toString());
        }
    }
    extract.extractInfoFolder(folder);
    DroidHandler.cleanTempFiles();
    extract.currentRoot.addAttribute("nbMsg", config.nbDoc.toString());
    System.out.println("Stop PST: " + (new Date().toString()));
    argument.currentOutputDir = oldDir;
    return extract.pstRoot;
}

From source file:com.ab.http.AsyncHttpResponseHandler.java

/**
 * Fired when a request fails to complete, override to handle in your own code.
 *
 * @param statusCode   return HTTP status code
 * @param headers      return headers, if any
 * @param responseBody the response body, if any
 * @param error        the underlying cause of the failure
 *///ww w. ja  va2  s.  co m
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
    String response = null;
    try {
        if (responseBody != null) {
            response = new String(responseBody, getCharset());
        }
        onFailure(statusCode, headers, error, response);
    } catch (UnsupportedEncodingException e) {
        Log.e(LOG_TAG, e.toString());
        onFailure(statusCode, headers, e, null);
    }
}

From source file:apimanager.ZohoSupportAPIManager.java

private JSONObject getSupportsRecordsAPI(int index, String authtoken, String portal, String dept,
        String columns, String folderToWriteResponse) {

    int fromIndex = ((index - 1) * 200 + 1);
    int toIndex = index * 200;

    String baseURL = null;/*from ww w.  j  av  a 2 s. c o m*/
    try {
        baseURL = "https://support.zoho.com/api/json/requests/getrecords?authtoken=" + authtoken + "&portal="
                + URLEncoder.encode(portal, ENCODETYPE) + "&department=" + URLEncoder.encode(dept, ENCODETYPE)
                + "&selectfields=requests(" + URLEncoder.encode(columns, ENCODETYPE) + ")";
        //String baseURL = "https://support.zoho.com/api/json/requests/getrecords?authtoken=8ecc8d0229b00b83d4c398b19a4282bc&portal=memdmissuemgr&department=MDM%20Issue%20Mgr&selectfields=requests(Status,Module,Created%20At,Functionality,Issue%20Type,OS%20Platform)";
    } catch (UnsupportedEncodingException ex) {
        loggerObj.log(Level.INFO, "baseURL is not formed properly" + ex.toString());
    }

    String fromIndexString = "&fromindex=" + fromIndex;
    String toIndexString = "&toindex=" + toIndex;
    String baseURL_Critirea = baseURL + fromIndexString + toIndexString;
    HttpsClient httpsClient = new HttpsClient();

    loggerObj.log(Level.INFO, "Going to connect to the url: " + baseURL_Critirea);
    System.out.println("Going to connect to the url: " + baseURL_Critirea);

    String result = httpsClient.OpenHTTPSConnection(baseURL_Critirea);
    JSONObject json = null;
    if (!JSONOperations.isErrorJSON(result)) {
        JSONParser parser = new JSONParser();
        try {
            json = (JSONObject) parser.parse(result);
        } catch (ParseException ex) {
            loggerObj.log(Level.INFO,
                    "Problem in parsing the data from Zoho Support. Exception is " + ex.toString());
            return null;
        }
    }
    if (json != null) {
        String FileToWrite = folderToWriteResponse + "/JSONResponse_" + index + ".json";
        boolean isFileWriteSuccess = FileOperations.writeObjectToFile(json, FileToWrite);
        if (!isFileWriteSuccess) {
            loggerObj.log(Level.INFO,
                    "Problem in writing the data from Zoho Support to the file: " + FileToWrite);
        }
    }
    return json;
}