Does resource exist?

@param resource       the resource
@param resourceLoader the resource loader
@return the boolean
327669
public static boolean doesResourceExist(final String resource, final ResourceLoader resourceLoader) {
        try {
            if (StringUtils.isNotBlank(resource)) {
                val res = resourceLoader.getResource(resource);
                return doesResourceExist(res);
            }
        } catch (final Exception e) {
            LOGGER.warn(e.getMessage(), e);
        }
        return false;
    }
709653
public static InputStream getResourceAsStream(String resource) {
        InputStream in = ClassUtils.getContextClassLoader().getResourceAsStream(resource);
        if (in == null) {
            in = IOUtils.class.getResourceAsStream(resource);
        }

        return in;
    }
544420
public static boolean doesResourceExist(final Resource res) {
        if (res != null) {
            try {
                IOUtils.read(res.getInputStream(), new byte[1]);
                return res.contentLength() > 0;
            } catch (final FileNotFoundException e) {
                LOGGER.trace(e.getMessage());
                return false;
            } catch (final Exception e) {
                LOGGER.trace(e.getMessage(), e);
                return false;
            }
        }
        return false;
    }
544606
@SuppressWarnings("static-method")
	protected boolean isSourceFile(Resource resource) {
		if (resource instanceof BatchLinkableResource) {
			return !((BatchLinkableResource) resource).isLoadedFromStorage();
		}
		return false;
	}
86446
@Override
  public boolean resourceExists(String path) {
    String completePath = getCompleteResourceUrl(path);
    return ResourceDataBroker.class.getResource(completePath) != null;
  }
44025
private void load(final String resourceName) {
		boolean found = false;

		try {
			resources.push(resourceName);

			// Try classloader - load the resources in reverse order of the enumeration.  Since later-loaded resources
			// override earlier-loaded ones, this better corresponds to the usual classpath behaviour.
			ClassLoader classloader = getParamsClassLoader();
			List<URL> urls = new ArrayList<>();

			for (Enumeration<URL> res = classloader.getResources(resourceName); res.
					hasMoreElements();) {
				urls.add(res.nextElement());
			}

			recordMessage("Resource " + resourceName + " was found  " + urls.size() + " times");

			// Sometimes the same URL will crop up several times (because of redundant entries in classpaths).  Also,
			// sometimes the same file appears under several URLS (because it's packaged into a jar and also a classes
			// directory, perhaps). In these circumstances we really only want to load the resource once - we load the
			// first one and then ignore later ones.
			Map<String, String> loadedFiles = new HashMap<>();

			// Build up a list of the byte arrays from the files that we then process.
			List<byte[]> contentsList = new ArrayList<>();
			List<URL> urlList = new ArrayList<>();

			// This processes from the front-of-classpath to end-of-classpath since end-of-classpath ones appear last in
			// the enumeration
			for (int i = 0; i < urls.size(); i++) {
				URL url = urls.get(i);
				found = true;

				// Load the contents of the resource, for comparison with existing resources.
				InputStream urlContentStream = url.openStream();
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				StreamUtil.copy(urlContentStream, baos);
				urlContentStream.close();
				byte[] urlContentBytes = baos.toByteArray();
				String urlContent = new String(urlContentBytes, "UTF-8");

				// Check if we have already loaded this file.
				if (loadedFiles.keySet().contains(urlContent)) {
					recordMessage("Skipped url " + url + " - duplicate of " + loadedFiles.get(urlContent));
					continue;
				}

				loadedFiles.put(urlContent, url.toString());
				contentsList.add(urlContentBytes);
				urlList.add(url);
			}

			for (int i = contentsList.size() - 1; i >= 0; i--) {
				byte[] buff = contentsList.get(i);
				URL url = urlList.get(i);
				recordMessage("Loading from url " + url + "...");
				ByteArrayInputStream in = new ByteArrayInputStream(buff);

				// Use the "IncludeProperties" to load properties into us one at a time....
				IncludeProperties properties = new IncludeProperties(url.toString());
				properties.load(in);
			}

			File file = new File(resourceName);

			// Don't reload the file in the working directory if we are in the home directory.
			if (file.exists()) {
				recordMessage("Loading from file " + filename(file) + "...");
				found = true;

				// Use the "IncludeProperties" to load properties into us, one at a time....
				IncludeProperties properties = new IncludeProperties("file:" + filename(file));
				properties.load(new BufferedInputStream(new FileInputStream(file)));
			}

			if (!found) {
				recordMessage("Did not find resource " + resourceName);
			}
		} catch (IOException ex) {
			// This is bad.
			recordException(ex);
		} catch (IllegalArgumentException ex) {
			// Most likely a "Malformed uxxxx encoding." error, which is
			// usually caused by a developer forgetting to escape backslashes
			recordException(ex);
		} finally {
			resources.pop();
		}
	}
293287
private boolean isInPaths(final CmsResource resource) {

        boolean result = false;
        String resourcePath = getCms().getSitePath(resource);
        for (String path : m_paths) {
            if (resourcePath.startsWith(path)) {
                result = true;
                break;
            }
        }
        return result;

    }
510018
protected Reader createResourceReader(Resource resource) {
        try {
            return new InputStreamReader(resource.getInputStream());
        }
        catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
665125
public static String getResourceURL(String resource) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        return cl.getResource(resource).toString();
    }
672703
public static EnumerationIter<URL> getResourceIter(String resource) {
		final Enumeration<URL> resources;
		try {
			resources = ClassLoaderUtil.getClassLoader().getResources(resource);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
		return new EnumerationIter<>(resources);
	}
949575
protected void validateResourceState(Resource resource) {
		if (resource instanceof StorageAwareResource && ((StorageAwareResource) resource).isLoadedFromStorage()) {
			LOG.error("Discouraged attempt to compute types for resource that was loaded from storage. Resource was : "+resource.getURI(), new Exception());
		}
	}
275372
public boolean isAvailable(String resource) {
        final boolean isAnyTraceEnabled = com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled();
        if (isAnyTraceEnabled && logger.isLoggable(Level.FINER)) {
            logger.entering(CLASS_NAME, "isAvailable", "resource [" + resource + "] ");
        } //d651265
        boolean available = false;
        // not sure if needed; after first check for isAvailable, welcome file
        // goes directly to wrapper; can this ever be true?
        RequestProcessor rp = extensionContext.getMappingTarget(resource);
        available = (rp instanceof IServletWrapper); // true if wrapper has
                                                     // already been created.

        if (available == false) {
            if (jspOptions.isDisableJspRuntimeCompilation() == false) {
                try {
                    available = handleCaseSensitivityCheck(resource, false); //PK81387 - passing false
                } catch (IOException io) {
                    available = false;
                }
            } else {
                JspInputSource inputSource = context.getJspInputSourceFactory().createJspInputSource(resource);
                JspResources jspResources = context.getJspResourcesFactory().createJspResources(inputSource);

                String classname = jspResources.getClassName();
                String generatedSourceDir = jspResources.getGeneratedSourceFile().getParent();
                if (generatedSourceDir.endsWith(File.separator) == false) {
                    generatedSourceDir = generatedSourceDir + File.separator;
                }
                File tempDirJSP = new File(generatedSourceDir + classname + ".class");
                available = tempDirJSP.exists();

                if (available == false) {

                    String jspUri = inputSource.getRelativeURL();
                    if (jspUri.charAt(0) != '/') {
                        jspUri = "/" + jspUri;
                    }
                    String webinfClassFilePath = null;
                    File webinfClassFile = null;
                    String packageName = null;
                    if (jspOptions.isUseFullPackageNames() == false) {
                        webinfClassFilePath = context.getRealPath("/WEB-INF/classes") + jspUri.substring(0, jspUri.lastIndexOf("/") + 1);
                        webinfClassFile = new File(webinfClassFilePath + File.separator + classname + ".class");
                    } else {
                        packageName = jspResources.getPackageName();
                        String packageDir = packageName.replace('.', '/');
                        webinfClassFilePath = context.getRealPath("/WEB-INF/classes") + "/" + packageDir;
                        webinfClassFile = new File(webinfClassFilePath + File.separator + classname + ".class");
                    }
                    available = webinfClassFile.exists();
                }
            }
        }
        if (isAnyTraceEnabled && logger.isLoggable(Level.FINE)) {
            logger.exiting(CLASS_NAME, "isAvailable", "resource [" + resource + "] is available? [" + available + "]");
        } //d651265
        return available;

    }
1162443
def resource_exists(self, slug, locale, project_slug=None):
        """"""

        try:
            resource = resources.Resource.get(
                project_slug=project_slug or self.get_project_slug(locale),
                slug=slug,
            )

            return resource

        except NotFoundError:
            pass

        return None
563593
public static boolean resourceExists(String name) {
        Objects.requireNonNull(name, Required.NAME.toString());
        
        URL resource = null;
        try {
            resource = Resources.getResource(name);            
        } catch (IllegalArgumentException e) { // NOSONAR Intentionally not logging or throwing this exception
           // Intentionally left blank
        }
        
        return resource != null;
    }
491252
public boolean isAvailable (String resource){
	    
	    Container c = _webapp.getModuleContainer();
	    if(c != null){
	       Entry entry = c.getEntry(resource); 
	       if(entry != null){
	           return true;
	       }
	       return isAvailableInDocumentRoot(resource,WCCustomProperties.SERVE_WELCOME_FILE_FROM_EDR);
	    }
	    
	    String tempFileString = _webapp.getRealPath(resource);
	    boolean available = false;
	    if (tempFileString != null) { 
	        File caseFile = new Java2SecurityFile(tempFileString);
		available = caseFile.exists();
		if (available && com.ibm.ws.util.FileSystem.isCaseInsensitive) {
			try{
				available = com.ibm.ws.util.FileSystem.uriCaseCheck(caseFile, resource);
			}catch (IOException io){
				available = false;
			}
		}
        }
		
	    if (!available)
	    	available = isAvailableInDocumentRoot(resource,WCCustomProperties.SERVE_WELCOME_FILE_FROM_EDR);			
		
        return available;
	}
426899
protected boolean isInConditionResource(String resource){
		Resource sqlResource = context.getResource(resource);
		InputStream in = null;
		String sql = null;
		try{
			in = sqlResource.getInputStream();
			sql = IOUtils.toString(in);
		} catch(IOException ioe){
			throw new RuntimeException("Failed to get condition SQL (" + ioe.getMessage() + ") from: " + resource, ioe);
		}finally{
			IOUtils.closeQuietly(in);
		}
		if (StringUtils.isNotBlank(sql)){
			return isInCondition(sql);
		}else{
			return true;
		}
	}
1247617
public static boolean resourceExists(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) {
				return true;
			}
		}
		
		return false;
	}