List of usage examples for java.lang Exception toString
public String toString()
From source file:com.sec.ose.osi.util.tools.Tools.java
public static String getPrintStackTraceInfoString(Exception e) { String returnStackTraceString = e.toString(); ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(out); e.printStackTrace(printStream);//w w w . j av a 2s . co m returnStackTraceString = out.toString(); return returnStackTraceString; }
From source file:Main.java
public static Document getDocument(String str) { Document doc = null;/*from ww w . j a v a2 s. c o m*/ try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; builder = factory.newDocumentBuilder(); StringReader userdataReader = new StringReader(str); InputSource inputSource = new InputSource(userdataReader); doc = builder.parse(inputSource); } catch (Exception e) { System.out.println(e.toString()); } return doc; }
From source file:aes_encryption.AES_Encryption.java
public static String encrypt(String strToEncrypt) { try {//from w ww . j a v a 2 s .co m Cipher cipher = Cipher.getInstance("AES_Encryption/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); setEncryptedString(Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes("UTF-8")))); } catch (Exception e) { System.out.println("Error while encrypting: " + e.toString()); } return null; }
From source file:Main.java
public static Document getDocument(File file) throws IOException { Document doc = null;// ww w .j a va 2 s .c om BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); ; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; builder = factory.newDocumentBuilder(); InputSource inputSource = new InputSource(br); doc = builder.parse(inputSource); } catch (Exception e) { System.out.println(e.toString()); } finally { br.close(); br = null; } return doc; }
From source file:Main.java
public static Process changeBuildProperty(Context c, String propName, String newValue) { Process p = null;//from ww w . ja va 2 s. c o m try { remountSystem(c); p = runSuCommandAsync(c, "busybox sed -i \"s/" + propName + "=.*/" + propName + "=" + newValue + "/g\" /system/build.prop ; "); p.waitFor(); } catch (Exception d) { Log.e("Helper", "Failed to change build.prop. errcode:" + d.toString()); } return p; }
From source file:Main.java
/** * Return '' or error message if error occurs during URL connection. * /* w w w . j a v a 2s .c o m*/ * @param url The URL to ckeck * @return */ public static String getUrlStatus(String url) { URL u; URLConnection conn; int connectionTimeout = 500; try { u = new URL(url); conn = u.openConnection(); conn.setConnectTimeout(connectionTimeout); // TODO : set proxy if (conn instanceof HttpURLConnection) { HttpURLConnection httpConnection = (HttpURLConnection) conn; httpConnection.setInstanceFollowRedirects(true); httpConnection.connect(); httpConnection.disconnect(); // FIXME : some URL return HTTP200 with an empty reply from server // which trigger SocketException unexpected end of file from server int code = httpConnection.getResponseCode(); if (code == HttpURLConnection.HTTP_OK) { return ""; } else { return "Status: " + code; } } // TODO : Other type of URLConnection } catch (Exception e) { e.printStackTrace(); return e.toString(); } return ""; }
From source file:watchtower.common.automation.JobUtils.java
public static Job fromJson(byte[] jobJson) { try {/* w ww . j av a 2 s. co m*/ String jsonString = StringEscapeUtils.unescapeJava(new String(jobJson, "UTF-8")); return OBJECT_MAPPER.readValue(jsonString, Job.class); } catch (Exception e) { logger.error("Failed to parse job json: {}", e.toString()); } return null; }
From source file:com.cisco.oss.foundation.http.jetty.JettyHttpClientFactory.java
public static HttpClient<HttpRequest, JettyHttpResponse> createHttpClient(String apiName, LoadBalancerStrategy.STRATEGY_TYPE highAvailabilityStrategyType, Configuration configuration, boolean enableLoadBalancing) { ConfigurationFactory.getConfiguration(); try {/*from w w w . ja v a 2 s . c o m*/ HttpClient client = null; if (highAvailabilityStrategyType == null) { client = new JettyHttpClient(apiName, configuration, enableLoadBalancing); } else { client = new JettyHttpClient(apiName, highAvailabilityStrategyType, configuration, enableLoadBalancing); } return client; } catch (Exception e) { throw new ClientException(e.toString(), e); } }
From source file:watchtower.common.event.EventUtils.java
public static Event fromJson(byte[] eventJson) { try {/* w w w . j av a 2 s . c o m*/ String jsonString = StringEscapeUtils.unescapeJava(new String(eventJson, "UTF-8")); return OBJECT_MAPPER.readValue(jsonString, Event.class); } catch (Exception e) { logger.error("Failed to parse event json: {}", e.toString()); } return null; }
From source file:com.jonbanjo.cups.operations.AuthHeader.java
static void makeAuthHeader(HttpRequest request, AuthInfo auth) { if (auth.reason == AuthInfo.AUTH_NOT_SUPPORTED) { return;/*from ww w . j a v a 2 s . c o m*/ } if (auth.username.equals("") || (auth.password.equals(""))) { auth.reason = AuthInfo.AUTH_REQUIRED; return; } UsernamePasswordCredentials creds = new UsernamePasswordCredentials(auth.username, auth.password); if (auth.getType().equals("Basic")) { BasicScheme basicScheme = new BasicScheme(); try { auth.setAuthHeader(basicScheme.authenticate(creds, request)); } catch (Exception e) { System.err.println(e.toString()); auth.reason = AuthInfo.AUTH_BAD; } } else if (auth.getType().equals("Digest")) { try { DigestScheme digestScheme = new DigestScheme(); digestScheme.processChallenge(auth.getHttpHeader()); auth.setAuthHeader(digestScheme.authenticate(creds, request)); String test0 = auth.getHttpHeader().getValue(); String test1 = auth.getAuthHeader().getValue(); System.out.println(); } catch (Exception e) { System.err.println(e.toString()); auth.reason = AuthInfo.AUTH_BAD; } } else { auth.reason = AuthInfo.AUTH_NOT_SUPPORTED; } }