List of usage examples for java.lang Exception toString
public String toString()
From source file:com.quietlycoding.android.reader.util.api.Tags.java
/** * This method pulls the tags from Google Reader, its used by the methods in * this class to communicate before parsing the specific results. * //w w w . j a v a 2 s . c o m * @param sid * the Google Reader authentication string. * @return arr JSONArray of the items from the server. */ private static JSONArray pullTags(String sid) { final DefaultHttpClient client = new DefaultHttpClient(); final HttpGet get = new HttpGet(URL); final BasicClientCookie cookie = Authentication.buildCookie(sid); try { client.getCookieStore().addCookie(cookie); final HttpResponse response = client.execute(get); final HttpEntity respEntity = response.getEntity(); Log.d(TAG, "Response from server: " + response.getStatusLine()); final InputStream in = respEntity.getContent(); final BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = ""; String arr = ""; while ((line = reader.readLine()) != null) { arr += line; } final JSONObject obj = new JSONObject(arr); final JSONArray array = obj.getJSONArray("tags"); return array; } catch (final Exception e) { Log.d(TAG, "Exception caught:: " + e.toString()); return null; } }
From source file:com.keybox.manage.db.UserThemeDB.java
/** * get user theme//from w ww .ja v a2 s . com * * @param userId object * @return user theme object */ public static UserSettings getTheme(Long userId) { UserSettings theme = null; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("select * from user_theme where user_id=?"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); if (rs.next()) { theme = new UserSettings(); theme.setBg(rs.getString("bg")); theme.setFg(rs.getString("fg")); if (StringUtils.isNotEmpty(rs.getString("d1"))) { String[] colors = new String[16]; colors[0] = rs.getString("d1"); colors[1] = rs.getString("d2"); colors[2] = rs.getString("d3"); colors[3] = rs.getString("d4"); colors[4] = rs.getString("d5"); colors[5] = rs.getString("d6"); colors[6] = rs.getString("d7"); colors[7] = rs.getString("d8"); colors[8] = rs.getString("b1"); colors[9] = rs.getString("b2"); colors[10] = rs.getString("b3"); colors[11] = rs.getString("b4"); colors[12] = rs.getString("b5"); colors[13] = rs.getString("b6"); colors[14] = rs.getString("b7"); colors[15] = rs.getString("b8"); theme.setColors(colors); } } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return theme; }
From source file:Main.java
private static boolean setWebkitProxyICS(Context ctx, String host, int port) throws Exception { // PSIPHON: added support for Android 4.x WebView proxy try {//from ww w . j a v a 2 s . c o m Class webViewCoreClass = Class.forName("android.webkit.WebViewCore"); Class proxyPropertiesClass = Class.forName("android.net.ProxyProperties"); if (webViewCoreClass != null && proxyPropertiesClass != null) { Method m = webViewCoreClass.getDeclaredMethod("sendStaticMessage", Integer.TYPE, Object.class); Constructor c = proxyPropertiesClass.getConstructor(String.class, Integer.TYPE, String.class); if (m != null && c != null) { m.setAccessible(true); c.setAccessible(true); Object properties = c.newInstance(host, port, null); // android.webkit.WebViewCore.EventHub.PROXY_CHANGED = 193; m.invoke(null, 193, properties); return true; } else return false; } } catch (Exception e) { Log.e("ProxySettings", "Exception setting WebKit proxy through android.net.ProxyProperties: " + e.toString()); } catch (Error e) { Log.e("ProxySettings", "Exception setting WebKit proxy through android.webkit.Network: " + e.toString()); } return false; }
From source file:com.sharksharding.resources.register.bean.RegisterDataSource.java
/** * bean//from ww w . j av a2s . c o m * * @author gaoxianglong * * @param nodePathValue * zookeepervalue * * @param resourceType * * * @return void */ public static void register(String nodePathValue, String resourceType) { if (null == aContext) return; final String tmpdir = TmpManager.createTmp(); logger.debug("tmpdir-->" + tmpdir); try (BufferedWriter out = new BufferedWriter(new FileWriter(tmpdir))) { if (null != nodePathValue) { out.write(nodePathValue); out.flush(); FileSystemResource resource = new FileSystemResource(tmpdir); ConfigurableApplicationContext cfgContext = (ConfigurableApplicationContext) aContext; DefaultListableBeanFactory beanfactory = (DefaultListableBeanFactory) cfgContext.getBeanFactory(); /* * ?????ioc?,???bean, * loadBeanDefinitions() */ new XmlBeanDefinitionReader(beanfactory).loadBeanDefinitions(resource); final String defaultBeanName = "jdbcTemplate"; String[] beanNames = beanfactory.getBeanDefinitionNames(); for (String beanName : beanNames) { /* ??beanNamejdbcTemplateJdbcTemplate */ if (defaultBeanName.equals(beanName)) { GetJdbcTemplate.setJdbcTemplate((JdbcTemplate) beanfactory.getBean(defaultBeanName)); } else { /* bean */ beanfactory.getBean(beanName); } } } } catch (Exception e) { throw new RegisterBeanException(e.toString()); } finally { TmpManager.deleteTmp(tmpdir); } }
From source file:Main.java
public static Bitmap getCompressBitmap(Bitmap bitmap, File file, int quality, int fileSize) { Bitmap bmp = null;/* www .jav a 2 s. c om*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); boolean result = bitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos); LOG("getCompressBitmap result: " + result); try { if (file != null) { if (result) { byte[] bt = bos.toByteArray(); FileOutputStream fos = new FileOutputStream(file); fos.write(bt); fos.close(); LOG("file.length(): " + file.length()); if (file.length() > fileSize) { bmp = getCompressBitmap(bmp, file, (int) (quality * 0.8), fileSize); } else { bmp = BitmapFactory.decodeFile(file.getPath()); } } } else { bmp = BitmapFactory.decodeByteArray(bos.toByteArray(), 0, bos.size()); } bos.close(); } catch (Exception e) { LOG("getCompressBitmap result: e" + e.toString()); e.printStackTrace(); return null; } return bmp; }
From source file:io.github.azagniotov.stubby4j.Main.java
private static void startStubby4jUsingCommandLineArgs() { try {/* ww w . jav a 2 s. c om*/ final long initialStart = System.currentTimeMillis(); final Map<String, String> commandLineArgs = commandLineInterpreter.getCommandlineParams(); final String configFilename = commandLineArgs.get(CommandLineInterpreter.OPTION_CONFIG); ANSITerminal.muteConsole(commandLineInterpreter.isMute()); ConsoleUtils.enableDebug(commandLineInterpreter.isDebug()); final File configFile = new File(configFilename); final Future<List<StubHttpLifecycle>> stubLoadComputation = EXECUTOR_SERVICE .submit(() -> new YAMLParser().parse(configFile.getParent(), configFile)); final StubbyManager stubbyManager = new StubbyManagerFactory().construct(configFile, commandLineArgs, stubLoadComputation); stubbyManager.startJetty(); final long totalEnd = System.currentTimeMillis(); ANSITerminal.status(String.format(BR + "stubby4j successfully started after %s milliseconds", (totalEnd - initialStart)) + BR); stubbyManager.statuses().forEach(ANSITerminal::status); ANSITerminal.info(BR + "Quit: ctrl-c" + BR); } catch (final Exception ex) { final String msg = String.format("Could not init stubby4j, error: %s", ex.toString()); throw new Stubby4JException(msg, ex); } }
From source file:msuresh.raftdistdb.RaftCluster.java
public static void InitPortNumber() { try {//from w w w . ja va 2 s . c om File f = new File(Constants.STATE_LOCATION + "global.info"); if (!f.exists()) { createDefaultGlobal(); } JSONParser parser = new JSONParser(); Object obj = parser.parse(new FileReader(Constants.STATE_LOCATION + "global.info")); JSONObject jsonObject = (JSONObject) obj; Long a = (Long) jsonObject.get("currentCount"); portId = a.intValue(); } catch (Exception e) { System.out.println(e.toString()); } }
From source file:com.grandcircus.controller.GoogleGeocode.java
/** * Given the string of an address, return a Coordinates object that contains * the coordinate information extracted from the API response * * @param address the string representation of a physical address * @return Coordinates object containing coordinate information from response *//*from w w w.java2s .co m*/ public static Coordinates geocode(String address) { Coordinates coords = new Coordinates(); String requestUrl = ""; try { requestUrl = buildURL(address); } catch (UnsupportedEncodingException uee) { uee.printStackTrace(); } GetMethod getMethod = new GetMethod(requestUrl); getMethod.setFollowRedirects(true); try { httpClient.executeMethod(getMethod); // build the response object GoogleGeocodeResponse response = new GoogleGeocodeResponse( IOUtils.toString(getMethod.getResponseBodyAsStream(), getMethod.getRequestCharSet())); /** * Parsing can be done via Dom Document as well: * GoogleGeocodeResponse response = new GoogleGeocodeResponse(getMethod.getResponseBodyAsStream()); */ // only change coordinates from default if request successful if (response.successful()) { coords = response.getCoords(); } } catch (Exception e) { System.out.println("Geocode exception: " + e.toString()); } finally { getMethod.abort(); getMethod.releaseConnection(); } return coords; }
From source file:com.keybox.manage.util.KeyStoreUtil.java
/** * get secret entry for alias// ww w.j a va 2 s . c o m * * @param alias keystore secret alias * @return secret byte array */ public static byte[] getSecretBytes(String alias) { byte[] value = null; try { KeyStore.SecretKeyEntry entry = (KeyStore.SecretKeyEntry) keyStore.getEntry(alias, new KeyStore.PasswordProtection(KEYSTORE_PASS)); value = entry.getSecretKey().getEncoded(); } catch (Exception ex) { log.error(ex.toString(), ex); } return value; }
From source file:com.keybox.manage.util.KeyStoreUtil.java
/** * get secret entry for alias/*from w w w .jav a 2 s. c om*/ * * @param alias keystore secret alias * @return secret string */ public static String getSecretString(String alias) { String value = null; try { KeyStore.SecretKeyEntry entry = (KeyStore.SecretKeyEntry) keyStore.getEntry(alias, new KeyStore.PasswordProtection(KEYSTORE_PASS)); value = new String(entry.getSecretKey().getEncoded()); } catch (Exception ex) { log.error(ex.toString(), ex); } return value; }