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:msuresh.raftdistdb.RaftCluster.java

/**
 * creates the cluster //ww w  . j av a 2s  . c  o  m
 * @param nodesInCluster
 * @param numberOfPartitions
 * @throws InterruptedException 
 */
public static void createCluster(String name, int nodesInCluster, int numberOfPartitions)
        throws InterruptedException, ExecutionException {
    InitPortNumber();
    try {
        JSONObject cluster = new JSONObject();
        cluster.put("name", name);
        cluster.put("countReplicas", nodesInCluster);
        cluster.put("countPartitions", numberOfPartitions);

        for (int i = 0; i < numberOfPartitions; i++)
            cluster.put(i, CreatePartitionCluster(nodesInCluster));
        JSONString.ConvertJSON2File(cluster, Constants.STATE_LOCATION + name + ".info");
        UpdatePortNumber();
        System.out.println("Database " + name + " has been created. ");

    } catch (Exception ex) {
        System.out.println(ex.toString());
    }

}

From source file:com.BibleQuote.utils.FsUtils.java

public static BufferedReader OpenFile(File file, String encoding) {
    Log.i(TAG, "FileUtilities.OpenFile(" + file + ", " + encoding + ")");

    if (!file.exists()) {
        return null;
    }/* w  w w.  ja  va 2  s  .  c o m*/
    BufferedReader bReader = null;
    try {
        InputStreamReader iReader;
        iReader = new InputStreamReader(new FileInputStream(file), encoding);
        bReader = new BufferedReader(iReader);
    } catch (Exception e) {
        Log.i(TAG, e.toString());
        return null;
    }

    return bReader;
}

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

/**
 * create new keystore/*from   w  w  w  .j  av a  2s  . c o  m*/
 */
private static void initializeKeyStore() {
    try {
        keyStore = KeyStore.getInstance("JCEKS");
        //create keystore
        keyStore.load(null, KEYSTORE_PASS);

        //set encryption key
        KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
        keyGenerator.init(128);
        KeyStoreUtil.setSecret(KeyStoreUtil.ENCRYPTION_KEY_ALIAS, keyGenerator.generateKey().getEncoded());

        //write keystore
        FileOutputStream fos = new FileOutputStream(keyStoreFile);
        keyStore.store(fos, KEYSTORE_PASS);
        fos.close();
    } catch (Exception ex) {
        log.error(ex.toString(), ex);
    }
}

From source file:Main.java

public static Map<String, Object> getProperties(Element root) {
    Map<String, Object> map = new HashMap<String, Object>();
    Element[] list = getChildrenByName(root, "property");
    for (int i = 0; i < list.length; i++) {
        String name = list[i].getAttribute("name");
        String type = list[i].getAttribute("type");
        String valueString = getText(list[i]);
        try {//w ww.  jav a 2 s .  com
            Class<?> cls = Class.forName(type);
            Constructor<?> con = cls.getConstructor(new Class<?>[] { String.class

            });
            Object value = con.newInstance(new Object[] { valueString

            });
            map.put(name, value);
        } catch (Exception e) {
            System.err.println("Unable to parse property '" + name +

                    "'='" + valueString + "': " + e.toString());
        }
    }
    return map;
}

From source file:com.drismo.logic.JsonFunctions.java

/**
 * Borrowed from:/*from   w w w  .  j  a  v  a  2 s.  c o m*/
 * http://p-xr.com/android-tutorial-how-to-parse-read-json-data-into-a-android-listview/
 * and slightly modified.
 * @param url the url to get JSON data from
 * @return the JSONObject containing all the info.
 */
public static JSONObject getJSONfromURL(String url) {
    //initialize
    InputStream is = null;
    String result = "";
    JSONObject jArray = null;
    //http post
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    } catch (Exception e) {
        Log.e("log_tag", "Error in http connection " + e.toString());
    }
    //convert response to string
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        result = sb.toString();
    } catch (Exception e) {
        Log.e("log_tag", "Error converting result " + e.toString());
    }
    //try parse the string to a JSON object
    try {
        jArray = new JSONObject(result);
    } catch (JSONException e) {
        Log.e("log_tag", "Error parsing data " + e.toString());
    }
    return jArray;
}

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

/**
 * returns list of output lines/*from   w w w  .j  ava2 s.  co  m*/
 *
 * @param sessionId session id object
 * @return session output list
 */
public static List<SessionOutput> getOutput(Connection con, Long sessionId, User user) {
    List<SessionOutput> outputList = new ArrayList<>();

    UserSessionsOutput userSessionsOutput = userSessionsOutputMap.get(sessionId);
    if (userSessionsOutput != null) {

        for (Integer key : userSessionsOutput.getSessionOutputMap().keySet()) {

            //get output chars and set to output
            try {
                SessionOutput sessionOutput = userSessionsOutput.getSessionOutputMap().get(key);
                if (sessionOutput != null && sessionOutput.getOutput() != null
                        && StringUtils.isNotEmpty(sessionOutput.getOutput())) {

                    outputList.add(sessionOutput);

                    //send to audit logger
                    systemAuditLogger.info(gson.toJson(new AuditWrapper(user, sessionOutput)));

                    if (enableInternalAudit) {
                        SessionAuditDB.insertTerminalLog(con, sessionOutput);
                    }

                    userSessionsOutput.getSessionOutputMap().put(key,
                            new SessionOutput(sessionId, sessionOutput));
                }
            } catch (Exception ex) {
                log.error(ex.toString(), ex);
            }

        }

    }

    return outputList;
}

From source file:com.tethrnet.manage.util.SessionOutputUtil.java

/**
 * returns list of output lines//from   w w w  .  j ava2 s  .  c om
 *
 * @param sessionId session id object
 * @param user user auth object
 * @return session output list
 */
public static List<SessionOutput> getOutput(Connection con, Long sessionId, User user) {
    List<SessionOutput> outputList = new ArrayList<SessionOutput>();

    UserSessionsOutput userSessionsOutput = userSessionsOutputMap.get(sessionId);
    if (userSessionsOutput != null) {

        for (Integer key : userSessionsOutput.getSessionOutputMap().keySet()) {

            //get output chars and set to output
            try {
                SessionOutput sessionOutput = userSessionsOutput.getSessionOutputMap().get(key);
                if (sessionOutput != null && sessionOutput.getOutput() != null) {

                    if (StringUtils.isNotEmpty(sessionOutput.getOutput())) {
                        outputList.add(sessionOutput);

                        //send to audit logger
                        systemAuditLogger.info(gson.toJson(new AuditWrapper(user, sessionOutput)));

                        if (enableInternalAudit) {
                            SessionAuditDB.insertTerminalLog(con, sessionOutput);
                        }

                        userSessionsOutput.getSessionOutputMap().put(key,
                                new SessionOutput(sessionId, sessionOutput));
                    }
                }
            } catch (Exception ex) {
                log.error(ex.toString(), ex);
            }

        }

    }

    return outputList;
}

From source file:neembuu.uploader.external.CheckMajorUpdate.java

/**
 * /*w w w .java2 s. c o  m*/
 * @param str
 * @return the value between <version> and </version> tags from the specified string.
 */
public static float getVersionFromXML(String str) {
    float ver = 0;
    try {
        String start = "<version>";
        String end = "</version>";

        str = str.substring(str.indexOf(start) + start.length());

        str = str.substring(0, str.indexOf(end));
        ver = Float.parseFloat(str);
    } catch (Exception any) {
        NULogger.getLogger().severe(any.toString());
    }
    return ver;
}

From source file:neembuu.uploader.external.CheckMajorUpdate.java

/**
 * /*from w  ww  .  j ava 2s .c  o m*/
 * @param str
 * @return the value between <version> and </version> tags from the specified string.
 */
public static long notificationDate(String str) {
    long time = 0;
    try {
        String start = "<notificationdate>";
        String end = "</notificationdate>";

        str = str.substring(str.indexOf(start) + start.length());

        str = str.substring(0, str.indexOf(end));
        time = Long.parseLong(str);
    } catch (Exception any) {
        NULogger.getLogger().severe(any.toString());
    }
    return time;
}

From source file:com.mycompany.asyncreq.Main.java

public static void ObjToCsv(Root tRoot, String reg) throws IOException {
    List<Tdataset> arForms = tRoot.dataset;
    List<ArrayList<String>> tradeDatas = new ArrayList<ArrayList<String>>();

    int count = 0;
    for (Iterator<Tdataset> j = arForms.iterator(); j.hasNext();) {

        Tdataset tmp = j.next();//from w ww . ja v a  2s .co m
        DateFormat format = new SimpleDateFormat("yyyyMM");
        try {
            Date date = format.parse(tmp.getperiod());
            Ttradedata trade = new Ttradedata(tmp.getrtCode(), tmp.getptCode(), tmp.getrgCode(),
                    tmp.getqtCode(), tmp.getestCode(), date, tmp.getTradeQuantity(), tmp.getNetWeight(),
                    tmp.getTradeValue(), tmp.getcmdCode());

            tradeDatas.add(trade.setString());
            if (tradeDatas.size() % 10000 == 0) {
                writeToCSV(tradeDatas,
                        "data/" + tRoot.dataset.get(0).getptCode() + "_" + count + "_" + reg + ".csv");
                count++;
                tradeDatas.clear();
            }
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }

    writeToCSV(tradeDatas, "data/" + tRoot.dataset.get(0).getptCode() + "_" + reg + ".csv");
    tradeDatas.clear();
    System.out.println("ok!");

}