List of usage examples for java.lang SecurityException toString
public String toString()
From source file:Main.java
public static String getDownloadDir() { String status = Environment.getExternalStorageState(); if (status == null || !status.equals(Environment.MEDIA_MOUNTED)) { return null; }/*from www.ja v a 2 s. c om*/ String path = null; // get the sdcard directory File sdFile = Environment.getExternalStorageDirectory(); if (null != sdFile) { path = sdFile.toString(); } else { path = "/sdcard/"; } path += "/download"; File destDir = new File(path); if (!destDir.exists()) { try { if (!destDir.mkdirs()) { Log.e("getDownloadDir", "create folder " + path + " failed"); return null; } } catch (SecurityException e) { Log.e("getDownloadDir", "create folder " + path + " failed: " + e.toString()); return null; } } return path; }
From source file:org.jdesktop.wonderland.modules.service.ModuleManagerUtils.java
/** * Creates a directory, and any necessary parent directories, if it does * not exist. Throws IOException upon error. * //from w w w. j a va2 s . com * @param root The directory to create */ public static void makeDirectory(File root) throws IOException { try { /* Create the directory, if false, throw IOException */ if (root.exists() == false) { if (root.mkdirs() == false) { throw new IOException("Failed to create " + root.getAbsolutePath()); } } } catch (java.lang.SecurityException excp) { throw new IOException(excp.toString()); } }
From source file:com.aegiswallet.utils.BasicUtils.java
public static String[] loadFileList() { String[] fileList = null;//from w ww . j a v a 2 s. c om File filesPath = Constants.WALLET_BACKUP_DIRECTORY; if (Constants.WALLET_BACKUP_DIRECTORY.exists() && Constants.WALLET_BACKUP_DIRECTORY.isDirectory()) { final String filePrefix = "AegisWalletBackup"; try { filesPath.mkdirs(); } catch (SecurityException e) { Log.e(TAG, "Could not write to SD card - " + e.toString()); } if (filesPath.exists()) { FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String filename) { File sel = new File(dir, filename); return filename.contains(filePrefix) || sel.isDirectory(); } }; fileList = filesPath.list(filter); } else { fileList = new String[0]; } } return fileList; }
From source file:it.cnr.icar.eric.common.AbstractProperties.java
/** * Checks if a directory for the given name exists. If not, try to create it. * * @param homeDir A File descriptor for the directory to be checked. * @return Full path to the directory./* ww w. j av a2s . co m*/ * @throw JAXRException if it fails to find and create the directory. */ protected static String initHomeDir(String propName, File homeDir) { try { if (!homeDir.exists()) { if (!homeDir.mkdirs()) { throw new RuntimeException(CommonResourceBundle.getInstance() .getString("message.createDirectory", new String[] { propName, homeDir.getPath() })); } } else { if (!homeDir.isDirectory()) { throw new RuntimeException(CommonResourceBundle.getInstance() .getString("message.accessDirectory", new String[] { propName, homeDir.getPath() })); } } String homeDirStr = homeDir.getCanonicalPath(); return homeDirStr; } catch (SecurityException se) { throw new RuntimeException(CommonResourceBundle.getInstance().getString("message.permissionDenied", new String[] { propName, homeDir.getPath(), se.toString() })); } catch (IOException io) { throw new RuntimeException(CommonResourceBundle.getInstance().getString("message.createAccessDirectory", new String[] { propName, homeDir.getPath(), io.toString() })); } }
From source file:org.omegat.util.StaticUtils.java
public static String getScriptDir() { // If the script directory has already been determined, return it if (m_scriptDir != null) return m_scriptDir; m_scriptDir = getConfigDir() + SCRIPT_DIR + File.separator; try {/* w ww .j a v a 2 s.c o m*/ // Check if the directory exists File dir = new File(m_scriptDir); if (!dir.exists()) { // Create the directory boolean created = dir.mkdirs(); // If the directory could not be created, // set the script directory to config directory if (!created) { Log.logErrorRB("SU_SCRIPT_DIR_CREATE_ERROR"); m_scriptDir = getConfigDir(); } } } catch (SecurityException e) { // The system doesn't want us to write where we want to write // reset the script dir to the current config dir m_scriptDir = getConfigDir(); // log the exception, but only after the script dir has been reset Log.logErrorRB("SU_SCRIPT_DIR_CREATE_ERROR"); Log.log(e.toString()); } return m_scriptDir; }
From source file:org.openstreetmap.josm.tools.ImageProvider.java
private static URL getImageUrl(String imageName, Collection<String> dirs, Collection<ClassLoader> additionalClassLoaders) { URL u = null;// ww w. j a v a 2 s .c om // Try passed directories first if (dirs != null) { for (String name : dirs) { try { u = getImageUrl(name, imageName, additionalClassLoaders); if (u != null) return u; } catch (SecurityException e) { System.out.println(tr( "Warning: failed to access directory ''{0}'' for security reasons. Exception was: {1}", name, e.toString())); } } } // Try user-preference directory String dir = Main.pref.getPreferencesDir() + "images"; try { u = getImageUrl(dir, imageName, additionalClassLoaders); if (u != null) return u; } catch (SecurityException e) { System.out.println( tr("Warning: failed to access directory ''{0}'' for security reasons. Exception was: {1}", dir, e.toString())); } // Absolute path? u = getImageUrl(null, imageName, additionalClassLoaders); if (u != null) return u; // Try plugins and josm classloader u = getImageUrl("resource://images/", imageName, additionalClassLoaders); if (u != null) return u; // Try all other resource directories for (String location : Main.pref.getAllPossiblePreferenceDirs()) { u = getImageUrl(location + "images", imageName, additionalClassLoaders); if (u != null) return u; u = getImageUrl(location, imageName, additionalClassLoaders); if (u != null) return u; } return null; }
From source file:org.eurekastreams.commons.scheduling.TransactionalTaskRunner.java
/** * * @param inTarget the object to call./* w w w . j a v a 2 s .c o m*/ * @param methodName the method to run on the target, method must accept no arguments. */ public TransactionalTaskRunner(final Object inTarget, final String methodName) { try { target = inTarget; method = inTarget.getClass().getMethod(methodName); } catch (SecurityException e) { log.error(e.toString()); } catch (NoSuchMethodException e) { log.error(e.toString()); } }
From source file:ua.aits.Carpath.functions.FileMethods.java
public String createTempDir() { Date date_format = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy-HH-mm-SS"); String folder = "archive_temp/temp-" + sdf.format(date_format); try {//from w w w . j av a 2 s .co m final boolean directory = new File(Constants.HOME + folder).mkdirs(); return folder; } catch (SecurityException se) { return se.toString(); } }
From source file:org.opendatakit.common.android.utilities.Base64Wrapper.java
public byte[] decode(String base64String) { Class<?>[] argClassList = new Class[] { String.class, int.class }; Object o;// w w w . ja v a2 s . c om try { Method m = base64.getDeclaredMethod("decode", argClassList); Object[] argList = new Object[] { base64String, FLAGS }; o = m.invoke(null, argList); } catch (SecurityException e) { e.printStackTrace(); throw new IllegalArgumentException(e.toString()); } catch (NoSuchMethodException e) { e.printStackTrace(); throw new IllegalArgumentException(e.toString()); } catch (IllegalAccessException e) { e.printStackTrace(); throw new IllegalArgumentException(e.toString()); } catch (InvocationTargetException e) { e.printStackTrace(); throw new IllegalArgumentException(e.toString()); } return (byte[]) o; }
From source file:org.opendatakit.common.android.utilities.Base64Wrapper.java
public String encodeToString(byte[] ba) { Class<?>[] argClassList = new Class[] { byte[].class, int.class }; try {/*from w ww . jav a 2 s . co m*/ Method m = base64.getDeclaredMethod("encode", argClassList); Object[] argList = new Object[] { ba, FLAGS }; Object o = m.invoke(null, argList); byte[] outArray = (byte[]) o; String s = new String(outArray, CharEncoding.UTF_8); return s; } catch (SecurityException e) { e.printStackTrace(); throw new IllegalArgumentException(e.toString()); } catch (NoSuchMethodException e) { e.printStackTrace(); throw new IllegalArgumentException(e.toString()); } catch (IllegalAccessException e) { e.printStackTrace(); throw new IllegalArgumentException(e.toString()); } catch (InvocationTargetException e) { e.printStackTrace(); throw new IllegalArgumentException(e.toString()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new IllegalArgumentException(e.toString()); } }