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 void deleteBuildPropertyBatched(Context c, String propArgument) {
    StringBuilder propName = new StringBuilder("");
    StringBuilder propValue = new StringBuilder("");
    StringBuilder commandLine = new StringBuilder("");
    boolean isValue = false;
    for (int i = 0; i < propArgument.length(); i++) {
        char ch = propArgument.charAt(i);
        if (ch == '=' && isValue == false) {
            isValue = true;//from w  ww . j  a  va 2s. co m
        } else if (ch == ';') {
            commandLine.append("busybox sed -i \"/" + propName + "=.*/d\" /system/build.prop ; ");

            isValue = false;
            propName = new StringBuilder("");
            propValue = new StringBuilder("");
        } else {
            if (isValue)
                propValue.append(ch);
            else
                propName.append(ch);
        }
    }

    Process p = null;
    try {
        remountSystem(c);

        p = runSuCommandAsync(c, commandLine.toString());
        p.waitFor();
    } catch (Exception d) {
        Log.e("Helper", "Failed to batch delete build.prop. errcode:" + d.toString());
    }
}

From source file:org.logger.event.web.utils.ServerValidationUtils.java

public static void rejectIfAnyException(Errors errors, String errorCode, Exception exception) {
    errors.rejectValue(errorCode, exception.toString());
}

From source file:com.ec2box.manage.util.OTPUtil.java

/**
 * verifies code for OTP secret per time interval
 *
 * @param secret shared secret//www.j  ava  2 s.  c o  m
 * @param token  verification token
 * @param time   time representation to calculate OTP
 * @return true if success
 */
private static boolean verifyToken(String secret, long token, long time) {

    long calculated = -1;

    byte[] key = new Base32().decode(secret);

    SecretKeySpec secretKey = new SecretKeySpec(key, "HmacSHA1");

    try {
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] hash = mac.doFinal(ByteBuffer.allocate(8).putLong(time).array());

        int offset = hash[hash.length - 1] & 0xF;
        for (int i = 0; i < 4; ++i) {
            calculated <<= 8;
            calculated |= (hash[offset + i] & 0xFF);
        }

        calculated &= 0x7FFFFFFF;
        calculated %= 1000000;
    } catch (Exception ex) {
        log.error(ex.toString(), ex);
    }

    return calculated != -1 && calculated == token;

}

From source file:com.keybox.manage.util.OTPUtil.java

/**
 * verifies code for OTP secret per time interval
 *
 * @param secret shared secret/*from   w w w . j  av a 2 s.c  o  m*/
 * @param token  verification token
 * @param time   time representation to calculate OTP
 * @return true if success
 */
private static boolean verifyToken(String secret, long token, long time) {

    long calculated = -1;

    byte[] key = new Base32().decode(secret);

    SecretKeySpec secretKey = new SecretKeySpec(key, "HmacSHA1");

    try {
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] hash = mac.doFinal(ByteBuffer.allocate(8).putLong(time).array());

        int offset = hash[hash.length - 1] & 0xF;
        for (int i = 0; i < 4; ++i) {
            calculated <<= 8;
            calculated |= (hash[offset + i] & 0xFF);
        }

        calculated &= 0x7FFFFFFF;
        calculated %= 1000000;
    } catch (Exception ex) {
        log.error(ex.toString(), ex);
    }

    return (calculated != -1 && calculated == token);

}

From source file:Main.java

public static String getJSONResponseFromURL(String url, Hashtable<String, String> httpGetParams) {
    String json_string = "";
    List<NameValuePair> nvps = buildNameValuePair(httpGetParams);
    url = buildGetUrl(nvps, url);//w w w  .j  a  va2  s . c o  m
    System.out.println("URL==>" + url);
    InputStream is = null;
    try {
        HttpGet httpget = new HttpGet(url);
        HttpResponse response = getThreadSafeClient().execute(httpget);

        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is), 8192);
        String line = null;
        while ((line = reader.readLine()) != null) {
            json_string = json_string + line;
        }
        response.getEntity().consumeContent();
        System.out.println("Json Response==>" + json_string);
    } catch (Exception e) {
        Log.e("log_tag", "Error in http connection" + e.toString());
        return null;
    }
    return json_string;
}

From source file:com.deliciousdroid.client.User.java

/**
 * Creates and returns an instance of the user from the provided JSON data.
 * //ww w.  jav a2s.  co m
 * @param user The JSONObject containing user data
 * @return user The new instance of Delicious user created from the JSON data.
 */
public static User valueOf(JSONObject user) {
    try {
        final String userName = user.getString("user");
        return new User(userName);
    } catch (final Exception ex) {
        Log.i("User", "Error parsing JSON user object" + ex.toString());

    }
    return null;
}

From source file:framework.clss.ConnectionBD.java

/**
 * Open conection with Data Base/*w w w. j a v a2 s  . co  m*/
 *
 */

public static void inicializa_BasicDataSourceFactory() {
    Properties propiedades = new Properties();
    /*
    setMaxActive(): N mx de conexiones que se pueden abrir simultneamente.
    setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms.
    setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando.
    */
    propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver");
    propiedades.setProperty("url", "jdbc:mysql://localhost:3306/mysql");
    propiedades.setProperty("maxActive", "10");
    propiedades.setProperty("maxIdle", "8");
    propiedades.setProperty("minIdle", "0");
    propiedades.setProperty("maxWait", "500");
    propiedades.setProperty("initialSize", "5");
    propiedades.setProperty("defaultAutoCommit", "true");
    propiedades.setProperty("username", "root");
    propiedades.setProperty("password", "");
    propiedades.setProperty("validationQuery", "select 1");
    propiedades.setProperty("validationQueryTimeout", "100");
    propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2");
    propiedades.setProperty("poolPreparedStatements", "true");
    propiedades.setProperty("maxOpenPreparedStatements", "10");

    try {
        //propiedades.load(new FileInputStream("src/config/datasource_config.properties"));
        dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:com.utest.domain.service.util.TrustedSSLUtil.java

private static SSLContext createSSLContext() {
    try {/*from   w w w  . j av  a 2  s .  co m*/
        final SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] { trustAllCerts }, null);
        return context;
    } catch (final Exception e) {
        throw new HttpClientError(e.toString());
    }
}

From source file:com.mindquarry.desktop.I18N.java

protected static Map<String, String> initTranslationMap(String fileBase, String fileSuffix) {
    try {// w  w  w  . ja v a2 s  .c  o m
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        parserFactory.setValidating(false);
        SAXParser parser = parserFactory.newSAXParser();
        XMLReader reader = parser.getXMLReader();
        TranslationMessageParser translationParser = new TranslationMessageParser();
        reader.setContentHandler(translationParser);
        reader.setErrorHandler(translationParser);
        // TODO: use "xx_YY" if available, use "xx" otherwise:
        String transFile = fileBase + Locale.getDefault().getLanguage() + fileSuffix;
        InputStream is = I18N.class.getResourceAsStream(transFile);
        if (is == null) {
            // no translation available for this language
            log.debug("No translation file available for language: " + Locale.getDefault().getLanguage());
            return new HashMap<String, String>();
        }
        log.debug("Loading translation file " + transFile + " from JAR");
        reader.parse(new InputSource(is));
        return translationParser.getMap();
    } catch (Exception e) {
        throw new RuntimeException(e.toString(), e);
    }
}

From source file:Main.java

/**
 * This method provides uniform exception handling functionality
 * @param context//  w  w  w  . ja v  a2  s .c o  m
 * @param e
 * @param errmsg
 */
public static void handleException(Context context, Exception e, String errmsg) {
    Toast.makeText(context, "(e) " + errmsg, Toast.LENGTH_LONG).show();
    Log.e("Yum Exception!", errmsg);
    Log.e("Yum Exception!", e.toString());
}