Find the File for the resource file in the various source directories.

@param sourceDirectories List of directories to scan
@param resourceFileName File name of resource file
@return The resolved File
@throws IOException If the File cannot be found
11618
protected File findFile(final List<File> sourceDirectories, String resourceFileName) throws IOException {
	    for (final File sourceDirectory : sourceDirectories) {
	        final File resourceFile = new File(sourceDirectory, resourceFileName);
	        if (resourceFile.exists()) {
	            return resourceFile;
	        }
	    }
	    
	    throw new IOException("Failed to find resource " + resourceFileName + " in any of the source directories: " + sourceDirectories);
	}
401537
public static String locateOrCreateDirectory(String dirName) throws IOException {
    String path = locateDirectory(dirName);

    if (path == null) {
      File file = new File(dirName);
      file.mkdirs();
      path = file.getCanonicalPath();
    }

    return path;
  }
626122
@Override
  public JarEntryDirectoryImpl getOrCreateDirectory(String relativeName) {
    IResource resource = _resources.get(relativeName);
    if(resource instanceof IFile){
      throw new UnsupportedOperationException("The requested resource " + relativeName + " is now being accessed as a directory, but was previously accessed as a file.");
    }
    JarEntryDirectoryImpl result = (JarEntryDirectoryImpl) resource;
    if (result == null) {
      result = new JarEntryDirectoryImpl(relativeName, this, this);
      _resources.put(relativeName, result);
      _childDirs.add(result);
    }
    return result;
  }
1140177
private String readResource(final String resourceName) throws IOException {
      return new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(resourceName), DEFAULT_CHARSET)).lines().collect(Collectors.joining("\n"));
   }
971280
@Nullable
  public static InputStream findInputStreamForResource(@Nonnull final ZipFile zipFile, @Nonnull final String resourcePath) throws IOException {
    final ZipEntry entry = zipFile.getEntry(resourcePath);

    InputStream result = null;

    if (entry != null && !entry.isDirectory()) {
      result = zipFile.getInputStream(entry);
    }

    return result;
  }
453161
public RepositoryFile getRepositoryFile() throws ResourceException {
        if (_fileRef == null || _fileRef.get() == null) {
            throw new ResourceException(this, "RepositoryFile '" + _qualifiedPath
                    + "' is not available since it was not serializable. The RepositoryFileResource instance can "
                    + "be recreated using a live repository and the qualified path of the file.");
        }
        return _fileRef.get();
    }
710534
public static void retrieve(String[] resources, File destDir) {

        for (String res : resources) {
            try {
                URL resUrl = ResourceUtils.getURL("classpath:" + res);
                File destFile = new File(destDir, res);
                if (destFile.exists()) {
                    continue;
                }
                LOG.info("guidance.file.open", destFile.getAbsolutePath());
                FileUtils.copyURLToFile(resUrl, destFile);
            } catch (IOException e) {
                LOG.warn("guidance.file.open.error", e);
            } catch (Exception exp) {
                LOG.warn("proxy.error", exp);
            }
        }

    }
398219
public void getResources(Vector<URL> resources, String name)
  {
    Path path;

    path = getPath(name);

    if (path != null && path.canRead()) {
      try {
        resources.add(path.getNetURL());
      } catch (Exception e) {
      }
    }
  }
925608
private List<SourceFile> findJavaScriptFiles(ResourceCollection rc) {
    List<SourceFile> files = new ArrayList<>();
    Iterator<Resource> iter = rc.iterator();
    while (iter.hasNext()) {
      FileResource fr = (FileResource) iter.next();
      // Construct path to file, relative to current working directory.
      java.nio.file.Path path = Paths.get("").toAbsolutePath().relativize(fr.getFile().toPath());
      files.add(SourceFile.fromPath(path, Charset.forName(encoding)));
    }
    return files;
  }
939795
private void createResourceFolder() throws IOException {
        if(!Files.exists(resourceLocation.toPath()))
            Files.createDirectories(resourceLocation.toPath());
    }
325936
public URL findResource(String fileName) {
		Object location = this.mixedResourceLocations.get(fileName);
		if (location == null) {
			return super.findResource(fileName);
		}
		String url;
		if (location instanceof File) {
			url = "file:/" + FileSupport.convertToUnixStylePath(((File) location).getAbsolutePath());
		} else {
			url = "jar:file:" + FileSupport.convertToUnixStylePath((String) location) + "!/" + fileName;
		}
		try {
			return new URL(url);
		} catch (MalformedURLException e) {
			throw new ResourceException(e);
		}
	}
172202
@Override
	public Set<InputStream> getResourcesAsStream(final String path) throws IOException
	{
		// For local paths, try to resolve the path relative to the folder of the master file
		// N.B. Assumes paths are sensible, not .//someFile.xml
		if (path.startsWith("./"))
		{
			final Set<InputStream> streams = inner.getResourcesAsStream(folder + path.substring(2));

			if (streams != null && !streams.isEmpty())
				return streams;
		}

		return inner.getResourcesAsStream(path);
	}
744968
public static void copyResourceFile(String source, Path target) throws IOException {
        InputStream resource = FsCrawlerUtil.class.getResourceAsStream(source);
        FileUtils.copyInputStreamToFile(resource, target.toFile());
    }
170357
public static PropertyFile find(final ClassLoader classloader, final String... fileNames)
	{
		URL resolvedResource = null;
		String resolvedFile = null;

		for (String fileName : fileNames)
		{
			if (fileName.charAt(0) == '/')
			{
				File file = new File(fileName);

				if (file.exists())
				{
					try
					{
						return PropertyFile.readOnly(file);
					}
					catch (IOException e)
					{
						throw new IllegalArgumentException("Error loading property file: " +
						                                   fileName +
						                                   ". Error: " +
						                                   e.getMessage(), e);
					}
				}
			}
			else
			{
				// Try to resolve the filename (for logging any errors)
				final URL resource = classloader.getResource(fileName);

				if (resource != null)
				{
					resolvedFile = fileName;
					resolvedResource = resource;
					break;
				}
			}
		}

		if (resolvedFile == null)
		{
			if (fileNames.length == 1)
				throw new IllegalArgumentException("Error finding property file in classpath: " + fileNames[0]);
			else
				throw new IllegalArgumentException("Error finding property files in classpath: " + Arrays.asList(fileNames));
		}
		else if (log.isInfoEnabled())
			log.info("{find} Loading properties from " + resolvedFile);

		return openResource(classloader, resolvedResource, resolvedFile);
	}
40308
public InputStream getResourceAsStream(String resourceName) {
		InputStream is = null;
		String realPath = getRealResourcePath(resourceName);
		if (isFileSystemPath(resourceName, realPath)) { // The resource has been
														// remapped to a file
														// system path
			try {
				is = new FileInputStream(realPath);
			} catch (FileNotFoundException e) {
				LOGGER.debug("The resource " + realPath + " has not been found");
			}
		}
		if (is == null) {
			is = super.getResourceAsStream(realPath);
		}
		return is;
	}
716372
public List<ResourceRef> getClassesFolderResources() throws IOException {
        if (classesFolderResources == null) {
            if (logger.isInfoEnabled()) {
                logger.info("[classesFolder] start to found available classes folders ...");
            }
            List<ResourceRef> classesFolderResources = new ArrayList<ResourceRef>();
            Enumeration<URL> founds = resourcePatternResolver.getClassLoader().getResources("");
            while (founds.hasMoreElements()) {
                URL urlObject = founds.nextElement();
                if (!"file".equals(urlObject.getProtocol())) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("[classesFolder] Ignored classes folder because "
                                + "not a file protocol url: " + urlObject);
                    }
                    continue;
                }
                String path = urlObject.getPath();
                Assert.isTrue(path.endsWith("/"));
//                if (!path.endsWith("/classes/") && !path.endsWith("/bin/")) {
//                    if (logger.isInfoEnabled()) {
//                        logger.info("[classesFolder] Ignored classes folder because "
//                                + "not ends with '/classes/' or '/bin/': " + urlObject);
//                    }
//                    continue;
//                }
                File file;
                try {
                    file = new File(urlObject.toURI());
                } catch (URISyntaxException e) {
                    throw new IOException(e);
                }
                if (file.isFile()) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("[classesFolder] Ignored because not a directory: "
                                + urlObject);
                    }
                    continue;
                }
                Resource resource = new FileSystemResource(file);
                ResourceRef resourceRef = ResourceRef.toResourceRef(resource);
                if (classesFolderResources.contains(resourceRef)) {
                    // 删除重复的地址
                    if (logger.isDebugEnabled()) {
                        logger.debug("[classesFolder] remove replicated classes folder: "
                                + resourceRef);
                    }
                } else {
                    classesFolderResources.add(resourceRef);
                    if (logger.isDebugEnabled()) {
                        logger.debug("[classesFolder] add classes folder: " + resourceRef);
                    }
                }
            }
            // 删除含有一个地址包含另外一个地址的
            Collections.sort(classesFolderResources);
            List<ResourceRef> toRemove = new LinkedList<ResourceRef>();
            for (int i = 0; i < classesFolderResources.size(); i++) {
                ResourceRef ref = classesFolderResources.get(i);
                String refURI = ref.getResource().getURI().toString();
                for (int j = i + 1; j < classesFolderResources.size(); j++) {
                    ResourceRef refj = classesFolderResources.get(j);
                    String refjURI = refj.getResource().getURI().toString();
                    if (refURI.startsWith(refjURI)) {
                        toRemove.add(refj);
                        if (logger.isInfoEnabled()) {
                            logger.info("[classesFolder] remove wrapper classes folder: " //
                                    + refj);
                        }
                    } else if (refjURI.startsWith(refURI) && refURI.length() != refjURI.length()) {
                        toRemove.add(ref);
                        if (logger.isInfoEnabled()) {
                            logger.info("[classesFolder] remove wrapper classes folder: " //
                                    + ref);
                        }
                    }
                }
            }
            classesFolderResources.removeAll(toRemove);
            //
            this.classesFolderResources = new ArrayList<ResourceRef>(classesFolderResources);
            if (logger.isInfoEnabled()) {
                logger.info("[classesFolder] found " + classesFolderResources.size()
                        + " classes folders: " + classesFolderResources);
            }
        } else {
            if (logger.isInfoEnabled()) {
                logger.info("[classesFolder] found cached " + classesFolderResources.size()
                        + " classes folders: " + classesFolderResources);
            }
        }
        return Collections.unmodifiableList(classesFolderResources);
    }
838031
public static Map<String,String> storeDirectoryResourcesAsString( File directory ) throws IOException {

		Map<String,byte[]> map = storeDirectoryResourcesAsBytes( directory );
		Map<String,String> result = new HashMap<>( map.size());
		for( Map.Entry<String,byte[]> entry : map.entrySet())
			result.put( entry.getKey(), new String( entry.getValue(), StandardCharsets.UTF_8 ));

		return result;
	}