Find a property file

@param classloader
@param fileName

@return
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);
	}
752363
public Class findClass(String name) throws ClassNotFoundException {

        if (log.isDebugEnabled())
            log.debug("    findClass(" + name + ")");

        // Cannot load anything from local repositories if class loader is stopped
        if (!started) {
            throw new ClassNotFoundException(name);
        }

        // (1) Permission to define this class when using a SecurityManager
        if (securityManager != null) {
            int i = name.lastIndexOf('.');
            if (i >= 0) {
                try {
                    if (log.isTraceEnabled())
                        log.trace("      securityManager.checkPackageDefinition");
                    securityManager.checkPackageDefinition(name.substring(0,i));
                } catch (Exception se) {
                    if (log.isTraceEnabled())
                        log.trace("      -->Exception-->ClassNotFoundException", se);
                    throw new ClassNotFoundException(name, se);
                }
            }
        }

        // Ask our superclass to locate this class, if possible
        // (throws ClassNotFoundException if it is not found)
        Class clazz = null;
        try {
            if (log.isTraceEnabled())
                log.trace("      findClassInternal(" + name + ")");
            try {
                clazz = findClassInternal(name);
            } catch(ClassNotFoundException cnfe) {
                if (!hasExternalRepositories) {
                    throw cnfe;
                }
            } catch(AccessControlException ace) {
                throw new ClassNotFoundException(name, ace);
            } catch (RuntimeException e) {
                if (log.isTraceEnabled())
                    log.trace("      -->RuntimeException Rethrown", e);
                throw e;
            }
            if ((clazz == null) && hasExternalRepositories) {
                try {
                    clazz = super.findClass(name);
                } catch(AccessControlException ace) {
                    throw new ClassNotFoundException(name, ace);
                } catch (RuntimeException e) {
                    if (log.isTraceEnabled())
                        log.trace("      -->RuntimeException Rethrown", e);
                    throw e;
                }
            }
            if (clazz == null) {
                if (log.isDebugEnabled())
                    log.debug("    --> Returning ClassNotFoundException");
                throw new ClassNotFoundException(name);
            }
        } catch (ClassNotFoundException e) {
            if (log.isTraceEnabled())
                log.trace("    --> Passing on ClassNotFoundException");
            throw e;
        }

        // Return the class we have located
        if (log.isTraceEnabled())
            log.debug("      Returning class " + clazz);
        if (log.isTraceEnabled())
            log.debug("      Loaded by " + clazz.getClassLoader());
        return (clazz);

    }
1285093
public static InputStream loadFile(String fileName) {
        logger.entering(fileName);
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        InputStream iStream = loader.getResourceAsStream(fileName);
        if (iStream == null) {
            try {
                iStream = new FileInputStream(fileName);
            } catch (FileNotFoundException e) { // NOSONAR
                // Gobbling the checked exception here and doing nothing with it
                // because we are explicitly checking if the inputstream is null
                // and then throwing a runtime exception
            }
        }
        if (iStream == null) {
            throw new IllegalArgumentException("[" + fileName + "] is not a valid resource");
        }
        logger.exiting();
        return iStream;
    }
1030944
public Class<?> findClass(String className)
	{
	
		Class<?> result = null;

		// look in hash map
		result = (Class<?>) classes.get(className);
		if (result != null)
		{
			return result;
		}

		try
		{
			return findSystemClass(className);
		}
		catch (Exception e)
		{
			Debugger.printWarn(e);
		}

		try
		{
			URL resourceURL = ClassLoader.getSystemResource(className.replace(
					'.', File.separatorChar) + ".class");

			if (resourceURL == null)
				return null;

			String classPath = resourceURL.getFile();

			classPath = classPath.substring(1);

			return loadClass(className, new File(classPath));
		}
		catch (Exception e)
		{
			Debugger.printError(e);
			return null;
		}
	}
201892
public Optional<AddOnModel> getAddOnForClassLoader(ClassLoader classLoader) {
        return addOns.stream()
                .filter(addOnModel -> addOnModel.getClass().getClassLoader().equals(classLoader))
                .findFirst();
    }
888611
public static String readFileFromClassPath(String _fileName) {
        StringBuilder sb = new StringBuilder();
        for (String string : readFileFromClassPathAsList(_fileName)) {
            sb.append(string).append("\n");
        }
        return sb.length() == 0 ? null : sb.toString();
    }
901368
@FFDCIgnore(ClassNotFoundException.class)
    private Class<?> findClassCommonLibraryClassLoaders(String name) throws ClassNotFoundException {
        for (LibertyLoader cl : delegateLoaders) {
            try {
                return cl.findClass(name);
            } catch (ClassNotFoundException e) {
                // Ignore. Will throw at the end if class is not found.
            }
        }
        // If we reached here, then the class was not loaded.
        throw new ClassNotFoundException(name);
    }
649268
private static String which(String classname, ClassLoader loader) {
        String classnameAsResource = classname.replace('.', '/') + ".class";
        if (loader==null) loader = ClassLoader.getSystemClassLoader();

        URL it = loader.getResource(classnameAsResource);
        return it != null ? it.toString() : null;
    }
732933
public static Properties loadProperties(Class<?> clazz, String fileName) throws IOException {
        Properties properties = new Properties();
        try (InputStream is = clazz.getClassLoader().getResourceAsStream(fileName)) {
            properties.load(is);
        }
        return properties;
    }
624786
public JavacFiler getJavacFiler(Object filer) {
		if (filer instanceof JavacFiler) return (JavacFiler) filer;
		
		// try to find a "delegate" field in the object, and use this to check for a JavacFiler
		for (Class<?> filerClass = filer.getClass(); filerClass != null; filerClass = filerClass.getSuperclass()) {
			try {
				return getJavacFiler(tryGetDelegateField(filerClass, filer));
			} catch (final Exception e) {
				// delegate field was not found, try on superclass
			}
		}
		
		processingEnv.getMessager().printMessage(Kind.WARNING,
			"Can't get a JavacFiler from " + filer.getClass().getName() + ". Lombok won't work.");
		return null;
	}
925011
public static Properties getPropertiesFromClasspath(String fileName)
      throws PropertiesFileNotFoundException {

    Properties props = new Properties();
    try {
      InputStream is = ClassLoader.getSystemResourceAsStream(fileName);
      if (is == null) { // try this instead
        is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
        logger.debug("loaded properties file with Thread.currentThread()");
      }
      props.load(is);
    } catch (Exception e) {
      throw new PropertiesFileNotFoundException(
          "ERROR LOADING PROPERTIES FROM CLASSPATH >" + fileName + "< !!!", e);
    }
    return props;
  }
737781
public static String locate(String className, ClassLoader classLoader) {
        String resource = new String(className);

        // format the file name into a valid resource name
        if (!resource.startsWith("/")) {
            resource = "/" + resource;
        }
        resource = resource.replace('.', '/');
        resource = resource + ".class";

        // attempt to locate the file using the class loader
        URL classUrl = classLoader.getResource(resource);
        if (classUrl == null && classLoader == ClasspathUtil.class.getClassLoader()) {
            // Apparently clazz.getResource() works sometimes when clazz.getClassLoader().getResource() does not.
            // TODO: why?
            classUrl = ClasspathUtil.class.getResource(resource);
        }

        if (classUrl == null) {
            return "\nClass not found: [" + className + "]";
        }
        else {
            return classUrl.getFile();
        }
    }
43282
public static File getFileFromDirectoryInClassPath(String fileName, String classPath) {

		Collection<String> paths = StringSupport.split(classPath, ";:", false);

		for(String singlePath : paths) {
			File dir = new File(singlePath);
			if (dir.isDirectory()) {
				File file = new File(singlePath + '/' + fileName);
				if (file.exists()) {
					return file;
				}
			}
		}
		return null;
	}
445265
public static String findSingleMainClass(JarFile jarFile, String classesLocation)
            throws IOException {
        MainClassesCallback callback = new MainClassesCallback();
        MainClassFinder.doWithMainClasses(jarFile, classesLocation, callback);
        return callback.getMainClass();
    }
1125117
public static Class<? extends FileSystem> getFileSystemByName(final String className) throws ClassNotFoundException {
		return Class.forName(className, true, getClassLoader()).asSubclass(FileSystem.class);
	}
858492
public JavaClass lookupClass(String className) throws ClassNotFoundException {
        if (classesThatCantBeFound.contains(className)) {
            throw new ClassNotFoundException("Error while looking for class " + className + ": class not found");
        }
        String resourceName = className.replace('.', '/') + ".class";
        InputStream in = null;
        boolean parsedClass = false;

        try {

            in = getInputStreamForResource(resourceName);
            if (in == null) {
                classesThatCantBeFound.add(className);
                throw new ClassNotFoundException("Error while looking for class " + className + ": class not found");
            }

            ClassParser classParser = new ClassParser(in, resourceName);
            JavaClass javaClass = classParser.parse();
            parsedClass = true;

            return javaClass;
        } catch (IOException e) {
            classesThatCantBeFound.add(className);
            throw new ClassNotFoundException("IOException while looking for class " + className, e);
        } finally {
            if (in != null && !parsedClass) {
                try {
                    in.close();
                } catch (IOException ignore) {
                    // Ignore
                }
            }
        }
    }
840733
private static InputStream findStream(String filename) {
        InputStream streamOnClass = JDefaultAddress.class.getResourceAsStream(filename);
        if (streamOnClass != null) {
            return streamOnClass;
        }
        InputStream is = JDefaultAddress.class.getClassLoader().getResourceAsStream(filename);
        return is;
    }