本文整理汇总了Java中sun.misc.Resource类的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Resource类属于sun.misc包,在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClassBytesStream
import sun.misc.Resource; //导入依赖的package包/类
private InputStream getClassBytesStream(String internalName) throws IOException {
InputStream is = null;
// first look into platformCp
final String resourceName = internalName + CLASS_RESOURCE_EXTENSION;
Resource resource = myPlatformClasspath.getResource(resourceName, false);
if (resource != null) {
is = new ByteArrayInputStream(resource.getBytes());
}
// second look into memory and classspath
if (is == null) {
is = lookupClassBeforeClasspath(internalName);
}
if (is == null) {
resource = myClasspath.getResource(resourceName, false);
if (resource != null) {
is = new ByteArrayInputStream(resource.getBytes());
}
}
if (is == null) {
is = lookupClassAfterClasspath(internalName);
}
return is;
}
示例2: getResourceAsStream
import sun.misc.Resource; //导入依赖的package包/类
public InputStream getResourceAsStream(String resourceName) throws IOException {
InputStream is = null;
Resource resource = myPlatformClasspath.getResource(resourceName, false);
if (resource != null) {
is = new ByteArrayInputStream(resource.getBytes());
}
if (is == null) {
resource = myClasspath.getResource(resourceName, false);
if (resource != null) {
is = new ByteArrayInputStream(resource.getBytes());
}
}
return is;
}
示例3: getResource
import sun.misc.Resource; //导入依赖的package包/类
public Resource getResource(final String name, boolean check) {
URL url = null;
File file = null;
try {
url = new URL(getBaseURL(), name);
if (!url.getFile().startsWith(getBaseURL().getFile())) {
return null;
}
file = new File(myRootDir, name.replace('/', File.separatorChar));
if (!check || file.exists()) { // check means we load or process resource so we check its existence via old way
return new FileResource(name, url, file, !check);
}
}
catch (Exception exception) {
if (!check && file != null && file.exists()) {
try { // we can not open the file if it is directory, Resource still can be created
return new FileResource(name, url, file, false);
}
catch (IOException ex) {
}
}
}
return null;
}
示例4: findClass
import sun.misc.Resource; //导入依赖的package包/类
/**
* Finds and loads the class with the specified name from the URL search
* path. Any URLs referring to JAR files are loaded and opened as needed
* until the class is found.
*
* @param name the name of the class
* @return the resulting class
* @exception ClassNotFoundException if the class could not be found
*/
protected Class<?> findClass(final String name)
throws ClassNotFoundException
{
try {
return (Class)
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws ClassNotFoundException {
String path = name.replace('.', '/').concat(".class");
Resource res = ucp.getResource(path, false);
if (res != null) {
try {
return defineClass(name, res);
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
} else {
throw new ClassNotFoundException(name);
}
}
}, acc);
} catch (java.security.PrivilegedActionException pae) {
throw (ClassNotFoundException) pae.getException();
}
}
示例5: findClass
import sun.misc.Resource; //导入依赖的package包/类
protected Class findClass(final String name) throws ClassNotFoundException {
try {
return (Class) AccessController.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws ClassNotFoundException {
String path = name.replace('.', '/').concat(".class");
Resource res = ucp.getResource(path, false);
if (res != null) {
if (TRACE) System.out.println("Hijacked! " + res);
try {
return defineClass(name, res);
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
} else {
throw new ClassNotFoundException(name);
}
}
}, acc);
} catch (java.security.PrivilegedActionException pae) {
throw (ClassNotFoundException) pae.getException();
}
}
示例6: findClass
import sun.misc.Resource; //导入依赖的package包/类
/**
* Finds and loads the class with the specified name from the URL search
* path. Any URLs referring to JAR files are loaded and opened as needed
* until the class is found.
*
* @param name the name of the class
* @return the resulting class
* @throws ClassNotFoundException if the class could not be found,
* or if the loader is closed.
* @throws NullPointerException if {@code name} is {@code null}.
*/
@Override
@SneakyThrows(ReflectiveOperationException.class)
protected Class<?> findClass(String name)
throws ClassNotFoundException {
String path = name.replace('.', '/') + ".class";
Field ucpField = URLClassLoader.class.getDeclaredField("ucp");
ucpField.setAccessible(true);
Resource res = ((URLClassPath) ucpField.get(this)).getResource(path, false);
if (res != null) {
try {
return defineClass(name, res);
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
} else {
throw new ClassNotFoundException(name);
}
}
示例7: findClass
import sun.misc.Resource; //导入依赖的package包/类
/**
* Finds and loads the class with the specified name from the URL search
* path. Any URLs referring to JAR files are loaded and opened as needed
* until the class is found.
*
* @param name the name of the class
* @return the resulting class
* @exception ClassNotFoundException if the class could not be found,
* or if the loader is closed.
*/
protected Class<?> findClass(final String name)
throws ClassNotFoundException
{
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<Class>() {
public Class run() throws ClassNotFoundException {
String path = name.replace('.', '/').concat(".class");
Resource res = ucp.getResource(path, false);
if (res != null) {
try {
return defineClass(name, res);
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
} else {
throw new ClassNotFoundException(name);
}
}
}, acc);
} catch (java.security.PrivilegedActionException pae) {
throw (ClassNotFoundException) pae.getException();
}
}
示例8: findClass
import sun.misc.Resource; //导入依赖的package包/类
/**
* Finds and loads the class with the specified name from the URL search
* path. Any URLs referring to JAR files are loaded and opened as needed
* until the class is found.
*
* @param name the name of the class
* @return the resulting class
* @exception ClassNotFoundException if the class could not be found,
* or if the loader is closed.
* @exception NullPointerException if {@code name} is {@code null}.
*/
protected Class<?> findClass(final String name)
throws ClassNotFoundException
{
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<Class<?>>() {
public Class<?> run() throws ClassNotFoundException {
String path = name.replace('.', '/').concat(".class");
Resource res = ucp.getResource(path, false);
if (res != null) {
try {
return defineClass(name, res);
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
} else {
throw new ClassNotFoundException(name);
}
}
}, acc);
} catch (java.security.PrivilegedActionException pae) {
throw (ClassNotFoundException) pae.getException();
}
}
示例9: defineClass
import sun.misc.Resource; //导入依赖的package包/类
private Class defineClass(String name, Resource res) throws IOException {
int i = name.lastIndexOf('.');
if (i != -1) {
String pkgname = name.substring(0, i);
// Check if package already loaded.
Package pkg = getPackage(pkgname);
if (pkg == null) {
try {
definePackage(pkgname, null, null, null, null, null, null, null);
}
catch (IllegalArgumentException e) {
// do nothing, package already defined by some other thread
}
}
}
byte[] b = res.getBytes();
return _defineClass(name, b);
}
示例10: doGetSubLoaderByClassContext
import sun.misc.Resource; //导入依赖的package包/类
private SandboxLoader doGetSubLoaderByClassContext(String clazz) {
String path = clazz.replace('.', '/').concat(".class");
for(Entry<URLClassPath, SandboxLoader> e : subLoaderByJar.entrySet()){
Resource res = e.getKey().getResource(path, false);
if (res != null)
return e.getValue();
}
SandboxLoader subLoader = subLoaderCache.get(clazz);
if(null != subLoader)
return subLoader;
for(String prefix : subLoaderPrefixCache.keySet())
if(clazz.startsWith(prefix))
return subLoaderPrefixCache.get(prefix);
return null;
}
示例11: bypassClazz
import sun.misc.Resource; //导入依赖的package包/类
private boolean bypassClazz(String name) {
if(null != enhancer && enhancer.isLoadClassWithApplicationLoader(name))
return true;
if(classesToLoadWithParent.contains(name))
return ! prohibitBypass(name);
for(String bp : classesByPrefixToLoadWithParent)
if(name.startsWith(bp))
return ! prohibitBypass(name);
/* check if it comes from an available jar */
if(! name.startsWith("java.") && null != bypassUcp){
String path = name.replace('.', '/').concat(".class");
Resource res = bypassUcp.getResource(path, false);
if (res != null)
return ! prohibitBypass(name);
}
return false;
}
示例12: getBootstrapResources
import sun.misc.Resource; //导入依赖的package包/类
/**
* Replica of parent {@link URLClassLoader} and {@link ClassLoader} class
* method for other method
*
* @return {@link URL}
*/
private static Enumeration<URL> getBootstrapResources(String name) throws IOException {
Enumeration<URL> urls;
// Enumeration to iterate over
final Enumeration<Resource> resources = getBootstrapsResources(name);
urls = new Enumeration<URL>() {
public URL nextElement() {
return (resources.nextElement()).getURL();
}
public boolean hasMoreElements() {
return resources.hasMoreElements();
}
};
return urls;
}
示例13: getBootstrapResources
import sun.misc.Resource; //导入依赖的package包/类
/**
* Find resources from the VM's built-in classloader.
*/
private static Enumeration<URL> getBootstrapResources(String name)
throws IOException
{
final Enumeration<Resource> e =
getBootstrapClassPath().getResources(name);
return new Enumeration<URL> () {
public URL nextElement() {
return e.nextElement().getURL();
}
public boolean hasMoreElements() {
return e.hasMoreElements();
}
};
}
示例14: findClass
import sun.misc.Resource; //导入依赖的package包/类
/**
* Finds and loads the class with the specified name from the URL search
* path. Any URLs referring to JAR files are loaded and opened as needed
* until the class is found.
*
* @param name the name of the class
* @return the resulting class
* @exception ClassNotFoundException if the class could not be found,
* or if the loader is closed.
* @exception NullPointerException if {@code name} is {@code null}.
*/
protected Class<?> findClass(final String name)
throws ClassNotFoundException
{
final Class<?> result;
try {
result = AccessController.doPrivileged(
new PrivilegedExceptionAction<Class<?>>() {
public Class<?> run() throws ClassNotFoundException {
String path = name.replace('.', '/').concat(".class");
Resource res = ucp.getResource(path, false);
if (res != null) {
try {
return defineClass(name, res);
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
} else {
return null;
}
}
}, acc);
} catch (java.security.PrivilegedActionException pae) {
throw (ClassNotFoundException) pae.getException();
}
if (result == null) {
throw new ClassNotFoundException(name);
}
return result;
}
示例15: getBootstrapResources
import sun.misc.Resource; //导入依赖的package包/类
/**
* Find resources from the VM's built-in classloader.
*/
private static Enumeration getBootstrapResources(String name)
throws IOException
{
final Enumeration e = getBootstrapClassPath().getResources(name);
return new Enumeration () {
public Object nextElement() {
return ((Resource)e.nextElement()).getURL();
}
public boolean hasMoreElements() {
return e.hasMoreElements();
}
};
}