Example usage for java.lang Exception toString

List of usage examples for java.lang Exception toString

Introduction

In this page you can find the example usage for java.lang Exception toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:Main.java

public static byte[] encrypt(byte[] ivBytes, byte[] keyBytes, byte[] textBytes) {
    try {//from w ww  .  j a v a 2s  .c  om
        AlgorithmParameterSpec ivSpec = new IvParameterSpec(ivBytes);
        SecretKeySpec newKey = new SecretKeySpec(keyBytes, "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, newKey, ivSpec);
        return cipher.doFinal(textBytes);
    } catch (Exception e) {
        Log.e(TAG, "Error during encryption: " + e.toString());
        return errorbyte;
    }
}

From source file:Main.java

public static String MD5(String inStr) {
    MessageDigest md5 = null;// w ww  .  j a  va2s.c om
    try {
        md5 = MessageDigest.getInstance("MD5");
    } catch (Exception e) {
        System.out.println(e.toString());
        e.printStackTrace();
        return "";
    }
    char[] charArray = inStr.toCharArray();
    byte[] byteArray = new byte[charArray.length];

    for (int i = 0; i < charArray.length; i++)
        byteArray[i] = (byte) charArray[i];

    byte[] md5Bytes = md5.digest(byteArray);

    StringBuffer hexValue = new StringBuffer();

    for (int i = 0; i < md5Bytes.length; i++) {
        int val = ((int) md5Bytes[i]) & 0xff;
        if (val < 16)
            hexValue.append("0");
        hexValue.append(Integer.toHexString(val));
    }

    return hexValue.toString();
}

From source file:Main.java

public static void toast(Context context, final String msg) {
    try {/* w  w  w .java 2 s . com*/
        Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
        Log.d(TAG, "toast: " + msg);
    } catch (Exception e) {
        Log.d(TAG, "Couldn't display toast: " + msg + " / " + e.toString());
    }
}

From source file:Main.java

/**
 * Get the total hrs logged this pay period.
 *
 * @param page the raw html of the user's timecard page
 * @return A double representing the total hours logged this pay period by the user.
 *//*from ww w.  ja v  a 2  s  . c o  m*/
protected static double getTotalsHrs(String page) {
    double total = 0;

    try {
        Pattern pattern = Pattern.compile("(?i)(<div.*?>)(" + TOTAL_STR + ")(.*?)(</div>)");
        Matcher matcher = pattern.matcher(page);
        if (matcher.find()) {
            String totalStr = matcher.group(3);
            if (!(totalStr == null || totalStr.trim().length() == 0)) {
                total = Double.parseDouble(totalStr);
            }
        }
    } catch (Exception e) {
        Log.w(TAG, e.toString());
    }

    return total;
}

From source file:Main.java

static public String download_json(String url_addr) {
    StringBuilder result = new StringBuilder();
    try {/*from  w w w .j  a  va 2  s .c  o m*/
        URL url = new URL(url_addr);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        if (conn != null) {
            conn.setConnectTimeout(10000);
            conn.setUseCaches(false);
            if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                for (;;) {
                    String line = br.readLine();
                    if (line == null)
                        break;
                    result.append(line + '\n');
                }
                br.close();
            } else {
                conn.disconnect();
                return null;
            }
            conn.disconnect();
        }
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        return null;
    }
    return result.toString();
}

From source file:Main.java

public static MediaMetadataRetriever initMetadataRetriever(String URI) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    if (!URI.contains("http:") && URI.endsWith("mp3")) {
        try {/*from w w  w.  j  av  a  2 s.  c om*/
            retriever.setDataSource(URI);
        } catch (Exception e) {
            Log.d(LOG_TAG, "Failed: " + URI + " " + e.toString());
            e.printStackTrace();
            return null;
        }
    } else {
        return null;
    }
    return retriever;
}

From source file:Main.java

/**
 * Method to send SMS message with a Pending Intent 
 * /* ww w .  j  a  v a2 s  . c o  m*/
 * @param phoneNumber The phone number that the message is to be sent to
 * @param body content of the SMS message
 * @param sentPI Pending intent that receives broadcast of when message is sent (To write the action into the database if sent successfully)
 */
public static void sendSms(String phoneNumber, String body, PendingIntent sentPI) {

    SmsManager sms = SmsManager.getDefault();
    try {
        sms.sendTextMessage(phoneNumber, null, body, sentPI, null);
    } catch (Exception e) {
        Log.d("WipiwayController", e.toString());
    }

}

From source file:Main.java

public static boolean WriteFileFromUrl(String url, String filename) {
    try {// ww w  .j a v a 2s. c  om
        URL fileUrl = new URL(url);
        URLConnection connection = fileUrl.openConnection();
        InputStream inputStream = new BufferedInputStream(fileUrl.openStream(), 10240);
        File cacheFile = new File(filename);
        FileOutputStream outputStream = new FileOutputStream(cacheFile);

        byte buffer[] = new byte[1024];
        int dataSize;
        int loadedSize = 0;
        while ((dataSize = inputStream.read(buffer)) != -1) {
            loadedSize += dataSize;
            outputStream.write(buffer, 0, dataSize);
        }

        outputStream.close();
        return true;
    } catch (Exception e) {
        Log.d("#StorageHelper Error:", e.toString());
        return false;
    }
}

From source file:Main.java

private static ArrayList<String> getNumbers(Context context) {
    ArrayList<String> list = new ArrayList<String>();
    Cursor cursor = null;//from   www  .ja v a2 s.c o m
    try {
        cursor = context.getContentResolver().query(Phone.CONTENT_URI, null, null, null, null);
        int phoneNumberIdx = cursor.getColumnIndex(Phone.NUMBER);
        cursor.moveToFirst();
        do {
            String phoneNumber = cursor.getString(phoneNumberIdx);
            list.add(phoneNumber);
        } while (cursor.moveToNext());
    } catch (Exception e) {
        Log.d(context.getPackageName(), e.toString());
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    return list;
}

From source file:Main.java

/**
 * Method to send SMS message//from www.j  a  v  a  2  s.c  o  m
 * 
 * @param phoneNumber The phone number that the message is to be sent to
 * @param body content of the SMS message
 */
public static void sendSms(String phoneNumber, String body) {

    Log.d("WipiwayUtils", "Sending SMS message - " + body + " ... Phone number - " + phoneNumber);

    SmsManager sms = SmsManager.getDefault();
    try {
        sms.sendTextMessage(phoneNumber, null, body, null, null);
    } catch (Exception e) {
        Log.d("WipiwayController", e.toString());
    }

    // Show in outbox - http://stackoverflow.com/a/3873328/804503

}