获取resource

@param location resource位置，支持协议参照{@link ResourceProtocol ResourceProtocol}，如果没有指定协议那么默认从classpath中获取
@return 对应的resource
@throws ResourceNotFoundException 当资源不存在时抛出该异常
961056
public static InputStream getResource(String location) throws ResourceNotFoundException {
        if (StringUtils.isEmpty(location)) {
            throw new NullPointerException("location must not be null");
        }
        log.debug("获取资源[{}]", location);
        try {
            if (location.startsWith(ResourceProtocol.FILE.protocol)) {
                return new FileInputStream(
                    new File(location.substring(ResourceProtocol.FILE.protocol.length())));
            } else if (location.startsWith(ResourceProtocol.URL.protocol)) {
                return new URL(location.substring(ResourceProtocol.URL.protocol.length()))
                    .openStream();
            } else if (location.startsWith(ResourceProtocol.HTTP.protocol)) {
                return new URL(location.substring(ResourceProtocol.HTTP.protocol.length()))
                    .openStream();
            } else if (location.startsWith(ResourceProtocol.HTTPS.protocol)) {
                return new URL(location.substring(ResourceProtocol.HTTPS.protocol.length()))
                    .openStream();
            } else {
                if (location.startsWith(ResourceProtocol.CLASSPATH.protocol)) {
                    location = location.substring(ResourceProtocol.CLASSPATH.protocol.length());
                }
                return Thread.currentThread().getContextClassLoader().getResourceAsStream(location);
            }
        } catch (Throwable e) {
            log.error("资源[{}]获取失败", location, e);
            throw new ResourceNotFoundException("查找资源[" + location + "]异常", e);
        }
    }
998603
public static location get(nitro_service service, String ipfrom) throws Exception{
		location obj = new location();
		obj.set_ipfrom(ipfrom);
		location response = (location) obj.get_resource(service);
		return response;
	}
50859
public static URL getResource(String resource, Class<?> baseClass) {
		return (null != baseClass) ? baseClass.getResource(resource) : ClassLoaderUtil.getClassLoader().getResource(resource);
	}
141802
@Override
    public File locateResource( String name ) {
        for (int i = 0; i < resourcePath.length; i++) {
            File fi = new File(resourcePath[i].getAbsolutePath()+File.separator+name);
            if ( fi.exists() )
                return fi;
        }
        return null;
    }
1084394
public static ResourceAddress.ResourceVersionedIdentifier parseCreateLocation(String locationResponseHeader) {
		Pattern pattern = Pattern.compile(REGEX_ID_WITH_HISTORY);
		Matcher matcher = pattern.matcher(locationResponseHeader);
		ResourceVersionedIdentifier parsedHeader = null;
		if(matcher.matches()){
			String serviceRoot = matcher.group(1);
			String resourceType = matcher.group(3);
			String id = matcher.group(5);
			String version = matcher.group(7);
			parsedHeader = new ResourceVersionedIdentifier(serviceRoot, resourceType, id, version);
		}
		return parsedHeader;
	}
1004591
@Override
    public File findFile(RepositoryPointerImpl location) {
        // Assume that instanceIds are good and check fileId only.
        File result = getChild(location.getFileId());
        return isFile(result) ? result : null;
    }
283033
@Override
    public InputStream getResourceStream (String path)
        throws ResourceNotFoundException
    {
        SiteKey skey = new SiteKey(path);

        // load it on up
        try {
            InputStream stream = _loader.getResourceAsStream(
                skey.siteId, skey.path);
            if (stream == null) {
                String errmsg = "Unable to load resource via " +
                    "site-specific jar file [path=" + path + "].";
                throw new ResourceNotFoundException(errmsg);
            }
            return stream;

        } catch (IOException ioe) {
            throw new ResourceNotFoundException(ioe.getMessage());
        }
    }
401393
public static InputStream getRequiredResourceAsStream(Class<?> clzz, String location) {
        InputStream resourceStream = clzz.getResourceAsStream(location);

        if (resourceStream == null) {
            // Try with a leading "/"
            if (!location.startsWith("/")) {
                resourceStream = clzz.getResourceAsStream("/" + location);
            }
            if (resourceStream == null) {
                throw new RuntimeException("Resource file was not found at location " + location);
            }
        }

        return resourceStream;
    }
564990
public static TypeAnnotationPosition
        resourceVariable(final List<TypePathEntry> location,
                         final JCLambda onLambda,
                         final int pos) {
        return new TypeAnnotationPosition(TargetType.RESOURCE_VARIABLE, pos,
                                          Integer.MIN_VALUE, onLambda,
                                          Integer.MIN_VALUE, Integer.MIN_VALUE,
                                          location);
    }
729948
public static Provider resourceProvider(ClassLoader classLoader, String pathToResource, Charset encoding) throws IOException {
        InputStream resourceAsStream = classLoader.getResourceAsStream(pathToResource);
        if (resourceAsStream == null) {
            throw new IOException("Cannot find " + pathToResource);
        }
        return provider(resourceAsStream, encoding);
    }
579298
public T loadXml(String locationUrl) {

    DataResource resource = this.resourceFactory.createDataResource(locationUrl);
    return loadXml(resource);
  }
38827
public static boolean isAbsoluteUrl(String location) {
        if (location != null && location.length() > 0 && location.contains(":")) {
            try {
                URI uri = new URI(location);
                return uri.getScheme() != null;
            } catch (URISyntaxException e) {
                // ignore invalid locations and consider not absolute
            }
        }
        return false;
    }
769836
public void setPropertiesLocation(String location) {
        Properties properties = load(null, new PathMatchingResourcePatternResolver(), location);
        if (properties != null && properties.size() > 0) {
            configure(properties);
        }
    }
759635
public static String getResourceLocation(String resourceId)
	{
		Resource resource = getResource(resourceId);
    	return resource.getDataLocation();
	}
571337
public static String resourceFileToString(final String location, final String fileName) {
        if (location == null || fileName == null) return null;

        final InputStream in = ResourceUtilities.class.getResourceAsStream(location + fileName);
        if (in == null) return null;

        final BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String line;
        final StringBuilder output = new StringBuilder("");
        try {
            while ((line = br.readLine()) != null) {
                output.append(line + "\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                LOG.error("Failed to close the InputStream", e);
            }
            try {
                br.close();
            } catch (IOException e) {
                LOG.error("Failed to close the BufferedReader", e);
            }
        }
        return output.toString();
    }
564893
public static URL getResource(String ref) {

		URL url = null;
		
		for (int i=0;i<locations.size();i++) {
			ResourceLocation location = (ResourceLocation) locations.get(i);
			url = location.getResource(ref);
			if (url != null) {
				break;
			}
		}
		
		if (url == null)
		{
			throw new RuntimeException("Resource not found: "+ref);
		}
			
		return url;
	}
1119274
public static URL locateOnClasspath(String resourceName) {
        URL url = null;

        // attempt to load from the context classpath
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if (loader != null) {
            url = loader.getResource(resourceName);

            if (url != null) {
                log.debug("Located '{}' in the context classpath", resourceName);
            }
        }

        // attempt to load from the system classpath
        if (url == null) {
            url = ClassLoader.getSystemResource(resourceName);

            if (url != null) {
                log.debug("Located '{}' in the system classpath", resourceName);
            }
        }

        return url;
    }