1 10 package com.ibm.icu.impl; 11 12 import java.io.InputStream ; 13 import java.net.URL ; 14 import java.security.AccessController ; 15 import java.security.PrivilegedAction ; 16 import java.util.MissingResourceException ; 17 18 21 public final class ICUData { 22 28 public static boolean exists(final String resourceName) { 29 URL i = null; 30 if (System.getSecurityManager() != null) { 31 i = (URL )AccessController.doPrivileged(new PrivilegedAction () { 32 public Object run() { 33 return ICUData.class.getResource(resourceName); 34 } 35 }); 36 } else { 37 i = ICUData.class.getResource(resourceName); 38 } 39 return i != null; 40 } 41 42 private static InputStream getStream(final Class root, final String resourceName, boolean required) { 43 InputStream i = null; 44 45 if (System.getSecurityManager() != null) { 46 i = (InputStream )AccessController.doPrivileged(new PrivilegedAction () { 47 public Object run() { 48 return root.getResourceAsStream(resourceName); 49 } 50 }); 51 } else { 52 i = root.getResourceAsStream(resourceName); 53 } 54 55 if (i == null && required) { 56 throw new MissingResourceException ("could not locate data " +resourceName, root.getPackage().getName(), resourceName); 57 } 58 return i; 59 } 60 61 private static InputStream getStream(final ClassLoader loader, final String resourceName, boolean required) { 62 InputStream i = null; 63 if (System.getSecurityManager() != null) { 64 i = (InputStream )AccessController.doPrivileged(new PrivilegedAction () { 65 public Object run() { 66 return loader.getResourceAsStream(resourceName); 67 } 68 }); 69 } else { 70 i = loader.getResourceAsStream(resourceName); 71 } 72 if (i == null && required) { 73 throw new MissingResourceException ("could not locate data", loader.toString(), resourceName); 74 } 75 return i; 76 } 77 78 public static InputStream getStream(ClassLoader loader, String resourceName){ 79 return getStream(loader,resourceName, false); 80 } 81 82 public static InputStream getRequiredStream(ClassLoader loader, String resourceName){ 83 return getStream(loader,resourceName, true); 84 } 85 86 89 public static InputStream getStream(String resourceName) { 90 return getStream(ICUData.class, resourceName, false); 91 } 92 93 96 public static InputStream getRequiredStream(String resourceName) { 97 return getStream(ICUData.class, resourceName, true); 98 } 99 100 103 public static InputStream getStream(Class root, String resourceName) { 104 return getStream(root, resourceName, false); 105 } 106 107 110 public static InputStream getRequiredStream(Class root, String resourceName) { 111 return getStream(root, resourceName, true); 112 } 113 } 114 115 | Popular Tags |