Loads a resource as {@link InputStream}.

@param resource
The resource to be loaded. If {@code baseDir} is not {@code null}, it is loaded
relative to {@code baseDir}.
@return The stream
329161
public static InputStream getInputStream(final File resource) throws IOException {
		if (resource.exists()) {
			return new FileInputStream(resource);
		}
		LOG.info("Could not find file '" + resource.getAbsolutePath() + "' in the file system. Trying to load it from the classpath...");

		String path = FilenameUtils.separatorsToUnix(resource.getPath());
		ClassLoader cl = Thread.currentThread().getContextClassLoader();

		InputStream is = cl.getResourceAsStream(path);

		if (is == null) {
			if (path.startsWith("/")) {
				LOG.info("Could not find file '" + resource
						+ " in the file system. Trying to load it from the classpath without the leading slash...");
				is = cl.getResourceAsStream(path.substring(1));
			}

			if (is == null) {
				// If configs are to be loaded from the classpath, we also try it directly
				// stripping of the config directory
				String configDir = new File(getConfigDir()).getName();
				if (path.startsWith(configDir)) {
					is = cl.getResourceAsStream(StringUtils.substringAfter(path, configDir + '/'));
				}
			}

			if (is == null) {
				throw new FileNotFoundException("Could not load file '" + resource + "'");
			}
		}

		return is;
	}
729989
private T loadResourceValue(final URL resource)
	{
		try (final InputStream is = resource.openStream())
		{
			cached = null; // Prevent the old value from being used

			return setCached(clazz.cast(factory.getInstance(clazz).deserialise(is)));
		}
		catch (IOException e)
		{
			throw new RuntimeException("Error loading JAXB resource " + name + " " + clazz + " from " + resource, e);
		}
	}
459820
private static InputStream inputStreamFromFile(URL resourceUrl)
      throws IOException, URISyntaxException {
    File resourceFile = new File(resourceUrl.toURI());
    return new FileInputStream(resourceFile);
  }
347179
public static InputStream getStream(URL url) {
		Assert.notNull(url);
		try {
			return url.openStream();
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
219083
protected Properties loadProperties(Resource resource, String filename) throws IOException {
		InputStream is = resource.getInputStream();
		Properties props = new Properties();
		try {
			if (resource.getFilename().endsWith(XML_SUFFIX)) {
				if (logger.isDebugEnabled()) {
					logger.debug("Loading properties [" + resource.getFilename() + "]");
				}
				this.propertiesPersister.loadFromXml(props, is);
			}
			else {
				String encoding = null;
				if (this.fileEncodings != null) {
					encoding = this.fileEncodings.getProperty(filename);
				}
				if (encoding == null) {
					encoding = this.defaultEncoding;
				}
				if (encoding != null) {
					if (logger.isDebugEnabled()) {
						logger.debug("Loading properties [" + resource.getFilename() + "] with encoding '" + encoding + "'");
					}
					this.propertiesPersister.load(props, new InputStreamReader(is, encoding));
				}
				else {
					if (logger.isDebugEnabled()) {
						logger.debug("Loading properties [" + resource.getFilename() + "]");
					}
					this.propertiesPersister.load(props, is);
				}
			}
			return props;
		}
		finally {
			is.close();
		}
	}
202271
public static String getResourceAsString(Class<?> clazz, String resource) throws IOException {
        try (InputStream inputStream = clazz.getResourceAsStream(resource)) {
            return IoUtils.toString(inputStream);
        }
    }
665125
public static String getResourceURL(String resource) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        return cl.getResource(resource).toString();
    }
1093302
public static Properties readPropertiesFromClassLoader(String resource) {
        Properties properties = new Properties();
        try {
            properties.load(FsCrawlerUtil.class.getClassLoader().getResourceAsStream(resource));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return properties;
    }
946401
public static List<URL> getResources(String resource) {
		final Enumeration<URL> resources;
		try {
			resources = ClassLoaderUtil.getClassLoader().getResources(resource);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
		return CollectionUtil.newArrayList(resources);
	}
175723
public static Resource newSystemResource(String resource)
        throws IOException
    {
        URL url=null;
        // Try to format as a URL?
        ClassLoader
            loader=Thread.currentThread().getContextClassLoader();
        if (loader!=null)
        {
            url=loader.getResource(resource);
            if (url==null && resource.startsWith("/"))
                url=loader.getResource(resource.substring(1));
        }
        if (url==null)
        {
            loader=Resource.class.getClassLoader();
            if (loader!=null)
            {
                url=loader.getResource(resource);
                if (url==null && resource.startsWith("/"))
                    url=loader.getResource(resource.substring(1));
            }
        }
        
        if (url==null)
        {
            url=ClassLoader.getSystemResource(resource);
            if (url==null && resource.startsWith("/"))
                url=loader.getResource(resource.substring(1));
        }
        
        if (url==null)
            return null;
        
        return newResource(url);
    }
174131
@Override
	public InputStream createResourceAsStream(GeneratorContext context) {

		String path = context.getPath();
		InputStream is = null;
		if (FileNameUtils.hasImageExtension(path)) {
			try {
				is = context.getResourceReaderHandler().getResourceAsStream(path, false);
			} catch (ResourceNotFoundException e) {
				// Nothing to do
			}
		}

		return is;
	}
924208
public static InputStream inputStream(URL url) {
        try {
            return url.openStream();
        } catch (IOException e) {
            throw E.ioException(e);
        }
    }
179834
public static InputStream getResourceStream(final String path) {
		final ClassLoader loader = Resources.class.getClassLoader();
		return loader.getResourceAsStream(path);
	}
221971
@SuppressWarnings("resource")
    private InputStream openResource(String name) throws IOException {
        InputStream in;
        if (iFileDir != null) {
            in = new FileInputStream(new File(iFileDir, name));
        } else {
            final String path = iResourcePath.concat(name);
            in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
                public InputStream run() {
                    if (iLoader != null) {
                        return iLoader.getResourceAsStream(path);
                    } else {
                        return ClassLoader.getSystemResourceAsStream(path);
                    }
                }
            });
            if (in == null) {
                StringBuilder buf = new StringBuilder(40)
                    .append("Resource not found: \"")
                    .append(path)
                    .append("\" ClassLoader: ")
                    .append(iLoader != null ? iLoader.toString() : "system");
                throw new IOException(buf.toString());
            }
        }
        return in;
    }
260230
public static InputStream getResourceAsStream(String ref) {
		InputStream in = null;
		
		for (int i=0;i<locations.size();i++) {
			ResourceLocation location = (ResourceLocation) locations.get(i);
			in = location.getResourceAsStream(ref);
			if (in != null) {
				break;
			}
		}
		
		if (in == null)
		{
			throw new RuntimeException("Resource not found: "+ref);
		}
			
		return new BufferedInputStream(in);
	}
928784
public void createResource(final InputStream inputStream, final String resourceName)
        throws JaxRxException {
        synchronized (resourceName) {
            if (inputStream == null) {
                throw new JaxRxException(400, "Bad user request");
            } else {
                try {
                    shred(inputStream, resourceName);
                } catch (final TTException exce) {
                    throw new JaxRxException(exce);
                }
            }
        }
    }
925636
@Override
  public InputStream getResourceAsStream(String name)
  {
    ResourceEntry entry = _resourceCacheMap.get(name);
    
    if (entry == null || entry.isModified()) {
      URL resource = super.getResource(name);
    
      entry = new ResourceEntry(resource);
    
      _resourceCacheMap.put(name, entry);
    }
    
    return entry.getResourceAsStream();
  }