List of usage examples for java.lang Exception Exception
public Exception(Throwable cause)
From source file:Main.java
static File make_tmpdir(Context context, SQLiteDatabase db) throws Exception { File extdir = Environment.getExternalStorageDirectory(); File tmp_top = new File(extdir, "tmp_LongText"); if (!tmp_top.exists()) { if (!tmp_top.mkdir()) throw new Exception("cannot create directory: " + tmp_top.getPath()); }//from w w w . ja va 2s .c om if (!tmp_top.canWrite()) throw new Exception("missing permission to write to " + tmp_top.getPath()); File tmpdir; Random r = new Random(); do { tmpdir = new File(tmp_top, String.format("%d", r.nextInt())); } while (tmpdir.exists()); if (!tmpdir.mkdir()) throw new Exception("cannot create directory: " + tmp_top.getPath()); if (!tmpdir.canWrite()) throw new Exception("missing permission to write to " + tmp_top.getPath()); ContentValues v = new ContentValues(); v.put("pid", Process.myPid()); v.put("tmpdir", tmpdir.getPath()); v.put("ctime", System.currentTimeMillis()); db.insert("tmpdir", null, v); return tmpdir; }
From source file:Main.java
public static Document createDocumentFromFile(File file) throws Exception { DocumentBuilderFactory factory = getDocumentBuilderFactory(); DocumentBuilder builder;/*w w w .j av a 2 s.c o m*/ try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new Exception(e); } return builder.parse(file); }
From source file:Main.java
public static Document createDocumentFromStream(InputStream is) throws Exception { DocumentBuilderFactory factory = getDocumentBuilderFactory(); DocumentBuilder builder;/* ww w. j a v a 2s .c o m*/ try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new Exception(e); } return builder.parse(is); }
From source file:Main.java
/** * Decrypt data/* ww w . j a va 2 s . co m*/ * @param secretKey - a secret key used for decryption * @param data - data to decrypt * @return Decrypted data * @throws Exception */ public static String decipher(String secretKey, String data) throws Exception { // Key has to be of length 8 if (secretKey == null || secretKey.length() != 8) throw new Exception("Invalid key length - 8 bytes key needed!"); SecretKey key = new SecretKeySpec(secretKey.getBytes(), ALGORITHM); Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, key); return new String(cipher.doFinal(toByte(data))); }
From source file:Main.java
private static String getTypeByClass(Class<?> type) throws Exception { if (type.equals(String.class)) { return "TEXT"; }// w ww. j av a2s .co m if (type.equals(Long.class) || type.equals(Integer.class) || type.equals(long.class) || type.equals(Date.class)) { return "INTEGER"; } if (type.equals(Boolean.class)) { return "BOOLEAN"; } Exception exception = new Exception( CONVERSION_CLASS_NOT_FOUND_EXCEPTION.concat(" - Class: ").concat(type.toString())); throw exception; }
From source file:MainClass.java
public static void b() throws Exception { throw new Exception("The Root Exception"); }
From source file:Main.java
/** * Method to decode a string xml text./* w ww . j a va 2 s . c o m*/ * @param text string xml to decode. * @return the string xml decoded. * @throws Exception throw if any error is occurred. */ public static String xmlDecode(String text) throws Exception { String origText = text; String newText = ""; while (text.contains("&")) { int pos = text.indexOf("&"); newText += text.substring(0, pos); text = text.substring(pos + 1); pos = text.indexOf(";"); if (pos <= 0) { throw new Exception("Improperly escaped character: " + origText); } String charref = text.substring(0, pos); text = text.substring(pos + 1); if (charref.equals("lt")) { newText += "<"; } else if (charref.equals("gt")) { newText += ">"; } else if (charref.equals("amp")) { newText += "&"; } else if (charref.equals("quot")) { newText += "\""; } else if (charref.equals("apos")) { newText += "'"; } else if (charref.startsWith("#")) { String number = charref.substring(1); int radix = 10; if (charref.startsWith("#x") || charref.startsWith("#X")) { number = charref.substring(2); radix = 16; } if ("".equals(number)) { throw new Exception("Improperly escaped character: " + charref); } char ch; try { ch = (char) Integer.parseInt(number, radix); } catch (NumberFormatException nfe) { throw new Exception("Improperly escaped character: " + charref); } newText += ch; } else { throw new Exception("Improperly escaped character: " + charref); } } //while return newText + text; }
From source file:ExceptionTrial.java
public static void theRoot() throws Exception { throw new Exception("The Root Exception"); }
From source file:eu.socialSensor.diverseImages2014.datasetCreation.MakeRelevanceDataset.java
/** * @param args//w w w.j a v a 2s .c om * [0] collection path<br> * [1] comma separated feature types e.g. "HOG,SURF,CM" <br> * [2] comma separated individual feature normalizations e.g. "l2,no,l2" <br> * [3] the type of normalization to apply on the concatenation of the features that are * individually normalized, e.g. "l2" or "no" <br> * [4] the type of normalization to apply on the overall vector, e.g. "l2" or "no" <br> * [5] whether to include Wikipedia image vectors <br> * [6] whether to write the dataset in sparse format<br> * [7] the filename extension (typically "dev" or "test") * * @throws Exception */ public static void main(String[] args) throws Exception { String collectionPath = args[0]; String[] featureTypes = args[1].split(","); String[] individualNorms = args[2].split(","); if (featureTypes.length != individualNorms.length) { throw new Exception("Features types and normalizations have different sizes!"); } String level1Norm = args[3]; String finalNorm = args[4]; boolean includeWiki = Boolean.parseBoolean(args[5]); boolean writeSparse = Boolean.parseBoolean(args[6]); String datasetExtension = args[7]; MEDI2014Collection dataStoreTrain = new MEDI2014Collection(collectionPath); dataStoreTrain.loadAll(includeWiki, featureTypes, individualNorms); MakeRelevanceDataset marf = new MakeRelevanceDataset(dataStoreTrain, featureTypes); String arffFileName = Arrays.toString(featureTypes) + "-" + Arrays.toString(individualNorms) + "-" + level1Norm + "-" + finalNorm; arffFileName += "-" + datasetExtension + ".arff"; marf.writeFile(arffFileName, individualNorms, level1Norm, finalNorm, writeSparse); }
From source file:Main.java
/** * Encrypt data// w ww . ja v a 2s . c o m * @param secretKey - a secret key used for encryption * @param data - data to encrypt * @return Encrypted data * @throws Exception */ public static String cipher(String secretKey, String data) throws Exception { // Key has to be of length 8 if (secretKey == null || secretKey.length() != 8) throw new Exception("Invalid key length - 8 bytes key needed!"); SecretKey key = new SecretKeySpec(secretKey.getBytes(), ALGORITHM); Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.ENCRYPT_MODE, key); return toHex(cipher.doFinal(data.getBytes())); }