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:edu.winlab.minijarvis.activity.CameraActivity.java

/**
 * To get camera instance/*from   w ww  .  j  a  va  2s  . com*/
 * @return Camera
 */
private static Camera getCameraInstance() {
    Camera camera = null;
    try {
        camera = Camera.open();

        // Work around for Camera preview issues
        Camera.Parameters params = camera.getParameters();
        params.setPreviewFpsRange(30000, 30000);
        camera.setParameters(params);
    } catch (Exception e) {
        System.out.println(e.toString());
        e.printStackTrace();
    }
    return camera;
}

From source file:com.kellerkindt.scs.utilities.Utilities.java

public static String sha1(String text) throws IOException {
    try {//  w  ww . j  a v a  2s .c  om
        MessageDigest md;
        md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[40];
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
    } catch (Exception e) {
        throw new IOException(e.toString());
    }
}

From source file:com.edgenius.core.util.FileUtil.java

/**
 * Delete all files and sub-directories and given directory itself.
 * @param dir/*  w  w  w.ja v a 2s.  co  m*/
 * @throws IOException 
 * @throws IOException
 */
public static void deleteDir(String dir) throws IOException {
    try {
        FileUtils.cleanDirectory(new File(dir));
        if (!new File(dir).delete())
            new File(dir).deleteOnExit();
    } catch (Exception e) {
        throw new IOException("Delete directory failed in " + e.toString());
    }
}

From source file:com.floragunn.searchguard.util.SecurityUtil.java

public static Serializable decryptAnDeserializeObject(final String string, final SecretKey key) {

    if (string == null) {
        throw new IllegalArgumentException("string must not be null");
    }//from w w w .jav  a  2  s  .  c om

    try {
        final byte[] userr = BaseEncoding.base64().decode(string);
        final ByteArrayInputStream bis = new ByteArrayInputStream(userr);
        final ObjectInputStream in = new ObjectInputStream(bis);
        final SealedObject ud = (SealedObject) in.readObject();
        return (Serializable) ud.getObject(key);
    } catch (final Exception e) {
        log.error(e.toString(), e);
        throw new ElasticsearchException(e.toString());
    }
}

From source file:com.hp.test.framework.Utlis.java

public static Map<String, List<String>> GetCountsrunsWise(ArrayList runs, String path) {
    String string = "";

    Map<String, List<String>> Run_counts = new HashMap<String, List<String>>();
    for (int count = 0; count < runs.size(); count++) {
        Boolean runhasData = false;
        String file = path + "\\" + runs.get(count) + "\\pieChart.js";

        //reading   
        try {//from  ww  w. jav  a2s .c  o  m
            InputStream ips = new FileInputStream(file);
            InputStreamReader ipsr = new InputStreamReader(ips);
            BufferedReader br = new BufferedReader(ipsr);
            String line;
            ArrayList<String> ar = new ArrayList<String>();
            while ((line = br.readLine()) != null) {
                runhasData = true;
                if (line.contains("var data")) {
                    // System.out.println(line);
                    String tem_ar[] = line.split("=");
                    //System.out.println(tem_ar[1]);
                    String temp_ar1[] = tem_ar[1].split(",");
                    String counts = "";
                    for (int i = 0; i < temp_ar1.length; i++) {
                        temp_ar1[i] = temp_ar1[i].replace("[", "");
                        temp_ar1[i] = temp_ar1[i].replace("]", "");
                        temp_ar1[i] = temp_ar1[i].replace("'", "");
                        String temp = temp_ar1[i];
                        ar.add(temp);
                        counts = counts + temp;
                        // System.out.println(temp_ar1[i]);

                    }
                    string += line + "\n";
                    Run_counts.put(runs.get(count).toString(), ar);
                    log.info("counts run wise-->" + runs.get(count) + "***" + ar.toString());
                    break;
                }
            }
            br.close();
        } catch (Exception e) {
            log.error(e.toString());

        }
        if (!runhasData) {
            ArrayList<String> ar = new ArrayList<String>();
            ar.add("Passed");
            ar.add("0");
            ar.add("Failed");
            ar.add("0");
            ar.add("Skipped");
            ar.add("0;");

            Run_counts.put(runs.get(count).toString(), ar);
            log.info("has NO*******  data for " + runs.get(count));
        }
    }
    return Run_counts;

}

From source file:ffx.Main.java

/**
 * Replace the default console handler with our custom FFX handler.
 *//*from   ww  w.ja v  a2  s .co  m*/
private static void startLogging() {
    // Remove all log handlers from the default logger.
    try {
        Logger defaultLogger = LogManager.getLogManager().getLogger("");
        Handler defaultHandlers[] = defaultLogger.getHandlers();
        for (Handler h : defaultHandlers) {
            defaultLogger.removeHandler(h);
        }
    } catch (Exception e) {
        System.err.println(e.toString());
    }

    // Retrieve the log level from the ffx.log system property.
    String logLevel = System.getProperty("ffx.log", "info");
    Level tempLevel;
    try {
        tempLevel = Level.parse(logLevel.toUpperCase());
    } catch (Exception e) {
        tempLevel = Level.INFO;
    }

    level = tempLevel;
    logHandler = new LogHandler();
    logHandler.setLevel(level);
    Logger ffxLogger = Logger.getLogger("ffx");
    ffxLogger.addHandler(logHandler);
    ffxLogger.setLevel(level);
}

From source file:de.cellular.lib.lightlib.backend.LLRequest.java

/**
 * Creates a {@link DefaultHttpClient} object.
 * //from  w  w  w .ja  va 2 s .c  o  m
 * @since 1.0
 * @param _credsProvider
 *            the object contains connect credential info like: User, Pwd, Host etc.
 * @param _ALLOW_ALL_HOSTNAME_VERIFIER_FOR_SSL
 *            true allow all hostname verifier for ssl.
 * @return the {@link DefaultHttpClient} object
 */
public static DefaultHttpClient createHttpClient(CredentialsProvider _credsProvider,
        boolean _ALLOW_ALL_HOSTNAME_VERIFIER_FOR_SSL) {
    // -------------------------------------------------------------------
    // Example for _credsProvider
    //
    // String usr = getUser();
    // String pwd = getPassword();
    // DefaultHttpClient httpclient = new DefaultHttpClient(conMgr, params);
    // CredentialsProvider credsProvider = new BasicCredentialsProvider();
    // credsProvider.setCredentials(new AuthScope(host, port), new UsernamePasswordCredentials(usr, pwd));
    // -------------------------------------------------------------------

    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, TIME_OUT);
    HttpConnectionParams.setSoTimeout(params, TIME_OUT);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(params, true);

    SchemeRegistry schReg = new SchemeRegistry();
    PlainSocketFactory plainSocketFactory = PlainSocketFactory.getSocketFactory();
    SSLSocketFactory sslSocketFactory = null;

    if (_ALLOW_ALL_HOSTNAME_VERIFIER_FOR_SSL) {
        try {
            KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
            trustStore.load(null, null);
            sslSocketFactory = new EasySSLSocketFactory(trustStore);
        } catch (Exception _e) {
            LL.e(_e.toString());
            sslSocketFactory = SSLSocketFactory.getSocketFactory();
        }
        sslSocketFactory
                .setHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    } else {
        sslSocketFactory = SSLSocketFactory.getSocketFactory();
    }
    schReg.register(new Scheme("http", plainSocketFactory, 80));
    schReg.register(new Scheme("https", sslSocketFactory, 443));
    ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);

    DefaultHttpClient httpclient = new DefaultHttpClient(conMgr, params);
    if (_credsProvider != null) {
        httpclient.setCredentialsProvider(_credsProvider);
    }
    return httpclient;
}

From source file:com.floragunn.searchguard.util.SecurityUtil.java

public static String encryptAndSerializeObject(final Serializable object, final SecretKey key) {

    if (object == null) {
        throw new IllegalArgumentException("object must not be null");
    }//  w w w.j av  a2  s.c o m

    try {
        final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        final SealedObject sealedobject = new SealedObject(object, cipher);
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        final ObjectOutputStream out = new ObjectOutputStream(bos);
        out.writeObject(sealedobject);
        final byte[] bytes = bos.toByteArray();
        return BaseEncoding.base64().encode(bytes);
    } catch (final Exception e) {
        log.error(e.toString(), e);
        throw new ElasticsearchException(e.toString());
    }
}

From source file:com.hp.test.framework.Utlis.java

public static void create_tempfile(File SourceFile, File TempFile, String passed_count, String failed_count,
        String skipped_count, String graphType) {
    try {//www .  j ava 2s.  c om
        InputStream ips = new FileInputStream(SourceFile);
        InputStreamReader ipsr = new InputStreamReader(ips);
        BufferedReader br = new BufferedReader(ipsr);

        FileWriter fw = new FileWriter(TempFile);
        BufferedWriter bw = new BufferedWriter(fw);
        PrintWriter fileOut = new PrintWriter(bw);
        //        fileOut.println (string+"\n test of read and write !!"); 
        //  fileOut.close();

        String line;
        String variable = "s";
        if (graphType.equals("line")) {
            variable = "line";

        }
        //ArrayList<String> ar = new ArrayList<String>();
        int i = 0;
        while ((line = br.readLine()) != null) {

            if (i == 0) {
                fileOut.println(line);
                i = i + 1;
                continue;

            }
            if (line.contains("var " + variable)) {
                i = i + 1;
                log.info(line);
                String tem_ar[] = line.split("=");
                log.info(tem_ar[1]);
                String variable1 = "var " + variable + "1 = [" + passed_count + "];";
                String variable2 = "var " + variable + "2 = [" + failed_count + "];";
                String variable3 = "var " + variable + "3 = [" + skipped_count + "];";
                if (i == 2) {
                    fileOut.println(variable1);
                    fileOut.println(variable2);
                    fileOut.println(variable3);
                }
                // string += line + "\n";
                // Run_counts.put(runs.get(count).toString(), ar);

            } else {
                fileOut.println(line);
            }
        }

        fileOut.close();
        br.close();
        log.info("Temp file after replacing counts created successfully--> " + TempFile.getPath());
    } catch (Exception e) {
        System.out.println(e.toString());

    }
}

From source file:com.radicaldynamic.groupinform.activities.AccountDeviceList.java

static public void fetchDeviceList(boolean fetchAnyway) {
    if (Collect.getInstance().getIoService().isSignedIn() || fetchAnyway) {
        if (Collect.Log.INFO)
            Log.i(Collect.LOGTAG, t + "fetching list of devices");
    } else {//from w  ww .ja  va 2  s .co  m
        if (Collect.Log.INFO)
            Log.i(Collect.LOGTAG, t + "not signed in, skipping device list fetch");
        return;
    }

    // Try to ping the service to see if it is "up"
    String deviceListUrl = Collect.getInstance().getInformOnlineState().getServerUrl() + "/device/list";
    String getResult = HttpUtils.getUrlData(deviceListUrl);
    JSONObject jsonDeviceList;

    try {
        jsonDeviceList = (JSONObject) new JSONTokener(getResult).nextValue();

        String result = jsonDeviceList.optString(InformOnlineState.RESULT, InformOnlineState.ERROR);

        if (result.equals(InformOnlineState.OK)) {
            // Write out list of jsonDevices for later retrieval by loadDevicesList() and InformOnlineService.loadDevicesHash()                
            JSONArray jsonDevices = jsonDeviceList.getJSONArray("devices");

            //                // Record the number of seats that this account is licenced for
            //                Collect
            //                    .getInstance()
            //                    .getInformOnlineState()
            //                    .setAccountLicencedSeats(jsonDeviceList.getInt("licencedSeats"));       

            //                // Record the plan type for this account (this is a weird place to do it in but it makes sense to piggyback)
            //                Collect
            //                    .getInstance()
            //                    .getInformOnlineState()
            //                    .setAccountPlan(jsonDeviceList.getString("planType"));
            try {
                // Write out a device list cache file
                FileOutputStream fos = new FileOutputStream(
                        new File(Collect.getInstance().getCacheDir(), FileUtilsExtended.DEVICE_CACHE_FILE));
                fos.write(jsonDevices.toString().getBytes());
                fos.close();
            } catch (Exception e) {
                if (Collect.Log.ERROR)
                    Log.e(Collect.LOGTAG, t + "unable to write device cache: " + e.toString());
                e.printStackTrace();
            }
        } else {
            // There was a problem... handle it!
        }
    } catch (NullPointerException e) {
        // Communication error
        if (Collect.Log.ERROR)
            Log.e(Collect.LOGTAG, t + "no getResult to parse.  Communication error with node.js server?");
        e.printStackTrace();
    } catch (JSONException e) {
        // Parse error (malformed result)
        if (Collect.Log.ERROR)
            Log.e(Collect.LOGTAG, t + "failed to parse getResult " + getResult);
        e.printStackTrace();
    }
}