List of usage examples for java.lang SecurityException getMessage
public String getMessage()
From source file:Main.java
/** * Vibrate if we can / are allowed to.//from w ww . jav a 2 s. c om */ public static void vibrate(@Nullable Vibrator vibrator, int milliseconds) { if (vibrator == null) { Log.i(TAG, "Not vibrating; no vibration support / vibrator not set up"); return; } try { vibrator.vibrate(milliseconds); Log.d(TAG, milliseconds + "ms vibration started..."); } catch (SecurityException e) { Log.i(TAG, "Not vibrating: " + e.getMessage()); } }
From source file:Delete2.java
public static void delete(String fileName) { try {//from ww w. ja v a2 s . c o m // Construct a File object for the file to be deleted. File target = new File(fileName); if (!target.exists()) { System.err.println("File " + fileName + " not present to begin with!"); return; } // Quick, now, delete it immediately: if (target.delete()) System.err.println("** Deleted " + fileName + " **"); else System.err.println("Failed to delete " + fileName); } catch (SecurityException e) { System.err.println("Unable to delete " + fileName + "(" + e.getMessage() + ")"); } }
From source file:Main.java
public static <T> T newInstance(Class<T> type, Class<?>[] argsClass, Object[] argsValues) throws InstantiationException, IllegalAccessException { T instance = null;//w ww .j av a 2 s.com try { Constructor<T> constructorDef = type.getConstructor(argsClass); instance = constructorDef.newInstance(argsValues); } catch (SecurityException e) { throw new InstantiationException(e.getMessage()); } catch (NoSuchMethodException e) { throw new InstantiationException(e.getMessage()); } catch (IllegalArgumentException e) { throw new InstantiationException(e.getMessage()); } catch (InvocationTargetException e) { throw new InstantiationException(e.getMessage()); } return instance; }
From source file:edu.harvard.iq.dataverse.batch.util.LoggingUtil.java
public static Logger getJobLogger(String jobId) { try {/*from w ww.jav a2 s . co m*/ Logger jobLogger = Logger.getLogger("job-" + jobId); FileHandler fh; String logDir = System.getProperty("com.sun.aas.instanceRoot") + System.getProperty("file.separator") + "logs" + System.getProperty("file.separator") + "batch-jobs" + System.getProperty("file.separator"); checkCreateLogDirectory(logDir); fh = new FileHandler(logDir + "job-" + jobId + ".log"); logger.log(Level.INFO, "JOB LOG: " + logDir + "job-" + jobId + ".log"); jobLogger.addHandler(fh); fh.setFormatter(new JobLogFormatter()); return jobLogger; } catch (SecurityException e) { logger.log(Level.SEVERE, "Unable to create job logger: " + e.getMessage()); return null; } catch (IOException e) { logger.log(Level.SEVERE, "Unable to create job logger: " + e.getMessage()); return null; } }
From source file:com.bluecloud.ioc.classloader.ClassHandler.java
/** * <h3>Class</h3>//from w w w. ja v a2 s . c o m * * @param obj * * @param methodName * ?? * @param args * ? * @throws IllegalArgumentException * @throws IllegalAccessException * @throws InvocationTargetException */ public static void invokeMethod(Object obj, String methodName, Object args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Class<? extends Object> clazz = obj.getClass(); try { if (args != null) { clazz.getMethod(methodName, args.getClass()).invoke(obj, args); } } catch (SecurityException e) { log.error(e.getMessage(), e); } catch (NoSuchMethodException e) { for (Method method : clazz.getMethods()) { if (method.getName().equals(methodName) && method.getParameterTypes().length == 1) { method.invoke(obj, args); } } } }
From source file:com.salsaberries.narchiver.Writer.java
/** * Writes all the pages to file.//from w ww. j a v a 2 s.c o m * * @param pages * @param location */ public static void storePages(LinkedList<Page> pages, String location) { logger.info("Dumping " + pages.size() + " pages to file at " + location + "/"); File file = new File(location); // Make sure the directory exists if (!file.exists()) { try { file.mkdirs(); logger.info("Directory " + file.getAbsolutePath() + " does not exist, creating."); } catch (SecurityException e) { logger.error(e.getMessage()); } } // Write them to the file if they haven't been already written while (!pages.isEmpty()) { Page page = pages.removeFirst(); String fileName = file.getAbsolutePath() + "/" + page.getDate() + "|" + URLEncoder.encode(page.getTagURL()); try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) { writer.write(page.toString()); } catch (IOException e) { logger.warn(e.getMessage()); } // Temporarily try to reduce memory page.setHtml(""); } }
From source file:Main.java
public static InputStream createWallpaperInputStream(Context context, String preferenceValue) throws FileNotFoundException { File file = new File(preferenceValue); if (file.exists()) { return new FileInputStream(file); }/*from w w w . ja va2 s .com*/ Uri uri = Uri.parse(preferenceValue); ContentResolver contentResolver = context.getContentResolver(); try { return contentResolver.openInputStream(uri); } catch (SecurityException e) { Log.i("ThemingUtils", "unable to open background image", e); FileNotFoundException fileNotFoundException = new FileNotFoundException(e.getMessage()); fileNotFoundException.initCause(e); throw fileNotFoundException; } }
From source file:org.pepstock.jem.node.tasks.jndi.AbsoluteHashMap.java
/** * This is a singleton. If instance is not null, means that local map is already loaded. * If null and classload is ANT classloader, then uses the proxy to load the instance from parent classloader, * otherwise it creates a new instance.// w w w . j ava 2 s. co m * @return shared HashMap. */ @SuppressWarnings({ "rawtypes", "unchecked" }) static synchronized Map<String, Object> getInstance() { ClassLoader myClassLoader = AbsoluteHashMap.class.getClassLoader(); if (instance == null) { // The root classloader is sun.misc.Launcher package. If we are not in a sun package, // we need to get hold of the instance of ourself from the class in the root classloader. // checks is ANT classloader if (myClassLoader.getClass().getName().startsWith("org.apache.tools.ant.loader.AntClassLoader") || myClassLoader.getClass().getName().startsWith(ReverseURLClassLoader.class.getName())) { try { // So we find our parent classloader ClassLoader parentClassLoader = myClassLoader.getParent(); // And get the other version of our current class Class otherClassInstance = parentClassLoader.loadClass(AbsoluteHashMap.class.getName()); // And call its getInstance method - this gives the correct instance of ourself Method getInstanceMethod = otherClassInstance.getDeclaredMethod("getInstance", new Class[] { String.class }); String internalKey = createKey(); Object otherAbsoluteSingleton = getInstanceMethod.invoke(null, new Object[] { internalKey }); // But, we can't cast it to our own interface directly because classes loaded from // different classloaders implement different versions of an interface. // So instead, we use java.lang.reflect.Proxy to wrap it in an object that // supports our interface, and the proxy will use reflection to pass through all calls // to the object. instance = (Map<String, Object>) Proxy.newProxyInstance(myClassLoader, new Class[] { Map.class }, new DelegateInvocationHandler(otherAbsoluteSingleton)); } catch (SecurityException e) { LogAppl.getInstance().debug(e.getMessage(), e); } catch (IllegalArgumentException e) { LogAppl.getInstance().debug(e.getMessage(), e); } catch (ClassNotFoundException e) { LogAppl.getInstance().debug(e.getMessage(), e); } catch (NoSuchMethodException e) { LogAppl.getInstance().debug(e.getMessage(), e); } catch (IOException e) { LogAppl.getInstance().debug(e.getMessage(), e); } catch (IllegalAccessException e) { LogAppl.getInstance().debug(e.getMessage(), e); } catch (InvocationTargetException e) { LogAppl.getInstance().debug(e.getMessage(), e); } // We're in the root classloader, so the instance we have here is the correct one } else { instance = new AbsoluteHashMap(); } } return instance; }
From source file:org.apache.flex.utils.FileUtils.java
/** * returns whether the file is absolute//from w w w. java 2 s. c o m * if a security exception is thrown, always returns false */ public static boolean isAbsolute(File f) { boolean absolute = false; try { absolute = f.isAbsolute(); } catch (SecurityException se) { if (Trace.pathResolver) { Trace.trace(se.getMessage()); } } return absolute; }
From source file:com.sun.socialsite.web.rest.core.RestrictedDataRequestHandler.java
public static void authorizeRequest(SocialRequestItem request) throws SocialSpiException { log.trace("BEGIN"); Future<?> result = null; try {/* w ww . j a v a 2 s . c o m*/ Factory.getSocialSite().getPermissionManager().checkPermission(requiredPermission, request.getToken()); } catch (SecurityException e) { if (log.isDebugEnabled()) { log.debug("Permission Denied", e); } throw new SocialSpiException(ResponseError.UNAUTHORIZED, e.getMessage()); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Unexpected Failure", e); } throw new SocialSpiException(ResponseError.BAD_REQUEST, e.getMessage()); } log.trace("END"); }