• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Resource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中sun.misc.Resource的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Resource类属于sun.misc包,在下文中一共展示了Resource类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:InstrumentationClassFinder.java


示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:InstrumentationClassFinder.java


示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:InstrumentationClassFinder.java


示例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();
}
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:34,代码来源:URLClassLoader.java


示例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();
    }
}
 
开发者ID:petablox-project,项目名称:petablox,代码行数:24,代码来源:HijackingClassLoader.java


示例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);
    }
}
 
开发者ID:yawkat,项目名称:mdep,代码行数:31,代码来源:ParentLastURLClassLoader.java


示例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();
    }
}
 
开发者ID:ZhaoX,项目名称:jdk-1.7-annotated,代码行数:35,代码来源:URLClassLoader.java


示例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();
    }
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:36,代码来源:URLClassLoader.java


示例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);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:UrlClassLoader.java


示例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;
}
 
开发者ID:csm,项目名称:java-sandbox,代码行数:19,代码来源:SandboxLoader.java


示例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;
}
 
开发者ID:csm,项目名称:java-sandbox,代码行数:22,代码来源:SandboxLoader.java


示例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;
}
 
开发者ID:levants,项目名称:lightmare,代码行数:26,代码来源:EjbClassLoader.java


示例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();
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:ClassLoader.java


示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:URLClassLoader.java


示例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();
    }
};
   }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:aClassLoader.java


示例16: getResource

import sun.misc.Resource; //导入依赖的package包/类
@Override
public Resource getResource(String name) {
    final String originalName = name;
    if (name.equals(SA_JDI_PROPERTIES_FILE_NAME)
            || name.startsWith(SA_JDI_PACKAGE_PREFIX)) {
        name = SA_JDI_JVM_PREFIX + "/" + name;
    }
    return new DelegatedResource(originalName, super.getResource(name));
}
 
开发者ID:serkan-ozal,项目名称:jemstone,代码行数:10,代码来源:HotSpotJvmAwareSaJdiClassLoader.java



注:本文中的sun.misc.Resource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Rect类代码示例发布时间:2022-05-21
下一篇:
Java AbstractSession类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap