List of usage examples for java.lang Exception Exception
public Exception(Throwable cause)
From source file:Main.java
public static HashMap<String, Node> getNodes(Node p_node) throws Exception { NodeList l_list = null;/*from w w w .jav a 2 s . c om*/ Node l_node = null; HashMap<String, Node> l_a = null; l_list = p_node.getChildNodes(); if (l_list == null) { throw new Exception("XSD001: Unsupported / Invalid Element Type."); } l_a = new HashMap<String, Node>(); for (int l_i = 0; l_i < l_list.getLength(); l_i++) { l_node = l_list.item(l_i); if (l_node.getNodeType() == Element.ELEMENT_NODE) { l_a.put(l_node.getNodeName(), l_node); } } return l_a; }
From source file:Main.java
/** * Removes entities file.//from ww w .ja va 2s . co m * @param context * @param fileName * @throws Exception */ public static void removeAllEntities(Context context, String fileName) throws Exception { File file = new File(context.getFilesDir(), fileName); boolean deleted = file.delete(); if (!deleted) { throw new Exception("Failed to remove file=" + fileName); } }
From source file:Main.java
private static Node getSingleNodeElementByXpath(String xpath) throws Exception { NodeList list = getNodeListByXpath(xpath); Node node = null;/*from w w w.jav a 2 s.c om*/ if (list.getLength() > 0 && list.item(0).getNodeType() == Node.ELEMENT_NODE) { node = list.item(0); } else { throw new Exception("Xpath Query did not result in a Node element. Check your Xpath expression"); } return node; }
From source file:Main.java
static public String computeEffectiveServerUrl(String serverUrl, String userName, String password) throws Exception { if (null == userName && null != password) { throw new Exception("Can not specify a password without a user name"); }/*w w w. j a va 2s . c o m*/ if (null != userName && null == password) { throw new Exception("Can not specify a user name without a password"); } if (null != userName && null == serverUrl) { throw new Exception("Can not specify a user name/password without a server URL"); } if (null == serverUrl) { return ""; } String serverUrlWithoutProtocol = null; String protocol = null; if (serverUrl.startsWith(HTTP_PROTOCOL)) { protocol = HTTP_PROTOCOL; serverUrlWithoutProtocol = serverUrl.substring(HTTP_PROTOCOL.length()); } else if (serverUrl.startsWith(HTTPS_PROTOCOL)) { protocol = HTTPS_PROTOCOL; serverUrlWithoutProtocol = serverUrl.substring(HTTPS_PROTOCOL.length()); } else { throw new Exception("Server URL must specify a protocol (http:// or https://)"); } if (null != userName) { serverUrl = protocol + userName + ":" + password + "@" + serverUrlWithoutProtocol; } return serverUrl; }
From source file:Main.java
static public String computeEffectiveDatabaseUrl(String serverUrl, String userName, String password, String databaseName) throws Exception { if (null == databaseName) { throw new Exception("Can not specify a db URL without a database name"); }//from ww w . ja va 2 s . com String effectiveServerUrl = computeEffectiveServerUrl(serverUrl, userName, password); if ("".equals(effectiveServerUrl)) { return databaseName; } if (effectiveServerUrl.endsWith("/")) { return effectiveServerUrl + databaseName; } return effectiveServerUrl + "/" + databaseName; }
From source file:Main.java
/** * //from w w w.j a v a 2 s. c o m * @param bytes * @param offset * @param length * @return * @throws UtilityException */ public static byte[] sliceBytes(byte[] bytes, int offset, int length) throws Exception { if (null == bytes || bytes.length <= 0) { return null; } if (bytes.length < length) { throw new Exception("Array index out of bound : " + length); } if ((offset + length) > bytes.length) { throw new Exception("Array index out of bound : " + (offset + length)); } if (offset < 0 || offset > bytes.length - 1) { throw new Exception("Array index out of bound : " + (offset + length)); } byte[] newArray = new byte[length]; for (int i = offset, j = 0; j < length; i++, j++) { newArray[j] = bytes[i]; } return newArray; }
From source file:Main.java
public static String requestPage(String urlPath) throws Exception { URL url = new URL(urlPath); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); int responseCode = connection.getResponseCode(); if (responseCode != 200) { throw new Exception("Error loading page: " + responseCode + connection.getResponseMessage()); }//from w w w . ja v a 2s . c om BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String inputLine; String response = ""; while ((inputLine = in.readLine()) != null) { response += inputLine; } in.close(); return response; }
From source file:Main.java
public static byte[] normalizeArray(byte[] bytes, int expectedLength) throws Exception { if (bytes.length > expectedLength) { boolean invalid = false; for (int i = bytes.length - 1 - expectedLength; i >= 0; i--) { if (bytes[i] != 0) { invalid = true;// w w w . j av a 2 s. c o m break; } } if (invalid) throw new Exception("Longer byte array than expected by caller."); } if (bytes.length == expectedLength) return bytes; return preAppendHighZeroPadding(bytes, expectedLength - bytes.length); }
From source file:Main.java
public static void setDefaultFont(Context context, String path, String fontName) { try {/*from w w w . ja v a2 s . co m*/ defaultTypeFace = Typeface.createFromAsset(context.getAssets(), path + "/" + fontName + ".ttf"); } catch (RuntimeException e) { if (e.getMessage().equals("native typeface cannot be made")) { try { throw new Exception("the fontName that you use does not exist in the file path!!"); } catch (Exception e1) { e1.printStackTrace(); } } } }
From source file:Main.java
public static boolean deleteDirectory(File directory) throws Exception { try {//from w ww.j a va 2 s . c om if (directory.exists()) { File[] files = directory.listFiles(); for (int i = 0; i < files.length; i++) if (files[i].isDirectory()) deleteDirectory(files[i]); else files[i].delete(); } } catch (Exception e) { throw new Exception(new StringBuilder().append("Error occurred while trying to delete directory ") .append(directory).toString()); } return directory.delete(); }