List of usage examples for java.lang Exception toString
public String toString()
From source file:Main.java
public static String convertXMLFileToString(String fileName) { try {/*ww w .ja va 2 s. c o m*/ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); Document doc = documentBuilderFactory.newDocumentBuilder().parse(inputStream); StringWriter stw = new StringWriter(); Transformer serializer = TransformerFactory.newInstance().newTransformer(); serializer.transform(new DOMSource(doc), new StreamResult(stw)); return stw.toString(); } catch (Exception e) { System.out.println("Unable to load xml file: " + e.toString()); } return null; }
From source file:Main.java
public static String calculateMd5Checksum(String filename) { String result = ""; try {//from w w w. j av a2 s.com byte[] b = createChecksumBytes(filename, "MD5"); // convert bytes to HEX strings for (int i = 0; i < b.length; i++) { result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1); } } catch (Exception ex) { throw new RuntimeException("Error: " + ex.toString(), ex); } return result; }
From source file:Main.java
public static String getWithinTags(String matchString, String tag) { final Pattern pattern = Pattern.compile("<" + tag + ">(.+?)</" + tag + ">"); final Matcher matcher = pattern.matcher(matchString); try {/* w w w .j a v a 2 s . co m*/ matcher.find(); return matcher.group(1); } catch (Exception e) { System.out.println("An exception has occured within tags: " + e.toString()); return ""; } }
From source file:Main.java
static public final String toString(Node node, boolean declaration) { try {// w w w. j av a 2 s . c o m DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); writer.getDomConfig().setParameter("xml-declaration", declaration); return writer.writeToString(node); } catch (Exception e) { return e.toString(); } }
From source file:Main.java
private static void writePageNameHashesToFile(Map<UUID, String> map, File folder) { if (uuidsToNames != null) { String mapString = "Map: "; for (Map.Entry<UUID, String> entry : uuidsToNames.entrySet()) { mapString += entry.toString(); mapString += "\n"; }/* ww w . j a v a 2 s . co m*/ } if (map == null) { // TODO: Do I need this? map = new HashMap<UUID, String>(); } try { FileOutputStream fos = new FileOutputStream(folder.getAbsolutePath() + fileName); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(map); oos.close(); } catch (Exception e) { Log.e("Write to file", e.toString()); } }
From source file:Main.java
public static boolean isImage(Blob blob) throws Exception { InputStream in = null;/*from w w w . j ava 2s .c o m*/ byte[] bytes = new byte[8]; try { in = blob.getBinaryStream(); in.read(bytes); return isImage(bytes); } catch (Exception ex) { throw new Exception(ex.toString()); } finally { if (in != null) { try { in.close(); } catch (IOException ex) { throw new Exception(ex.toString()); } } bytes = null; } }
From source file:Main.java
public static void saveDBInSdcard(Context pContext, String pDatabaseName) { try {/*from w ww .j a v a2s .co m*/ File sd = Environment.getExternalStorageDirectory(); File data = Environment.getDataDirectory(); if (sd.canWrite()) { String currentDBPath = "//data//" + pContext.getPackageName() + "//databases//" + pDatabaseName; String backupDBPath = pDatabaseName; File currentDB = new File(data, currentDBPath); File backupDB = new File(sd, backupDBPath); FileChannel src = new FileInputStream(currentDB).getChannel(); FileChannel dst = new FileOutputStream(backupDB).getChannel(); dst.transferFrom(src, 0, src.size()); src.close(); dst.close(); Toast.makeText(pContext, backupDB.toString(), Toast.LENGTH_LONG).show(); } } catch (Exception e) { Toast.makeText(pContext, e.toString(), Toast.LENGTH_LONG).show(); } }
From source file:Main.java
public static boolean saveBitmap(Bitmap bmp, String path) { File file = new File(path); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs();// www.ja v a 2 s . c o m } if (file.exists()) { file.delete(); } try { FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.JPEG, 80, out); out.flush(); out.close(); Log.i("saveBitmap success:", path); return true; } catch (Exception e) { Log.e("saveBitmap:" + path, e.toString()); } return false; }
From source file:Main.java
/** get first valid ipv4 address of this device */ public static String getLocalIpAddress() { try {/*from ww w. j a va 2s . com*/ for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress() && validIP(inetAddress.getHostAddress())) { return inetAddress.getHostAddress(); } } } } catch (Exception e) { Log.e(TAG, e.toString()); } return null; }
From source file:Main.java
public static String getValue(String key) { try {//from w w w . j av a 2 s . c om String value = config.getProperty(key); return value; } catch (Exception e) { e.printStackTrace(); System.err.println("ConfigInfoError" + e.toString()); return null; } }