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:com.tencent.wetest.common.util.DeviceUtil.java

public static String getCpuMaxFreq() {
    String result = "--";
    double cpuMaxFreq = 0;
    try {/*from  w  w w  .  j a v  a  2s.  c o  m*/
        BufferedReader br = new BufferedReader(
                new FileReader("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"));
        String text = "";
        while ((text = br.readLine()) != null) {
            text = text.trim();
            if (!"".equals(text.trim())) {
                cpuMaxFreq = Double.parseDouble(text.trim()) / (1000 * 1000);
                BigDecimal bg = new BigDecimal(cpuMaxFreq).setScale(1, RoundingMode.UP);

                result = "" + bg.doubleValue();

            }
            break;
        }
        br.close();
        br = null;

    } catch (Exception e) {

        Logger.error("getCpuMaxFreq Exception:" + e.toString());

    }

    return result;
}

From source file:com.tencent.wetest.common.util.DeviceUtil.java

/**
 * ??/*from w w w  .j a  v a2s .  co  m*/
 * @param ctx 
 * @return ?,??MB
 */

public static String getTotalMemory(Context ctx) {

    String str1 = "/proc/meminfo";// ?
    String str2;
    String[] arrayOfString;
    long initial_memory = 0;

    try {

        FileReader localFileReader = new FileReader(str1);
        BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);
        str2 = localBufferedReader.readLine();// ?meminfo?

        arrayOfString = str2.split("\\s+");

        initial_memory = Integer.valueOf(arrayOfString[1]).intValue() / 1024;
        localBufferedReader.close();

    } catch (Exception e) {

        Logger.error("getTotalMemory Exception : " + e.toString());
    }

    return String.valueOf(initial_memory);
}

From source file:models.Template.java

public static String upload(String name, String description, File template, String userRegistered,
        Boolean isHidden) {//from w  w w . j a  va  2s.co m
    try {
        FileStringReader reader = new FileStringReader(template);
        String text = reader.read();

        if (!Helper.isUtf8(text)) {
            return "File must be in Plaintext (UTF 8).";
        }

        String author = userRegistered;

        Date now = new Date();
        Template temp = new Template(name, template.getName(), author, now, description, 4);
        temp.userRegistered = userRegistered;
        temp.isHidden = isHidden;
        temp.save();

        int dotPos = template.getName().lastIndexOf(".");
        String newName;
        String extension = null;

        if (dotPos != -1) {
            extension = template.getName().substring(dotPos);
            newName = temp.id + "_" + name + extension;
        } else {
            newName = temp.id + "_" + name;
        }

        File copy_to = new File(Play.applicationPath.getAbsolutePath() + "/public/templates/" + newName);

        //System.out.println(copy_to.getAbsolutePath());
        Helper.copy(template, copy_to);

        temp.filename_ = newName;
        temp.calculateForm();
        temp.save();

        Helper helper = new Helper();
        if (!extension.equals(".tex")) {
            helper.templateToImage(temp);
        } else {
            Substitution sub = new Substitution(temp.textFile);
            Map map = new HashMap(temp.templates_);
            Iterator it = map.keySet().iterator();

            while (it.hasNext()) {
                String key = (String) it.next();
                map.put(key, key);
            }
            sub.replace(map);
            File replaced_file = new File(
                    Play.applicationPath.getAbsolutePath() + "/public/tmp/" + temp.filename_);
            File destination = new File(replaced_file.getParent());
            FileStringWriter writer = new FileStringWriter(replaced_file);

            writer.write(sub.getText());

            helper.texToPdf(replaced_file, destination);

            String[] source_name = temp.filename_.split(".tex");

            File source = new File(destination + "/" + source_name[0] + ".pdf");
            destination = new File(
                    Play.applicationPath.getAbsolutePath() + "/template/" + source_name[0] + ".pdf.jpg");

            helper.pdfToImage(source, destination);

        }

        return null;
    } catch (Exception e) {
        System.out.println(e.toString());
        return e.toString();
    }
}

From source file:gdt.data.grain.Locator.java

/**
   * Convert properties into the locator string.
   * @param props properties //from   w ww  .ja  v a2  s  .  c o  m
* @return locator string.   
   */
public static String toString(Properties props) {
    if (props == null)
        return null;
    try {
        StringBuffer sb = new StringBuffer();
        Enumeration<?> keys = props.keys();
        if (keys == null)
            return null;
        String name$;
        String value$;
        while (keys.hasMoreElements()) {
            name$ = (String) keys.nextElement();
            value$ = props.getProperty(name$);
            if (value$ != null)
                sb.append(name$ + VALUE_DELIMITER + value$ + NAME_DELIMITER);
        }
        String locator$ = sb.toString();
        locator$.substring(0, locator$.length() - NAME_DELIMITER.length());
        return sb.toString();
    } catch (Exception e) {
        Logger.getLogger(Locator.class.getName()).severe(":compress:" + e.toString());
        return null;
    }
}

From source file:edu.usc.polar.CoreNLP.java

public static void StanfordCoreNLP(String doc, String args[]) {
    try {// w w  w  .  jav  a2s .  c o  m
        String text;
        AutoDetectParser parser = new AutoDetectParser();
        BodyContentHandler handler = new BodyContentHandler();
        Metadata metadata = new Metadata();

        if (args.length > 0) {
            serializedClassifier = args[0];
        }

        if (args.length > 1) {
            String fileContents = IOUtils.slurpFile(args[1]);
            List<List<CoreLabel>> out = classifier.classify(fileContents);
            for (List<CoreLabel> sentence : out) {
                for (CoreLabel word : sentence) {
                    System.out
                            .print(word.word() + '/' + word.get(CoreAnnotations.AnswerAnnotation.class) + ' ');
                }
                System.out.println();
            }

            out = classifier.classifyFile(args[1]);
            for (List<CoreLabel> sentence : out) {
                for (CoreLabel word : sentence) {
                    System.out
                            .print(word.word() + '/' + word.get(CoreAnnotations.AnswerAnnotation.class) + ' ');
                }
                System.out.println();
            }

        } else {

            InputStream stream = new FileInputStream(doc);
            //ParsingExample.class.getResourceAsStream(doc) ;
            //   System.out.println(stream.toString());
            parser.parse(stream, handler, metadata);
            // return handler.toString();
            text = handler.toString();
            String metaValue = metadata.toString();
            // System.out.println("Desc:: "+metadata.get("description"));

            String[] example = new String[1];
            example[0] = text;
            String name = doc.replace("C:\\Users\\Snehal\\Documents\\TREC-Data\\Data", "polar.usc.edu")
                    .replace("\\", ".");
            List<Triple<String, Integer, Integer>> list = classifier.classifyToCharacterOffsets(text);
            JSONObject jsonObj = new JSONObject();
            jsonObj.put("DOI", name);
            jsonObj.put("metadata", metaValue.replaceAll("\\s\\s+|\n|\t", " "));
            JSONArray tempArray = new JSONArray();
            JSONObject tempObj = new JSONObject();
            for (Triple<String, Integer, Integer> item : list) {
                //          String jsonOut="{ DOI:"+name+"  ,"
                //                + ""+item.first() + "\": \"" + text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t"," ")+"\""
                //                + "\"metadata\":\""+metaValue+"\""
                //                + "}";
                // System.out.println(jsonOut);
                tempObj.put(item.first(),
                        text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t", " "));
            }
            tempArray.add(tempObj);
            jsonObj.put("NER", tempArray);
            jsonArray.add(jsonObj);
        }
        // System.out.println("---");

    } catch (Exception e) {
        System.out.println("ERROR : CoreNLP" + "|File Name"
                + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString());
    }
}

From source file:com.tvs.signaltracker.Utils.java

public static JSONObject getODataJSONfromURL(String url) {
    if (!(url == "")) {
        //initialize
        InputStream is = null;// w w  w. j av  a2  s.c o  m
        String result = "";
        JSONObject jArray = null;
        String error = "";
        //http post
        try {
            HttpClient httpclient = getNewHttpClient();
            HttpGet httpget = new HttpGet(url);
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();

        } catch (Exception e) {
            Log.e("SignalTracker::getJSONfromURL", "Error in http connection " + e.toString());
            error = e.toString();
        }

        //convert response to string
        try {
            if (error == null || error == "") {
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                is.close();
                result = sb.toString();
            } else {
                result = "{result:'" + error + "'}";
            }
        } catch (Exception e) {
            Log.e("getJSONfromURL", "Error converting result " + e.toString());
        }
        //try parse the string to a JSON object
        try {
            result = TheUpCrypter.DecodeOData(result);
            jArray = new JSONObject(result);
        } catch (Exception e) {
            Log.e("SignalTracker::getJSONfromURL", "Error parsing data " + e.toString());
            Log.e("SignalTracker::getJSONfromURL", "Site output: " + result);
            Log.e("SignalTracker::getJSONfromURL", "URL: " + url);
        }
        return jArray;
    } else {
        return null;
    }
}

From source file:com.tvs.signaltracker.Utils.java

public static JSONObject getJSONfromURL(String url) {
    if (!(url == "")) {
        //initialize
        InputStream is = null;/*from w ww  . j a  v a 2s  .  co  m*/
        String result = "";
        JSONObject jArray = null;
        String error = "";
        //http post
        try {
            HttpClient httpclient = getNewHttpClient();
            HttpGet httpget = new HttpGet(url);
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();

        } catch (Exception e) {
            Log.e("SignalTracker::getJSONfromURL", "Error in http connection " + e.toString());
            error = e.toString();
        }

        //convert response to string
        try {
            if (error == null || error == "") {
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                is.close();
                result = sb.toString();
            } else {
                result = "{result:'" + error + "'}";
            }
        } catch (Exception e) {
            Log.e("getJSONfromURL", "Error converting result " + e.toString());
        }

        //try parse the string to a JSON object
        try {
            jArray = new JSONObject(result);
        } catch (JSONException e) {
            Log.e("SignalTracker::getJSONfromURL", "Error parsing data " + e.toString());
            Log.e("SignalTracker::getJSONfromURL", "Site output: " + result);
            Log.e("SignalTracker::getJSONfromURL", "URL: " + url);
        }
        return jArray;
    } else {
        return null;
    }
}

From source file:com.intuit.tank.harness.AmazonUtil.java

public static int getCapacity() {
    int ret = 4000;
    try {/*w  w w .j  av  a 2 s  .co m*/
        String lp = getUserDataAsMap().get(TankConstants.KEY_NUM_USERS_PER_AGENT);
        if (lp != null) {
            ret = Integer.valueOf(lp);
        }
    } catch (Exception e) {
        LOG.warn("Error getting capacity: " + e.toString());
    }
    return ret;
}

From source file:com.addthis.hydra.job.alert.JobAlertUtil.java

private static String testQueryResult(JSONArray array, BundleFilter filter) {
    StringBuilder errorBuilder = new StringBuilder();
    JSONArray headerRow = array.optJSONArray(0);
    String[] header = new String[headerRow.length()];
    for (int i = 0; i < header.length; i++) {
        header[i] = headerRow.optString(i);
    }//from   ww w. j a  v a2s . c  om
    for (int i = 1; i < array.length(); i++) {
        JSONArray row = array.optJSONArray(i);
        Bundle bundle = new ListBundle();
        BundleFormat format = bundle.getFormat();
        for (int j = 0; j < row.length(); j++) {
            bundle.setValue(format.getField(header[j]), ValueFactory.create(row.optString(j)));
        }
        try {
            if (!filter.filter(bundle)) {
                errorBuilder.append("filter failed for row: ").append(i - 1).append(" bundle: ").append(bundle)
                        .append('\n');
                log.trace("Row {} filter result is FAILURE", i - 1);
            } else {
                log.trace("Row {} filter result is SUCCESS", i - 1);
            }
        } catch (Exception ex) {
            log.warn("Error while evaluating row {}", i - 1, ex);
            errorBuilder.append(ex.toString());
        }
    }
    if (errorBuilder.length() > 0) {
        return errorBuilder.toString();
    } else {
        return null;
    }
}

From source file:com.intuit.tank.harness.AmazonUtil.java

/**
 * gets stop behavior form user data.//  www.java2 s  . co  m
 * 
 * @return Stopbehavior
 */
public static StopBehavior getStopBehavior() {
    StopBehavior ret = StopBehavior.END_OF_SCRIPT_GROUP;
    try {
        String sb = getUserDataAsMap().get(TankConstants.KEY_STOP_BEHAVIOR);
        if (sb != null) {
            ret = StopBehavior.valueOf(sb);
        }
    } catch (Exception e) {
        LOG.warn("Error getting StopBehavior: " + e.toString());
    }
    return ret;
}