1 20 21 27 28 package javax.xml.stream; 29 30 import java.security.*; 31 import java.net.*; 32 import java.io.*; 33 import java.util.*; 34 35 42 class SecuritySupport { 43 44 45 ClassLoader getContextClassLoader() throws SecurityException { 46 return (ClassLoader ) 47 AccessController.doPrivileged(new PrivilegedAction() { 48 public Object run() { 49 ClassLoader cl = null; 50 cl = Thread.currentThread().getContextClassLoader(); 52 54 if (cl == null) 55 cl = ClassLoader.getSystemClassLoader(); 56 57 return cl; 58 } 59 }); 60 } 61 62 String getSystemProperty(final String propName) { 63 return (String ) 64 AccessController.doPrivileged(new PrivilegedAction() { 65 public Object run() { 66 return System.getProperty(propName); 67 } 68 }); 69 } 70 71 FileInputStream getFileInputStream(final File file) 72 throws FileNotFoundException 73 { 74 try { 75 return (FileInputStream) 76 AccessController.doPrivileged(new PrivilegedExceptionAction() { 77 public Object run() throws FileNotFoundException { 78 return new FileInputStream(file); 79 } 80 }); 81 } catch (PrivilegedActionException e) { 82 throw (FileNotFoundException)e.getException(); 83 } 84 } 85 86 InputStream getResourceAsStream(final ClassLoader cl, 87 final String name) 88 { 89 return (InputStream) 90 AccessController.doPrivileged(new PrivilegedAction() { 91 public Object run() { 92 InputStream ris; 93 if (cl == null) { 94 ris = ClassLoader.getSystemResourceAsStream(name); 95 } else { 96 ris = cl.getResourceAsStream(name); 97 } 98 return ris; 99 } 100 }); 101 } 102 103 boolean doesFileExist(final File f) { 104 return ((Boolean ) 105 AccessController.doPrivileged(new PrivilegedAction() { 106 public Object run() { 107 return new Boolean (f.exists()); 108 } 109 })).booleanValue(); 110 } 111 112 } 113 | Popular Tags |