Example usage for java.io UnsupportedEncodingException printStackTrace

List of usage examples for java.io UnsupportedEncodingException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.QuarkLabs.BTCeClientJavaFX.networking.App.java

public void getTradeHistory() {

    try {/* www . j a  v  a2  s . c om*/
        authRequest.makeRequest("TradeHistory", null);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

From source file:lv.semti.morphology.webservice.InflectPhraseResource.java

@Get
public String retrieve() {
    String query = (String) getRequest().getAttributes().get("phrase");
    try {//from  w  ww .  jav a  2 s.co m
        query = URLDecoder.decode(query, "UTF8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    String category = getQuery().getValues("category");

    MorphoServer.analyzer.enableGuessing = true;
    MorphoServer.analyzer.enableVocative = true;
    MorphoServer.analyzer.guessVerbs = false;
    MorphoServer.analyzer.guessParticiples = false;
    MorphoServer.analyzer.guessAdjectives = true;
    MorphoServer.analyzer.guessInflexibleNouns = true;
    MorphoServer.analyzer.enableAllGuesses = true;

    //MorphoServer.analyzer.describe(new PrintWriter(System.err));

    JSONObject oInflections = new JSONObject();
    Expression e = new Expression(query, category, true); // Pieemam, ka klients padod pamatformu
    //e.describe(new PrintWriter(System.err)); // ko tad tageris im ir sadom?jis
    Map<String, String> inflections = e.getInflections();
    for (String i_case : inflections.keySet()) {
        oInflections.put(i_case, inflections.get(i_case).replaceAll("'", "''"));
    }
    if (e.category == Category.hum) {
        if (e.gender == Gender.masculine)
            oInflections.put(AttributeNames.i_Gender, AttributeNames.v_Masculine);
        if (e.gender == Gender.feminine)
            oInflections.put(AttributeNames.i_Gender, AttributeNames.v_Feminine);
    }

    MorphoServer.analyzer.defaultSettings();
    return oInflections.toJSONString();
}

From source file:edu.umass.cs.gigapaxos.paxospackets.ProposalPacket.java

@Override
public byte[] toBytes() {
    try {/*from  ww  w. jav  a  2s  .  com*/
        byte[] bytes = this.toString().getBytes(CHARSET);
        return bytes;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:cn.vlabs.clb.server.ui.frameservice.pdf.handler.GetPdfContentHandler.java

private void writePdfContentToResponse(GridFSDBFile dbfile, HttpServletRequest request,
        HttpServletResponse response) {/*from   w  ww  .  j av a  2 s.c  om*/
    OutputStream os = null;
    try {
        response.setContentLength((int) dbfile.getLength());
        response.setContentType("application/x-download");
        String filename = dbfile.getFilename();
        String headerValue = ResponseHeaderUtils.buildResponseHeader(request, filename, true);
        response.setHeader("Content-Disposition", headerValue);
        response.setHeader("Content-Length", dbfile.getLength() + "");
        os = response.getOutputStream();
        dbfile.writeTo(os);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (os != null) {
            IOUtils.closeQuietly(os);
        }
    }
}

From source file:de.chaosdorf.meteroid.longrunningio.LongRunningIOPost.java

@Override
protected String doInBackground(Void... params) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    HttpPost httpPost = new HttpPost(url);
    try {/*from   ww  w  . j  a  va2s .  co  m*/
        httpPost.setEntity(new UrlEncodedFormEntity(postData));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return null;
    }
    try {
        HttpResponse response = httpClient.execute(httpPost, localContext);
        int code = response.getStatusLine().getStatusCode();
        if (code >= 400 && code <= 599) {
            callback.displayErrorMessage(id, response.getStatusLine().getReasonPhrase());
            return null;
        }
        HttpEntity entity = response.getEntity();
        return EntityUtils.toString(entity, HTTP.UTF_8);
    } catch (Exception e) {
        callback.displayErrorMessage(id, e.getLocalizedMessage());
        return null;
    }
}

From source file:com.likethecolor.alchemy.api.params.Params.java

protected String encode(final String value) {
    String encodedValue = "";
    if (StringUtils.isBlank(value)) {
        return encodedValue;
    }/*from  w w w.ja v a 2s . co  m*/

    try {
        encodedValue = URLEncoder.encode(value, Constants.DEFAULT_ENCODING);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return encodedValue;
}

From source file:hoahong.facebook.messenger.fbclient.MMConnector.java

public AvatarFbReponseData sendRequest(String id, int size) {
    AvatarFbReponseData responseData = null;
    try {//from  ww  w .j  av  a 2 s .co  m
        Gson gson = new Gson();

        String link = "https://graph.facebook.com/" + id + "/picture?type=normal&redirect=0&width=" + size
                + "&height=" + size;
        // prepare request
        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, TIME_OUT_CONNECTION);
        HttpConnectionParams.setConnectionTimeout(httpParameters, TIME_OUT_SOCKET);
        HttpClient httpClient = new DefaultHttpClient(httpParameters);
        HttpGet postRequest = new HttpGet(link);
        //postRequest.setHeader("Content-Type", "application/json");
        //set session

        // execute request and send response message to MMClientContext
        HttpResponse httpResponse = httpClient.execute(postRequest);
        //System.out.println("response: " + httpResponse);

        /**** handle response for each command ***/
        //extract json Object
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
        // read entire content
        StringBuilder buffer = new StringBuilder();
        String ln;
        while ((ln = reader.readLine()) != null) {
            buffer.append(ln);
        }
        if (buffer.length() == 0) {
            // empty? do something... 
            throw new Exception("Empty response");
        } else {
            responseData = gson.fromJson(buffer.toString(), AvatarFbReponseData.class);
        }

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        // are you sure you have to do this?
        //           httpClient.getConnectionManager().shutdown();
    }
    return responseData;
}

From source file:org.mango.facebooktext.fbclient.MMConnector.java

public AvatarFbReponseData sendRequest(String id) {
    AvatarFbReponseData responseData = null;
    try {// w  w w.  j a v  a 2s. c  om
        Gson gson = new Gson();

        String link = "https://graph.facebook.com/" + id
                + "/picture?type=normal&redirect=0&width=100&height=100";
        // prepare request
        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, TIME_OUT_CONNECTION);
        HttpConnectionParams.setConnectionTimeout(httpParameters, TIME_OUT_SOCKET);
        HttpClient httpClient = new DefaultHttpClient(httpParameters);
        HttpGet postRequest = new HttpGet(link);
        //postRequest.setHeader("Content-Type", "application/json");
        //set session

        // execute request and send response message to MMClientContext
        HttpResponse httpResponse = httpClient.execute(postRequest);
        //System.out.println("response: " + httpResponse);

        /**** handle response for each command ***/
        //extract json Object
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
        // read entire content
        StringBuilder buffer = new StringBuilder();
        String ln;
        while ((ln = reader.readLine()) != null) {
            buffer.append(ln);
        }
        if (buffer.length() == 0) {
            // empty? do something... 
            throw new Exception("Empty response");
        } else {
            responseData = gson.fromJson(buffer.toString(), AvatarFbReponseData.class);
        }

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        // are you sure you have to do this?
        //           httpClient.getConnectionManager().shutdown();
    }
    return responseData;
}

From source file:me.chunsheng.ebooks.hackerearth.api.requests.BaseRequest.java

protected String sendRequest(final String endpoint, final List<NameValuePair> options) {
    try {/*from   w w w .j  a va  2s.  co m*/
        HttpPost httpPost = new HttpPost(endpoint);
        httpPost.setEntity(new UrlEncodedFormEntity(options));
        httpPost.setHeader(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF_8");
        //httpPost.setHeader("Content-type", "application/json");
        HttpClient client = new DefaultHttpClient();
        HttpResponse response = client.execute(httpPost);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        StringBuffer resultBuffer = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null) {
            resultBuffer.append(line);
        }
        return resultBuffer.toString();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.cybrosys.currency.Currency_JSONParsor.java

public JSONObject getJSONformUrl(String url) {
    try {/*w  w w. j a  va2 s  . c  o  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) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;

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

        e.printStackTrace();
    }
    try {
        jobj = new JSONObject(json);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return jobj;
}