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.example.cmput301.model.WebService.java

/**
 * Erases everything form web service./*from  www  . ja  v  a2 s.  co  m*/
 * @param key Password
 * @return String response
 */
public static String nuke(String key) {
    try {
        //Construct data string
        String data = URLEncoder.encode("action", "UTF8") + "=" + URLEncoder.encode("nuke", "UTF8");
        data += "&" + URLEncoder.encode("key", "UTF8") + "=" + URLEncoder.encode(key, "UTF8");

        // Setup Connection
        HttpURLConnection conn = setupConnections();

        // Send data and get response
        return getHttpResponse(conn, data);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;

}

From source file:aarddict.Volume.java

static String utf8(byte[] signature) {
    try {//  w w w. j a va 2 s.  c o m
        return new String(signature, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:com.example.cmput301.model.WebService.java

/**
 * Gets all tasks from web server./*from  w  w  w . j a va 2s.  c  om*/
 * @return List<Task> of all tasks on web server.
 */
public static List<Task> list() {
    try {
        String dataString = getDataString((JSONObject) null, "list");

        //setup connection
        HttpURLConnection conn = setupConnections();

        //send data and get response
        String httpResponse = getHttpResponse(conn, dataString);

        //convert response to json array
        JSONArray jsonArray = new JSONArray(httpResponse);

        return fromJsonArray(jsonArray);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnsupportedOperationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:eu.thecoder4.gpl.pleftdroid.PleftBroker.java

/**
 * //from  ww w.ja  v a  2 s  . c  o  m
 */
static protected int setAvailability(String avails, int aid, String pserver, String user, String vcode) {
    int SC = HttpStatus.SC_INTERNAL_SERVER_ERROR;
    String aurl = pserver + "/a?id=" + aid + "&u=" + user + "&p=" + vcode;
    HttpClient client = getDefaultClient();

    SC = doAuthnForAppointment(client, aurl);

    HttpPost request = new HttpPost(pserver + REQ_SET_AVAILABILITY);

    List<NameValuePair> postParameters = new ArrayList<NameValuePair>(2);
    postParameters.add(new BasicNameValuePair("a", avails));
    postParameters.add(new BasicNameValuePair("id", Integer.toString(aid)));
    Log.i("PB", "a=" + avails + ",id=" + aid);
    try {
        request.setEntity(new UrlEncodedFormEntity(postParameters));
        Log.i("PB", request.getURI().toString());
        Log.i("PB", request.getEntity().toString());
        HttpResponse response = client.execute(request);
        SC = response.getStatusLine().getStatusCode();
        Log.i("PB sc", " " + SC);
        Log.i("PB", response.toString());

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return SC;
}

From source file:org.opendatakit.common.utils.WebUtils.java

/**
 * Safely encode a string for use as a query parameter.
 * /* w  w  w  . j a  v a 2 s.  c o m*/
 * @param rawString
 * @return encoded string
 */
public static String safeEncode(String rawString) {
    if (rawString == null || rawString.length() == 0) {
        return null;
    }

    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        GZIPOutputStream gzip = new GZIPOutputStream(out);
        gzip.write(rawString.getBytes(CharEncoding.UTF_8));
        gzip.finish();
        gzip.close();
        String candidate = Base64.encodeBase64URLSafeString(out.toByteArray());
        return candidate;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        throw new IllegalArgumentException("Unexpected failure: " + e.toString());
    } catch (IOException e) {
        e.printStackTrace();
        throw new IllegalArgumentException("Unexpected failure: " + e.toString());
    }
}

From source file:edu.jhu.cvrg.waveform.utility.WebServiceUtility.java

/** Generates the URL of the REST call which will return the details of this Ontology Concept.
 * //from  w  ww  .  j av  a2s  . com
 * @param treeNodeID - Node ID returned by the Ontology tree when the concept was selected. e.g ""
 * @param ontID - id of the ontology to search, e.g. "2079"
 * @param apikey - JHU's key to use the bioportal lookup service, e.g. "24e0e602-54e0-11e0-9d7b-005056aa3316"
 * @return -  the REST URL.
 */
public static String getAnnotationRestURL(String treeNodeID, String ontID, String apikey) {

    if (treeNodeID.contains("http://")) {
        try {
            treeNodeID = URLEncoder.encode(treeNodeID, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    String restURL = ServiceProperties.getInstance().getBioportalAPIServerURL() + "/ontologies/" + ontID
            + "/classes/" + treeNodeID + "?apikey=" + apikey;
    return restURL;
}

From source file:org.opendatakit.common.utils.WebUtils.java

/**
 * Decode a safeEncode() string./*from ww  w . j a va  2s.  co  m*/
 * 
 * @param encodedWebsafeString
 * @return rawString
 */
public static String safeDecode(String encodedWebsafeString) {
    if (encodedWebsafeString == null || encodedWebsafeString.length() == 0) {
        return encodedWebsafeString;
    }

    try {
        ByteArrayInputStream in = new ByteArrayInputStream(
                Base64.decodeBase64(encodedWebsafeString.getBytes(CharEncoding.UTF_8)));
        GZIPInputStream gzip = new GZIPInputStream(in);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int ch = gzip.read();
        while (ch >= 0) {
            out.write(ch);
            ch = gzip.read();
        }
        gzip.close();
        out.flush();
        out.close();
        return new String(out.toByteArray(), CharEncoding.UTF_8);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        throw new IllegalArgumentException("Unexpected failure: " + e.toString());
    } catch (IOException e) {
        e.printStackTrace();
        throw new IllegalArgumentException("Unexpected failure: " + e.toString());
    }
}

From source file:com.android.W3T.app.network.NetworkUtil.java

public static String attemptSearch(String op, int range, String[] terms) {
    // Here we may want to check the network status.
    checkNetwork();/* ww  w .ja v a 2 s  .c  o  m*/

    try {
        JSONObject param = new JSONObject();
        param.put("acc", UserProfile.getUsername());
        param.put("opcode", "search");
        param.put("mobile", true);
        JSONObject jsonstr = new JSONObject();
        if (op == METHOD_KEY_SEARCH) {
            // Add your data
            // Add keys if there is any.
            if (terms != null) {
                JSONArray keys = new JSONArray();
                int numTerm = terms.length;
                for (int i = 0; i < numTerm; i++) {
                    keys.put(terms[i]);
                }
                param.put("keys", keys);
            }
            // Calculate the Search Range by last N days
            Calendar c = Calendar.getInstance();
            if (range == -SEVEN_DAYS || range == -FOURTEEN_DAYS) {
                // 7 days or 14 days
                c.add(Calendar.DAY_OF_MONTH, range);
            } else if (range == -ONE_MONTH || range == -THREE_MONTHS) {
                // 1 month or 6 month
                c.add(Calendar.MONTH, range);
            }

            String timeStart = String.valueOf(c.get(Calendar.YEAR));
            timeStart += ("-" + String.valueOf(c.get(Calendar.MONTH) + 1));
            timeStart += ("-" + String.valueOf(c.get(Calendar.DAY_OF_MONTH)));
            Calendar current = Calendar.getInstance();
            current.add(Calendar.DAY_OF_MONTH, 1);
            String timeEnd = String.valueOf(current.get(Calendar.YEAR));
            timeEnd += ("-" + String.valueOf(current.get(Calendar.MONTH) + 1));
            timeEnd += ("-" + String.valueOf(current.get(Calendar.DAY_OF_MONTH)));

            JSONObject timeRange = new JSONObject();
            timeRange.put("start", timeStart);
            timeRange.put("end", timeEnd);
            param.put("timeRange", timeRange);

            jsonstr.put("json", param);
        } else if (op == METHOD_TAG_SEARCH) {

        } else if (op == METHOD_KEY_DATE_SEARCH) {
            if (terms.length > 2) {
                // Add keys if there is any.
                JSONArray keys = new JSONArray();
                int numTerm = terms.length - 2;
                for (int i = 0; i < numTerm; i++) {
                    keys.put(terms[i]);
                }
                param.put("keys", keys);
            } else if (terms.length < 2) {
                System.out.println("Wrong terms: no start or end date.");
                return null;
            }
            JSONObject timeRange = new JSONObject();
            timeRange.put("start", terms[terms.length - 2]);
            timeRange.put("end", terms[terms.length - 1]);
            param.put("timeRange", timeRange);
            jsonstr.put("json", param);
        }
        URL url = new URL(RECEIPT_OP_URL);
        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);

        OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
        // Must put "json=" here for server to decoding the data
        String data = "json=" + jsonstr.toString();
        out.write(data);
        out.flush();
        out.close();

        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        return in.readLine();
        //           String s = in.readLine();
        //           System.out.println(s);
        //           return s;
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:br.org.indt.ndg.common.MD5.java

public static String createMD5(String key) throws NoSuchAlgorithmException {
    MessageDigest messageDigest = java.security.MessageDigest.getInstance("MD5");

    try {/*from   w w w  . j a va  2  s.  c o m*/
        messageDigest.update(key.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    byte[] byteArrayMD5 = messageDigest.digest();

    String surveyFileMD5 = getByteArrayAsString(byteArrayMD5);

    return surveyFileMD5;
}

From source file:com.lvwallpapers.utils.WebServiceUtils.java

public static GalleryM getGallery(int page) {

    GalleryM galleryM = new GalleryM();
    List<PhotoGallery> lstGalleryPhoto = new ArrayList<PhotoGallery>();

    try {//from w w  w. j av  a 2  s. co m

        Log.e("URL DSAHDKJA", getWeb_UrlGallery(page));

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpPost = new HttpGet(getWeb_UrlGallery(page));
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        String result = EntityUtils.toString(httpEntity);
        Log.e("Message", result);
        if (result != null && result.length() > 0) {
            JSONObject jobject = new JSONObject(result);
            String jsonPhotos = jobject.getString("photos");

            JSONObject joPhotos = new JSONObject(jsonPhotos);

            int pageG = joPhotos.getInt("page");
            int pages = joPhotos.getInt("pages");

            galleryM.page = pageG;
            galleryM.pages = pages;

            String photos = joPhotos.getString("photo");

            JSONArray joarray = new JSONArray(photos);

            for (int i = 0; i < joarray.length(); i++) {
                JSONObject jo = joarray.getJSONObject(i);

                PhotoGallery photo = new PhotoGallery();
                String id = jo.getString("id");
                String secret = jo.getString("secret");
                String server = jo.getString("server");
                String farm = jo.getString("farm");
                String url_m = (jo.has("url_m")) ? jo.getString("url_m") : "";
                String url_s = (jo.has("url_s")) ? jo.getString("url_s") : "";
                String url_o = (jo.has("url_o")) ? jo.getString("url_o") : "";
                String url_l = (jo.has("url_l")) ? jo.getString("url_l") : url_o;

                if (url_o.length() == 0 && url_l.length() == 0) {
                    url_l = url_s;
                }

                photo.photoId = id;
                photo.secret = secret;
                photo.server = server;
                photo.farm = farm;
                photo.url_l = url_l;
                photo.url_m = url_m;
                photo.url_s = url_s;

                lstGalleryPhoto.add(photo);
            }

            galleryM.lstPhotoGallery = lstGalleryPhoto;

        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();

    } catch (ClientProtocolException e) {
        e.printStackTrace();

    } catch (IOException e) {
        e.printStackTrace();

    } catch (JSONException e) {
        e.printStackTrace();

    }

    return galleryM;

}