Read lines with rest or classpath or file path list.

@param resourceWithRestOrClasspathOrFilePath the resource with rest or classpath or file path
@param charsetName                           the charset name
@return the list
762511
public static List<String> readLinesWithRestOrClasspathOrFilePath(
            String resourceWithRestOrClasspathOrFilePath, String charsetName) {
        return JMCollections
                .buildListByLine(getStringWithRestOrClasspathOrFilePath(
                        resourceWithRestOrClasspathOrFilePath, charsetName));
    }
171150
public static String readStr(String resource, Charset charset) {
		return getResourceObj(resource).readStr(charset);
	}
1059200
@Override
	public Set<InputStream> getResourcesAsStream(final String path) throws IOException
	{
		// First, try the path as specified
		final Set<InputStream> streams = inner.getResourcesAsStream(path);

		// If no results were found and the path was absolute, retry without the leading slash
		if ((streams == null || streams.isEmpty()) && !path.isEmpty() && path.charAt(0) == '/')
		{
			// Strip the leading slash away and re-try the path
			// This lets us
			final String newPath = path.substring(1);

			return inner.getResourcesAsStream(newPath);
		}
		else
		{
			return streams;
		}
	}
157998
public static BufferedReader getReader(String resurce, Charset charset) {
		return getResourceObj(resurce).getReader(charset);
	}
297243
public static List<String> readLines(InputStream inputStream,
            String charsetName) {
        List<String> stringList = new ArrayList<>();
        try {
            consumeInputStream(inputStream, charsetName, stringList::add);
        } catch (Exception e) {
            return JMExceptionManager.handleExceptionAndReturn(log, e,
                    "readLines", Collections::emptyList, inputStream, charsetName);
        }
        return stringList;
    }
915082
public static Resource getFileResource(String filePath) {
        String path;

        if (filePath.contains(FILE_PATH_CHARSET_PARAMETER)) {
            path = filePath.substring(0, filePath.indexOf(FileUtils.FILE_PATH_CHARSET_PARAMETER));
        } else {
            path = filePath;
        }

        if (path.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
            return new FileSystemResource(path.substring(ResourceUtils.FILE_URL_PREFIX.length() - 1));
        } else if (path.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
            return new PathMatchingResourcePatternResolver().getResource(path);
        }

        Resource file = new FileSystemResource(path);
        if (!file.exists()) {
            return  new PathMatchingResourcePatternResolver().getResource(path);
        }

        return file;
    }
5608
public static String readResource(String path)
    {
        Class<?> callerClass = resolveCaller();
        if (callerClass == null)
        {
            return null;
        }

        return readResource(resolveCaller(), path);
    }
57343
public Set getResourcePaths(String path, boolean searchMetaInf)
  {
    java.util.HashSet set = new java.util.HashSet();

    if ((WCCustomProperties.SKIP_META_INF_RESOURCES_PROCESSING) && (searchMetaInf == true)){

        searchMetaInf = false;
        logger.logp(Level.FINE, CLASS_NAME, "getResourcePaths", "override searchMetaInf to false becuase of custom property");
    }
    
    
    if (container != null){
        try {
            addResourcePaths(set, container, path, searchMetaInf);
        } catch (UnableToAdaptException e) {
            throw new IllegalStateException(e);
        }
        
        // PM21451 Start
        // search the static doc roots and include a search of meta-inf resources if boolean parameter is true
        // 96723: Hard code a "false" parameter to avoid searching META-INF resources a second time. The
        // resource paths are already added by Liberty specific container code.
        set.addAll(getStaticDocumentRootUtils().getResourcePaths(path,false));

        // look at the JSP doc roots but don't search meta-inf resources this time (meta-inf resources are common
        // to both doc roots).
        set.addAll(getJSPDocumentRootUtils().getResourcePaths(path,false));
        // PM21451 End
        
        return set;
    }

    java.io.File root = new java.io.File(documentRoot + path);

    if (root.exists())
    {
      java.io.File[] fileList = root.listFiles();
      if (fileList != null)
      {
        for (int i = 0; i < fileList.length; i++)
        {
          String resourcePath = fileList[i].getPath();
          resourcePath = resourcePath.substring(documentRoot.length());
          resourcePath = resourcePath.replace('\\', '/');
          if (fileList[i].isDirectory())
          {
            if (resourcePath.endsWith("/") == false)
            {
              resourcePath += "/";
            }
          }
          set.add(resourcePath);
        }
      }
    }
    return (set);
  }
1143694
private Set<String> getResourceNamesFromJar(String path, URL resourceURL) {

		URLConnection con = null;

		try {
			if (resourceURL.toString().startsWith(JawrConstant.JAR_URL_PREFIX)) {
				con = resourceURL.openConnection();
			}
		} catch (IOException e) {

			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("Unable to find resources name for path '" + path + "'", e);
			}
			return Collections.emptySet();
		}

		JarFile jarFile;
		String jarFileUrl;
		String rootEntryPath;
		boolean newJarFile = false;

		try {
			if (con instanceof JarURLConnection) {
				// Should usually be the case for traditional JAR files.
				JarURLConnection jarCon = (JarURLConnection) con;
				jarCon.setUseCaches(true);
				jarFile = jarCon.getJarFile();
				JarEntry jarEntry = jarCon.getJarEntry();
				rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
			} else {
				// No JarURLConnection -> need to resort to URL file parsing.
				// We'll assume URLs of the format "jar:path!/entry", with the
				// protocol
				// being arbitrary as long as following the entry format.
				// We'll also handle paths with and without leading "file:"
				// prefix.
				String urlFile = resourceURL.getFile();
				int separatorIndex = urlFile.indexOf(JAR_URL_SEPARATOR);
				if (separatorIndex != -1) {
					jarFileUrl = urlFile.substring(0, separatorIndex);
					rootEntryPath = urlFile.substring(separatorIndex + JAR_URL_SEPARATOR.length());
					jarFile = getJarFile(jarFileUrl);
				} else {
					jarFile = new JarFile(urlFile);
					rootEntryPath = "";
				}
				newJarFile = true;
			}
		} catch (IOException e) {
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("Unable to find resources name for path '" + path + "'", e);
			}
			return Collections.emptySet();
		}
		try {
			if (!"".equals(rootEntryPath) && !rootEntryPath.endsWith("/")) {
				// Root entry path must end with slash to allow for proper
				// matching.
				// The Sun JRE does not return a slash here, but BEA JRockit
				// does.
				rootEntryPath = rootEntryPath + "/";
			}
			Set<String> result = new LinkedHashSet<>(8);
			for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
				JarEntry entry = entries.nextElement();
				String entryPath = entry.getName();
				if (isDirectChildPath(rootEntryPath, entryPath)) {
					String relativePath = entryPath.substring(rootEntryPath.length());
					result.add(relativePath);
				}
			}
			return result;
		} finally {
			// Close jar file, but only if freshly obtained -
			// not from JarURLConnection, which might cache the file reference.
			if (newJarFile) {
				try {
					jarFile.close();
				} catch (IOException e) {
					// Nothing to do
				}
			}
		}
	}
950334
public static String convertResourcePathToClassName(String resourcePath) {
        Assert.notNull(resourcePath, "Resource path must not be null");
        return resourcePath.replace(PATH_SEPARATOR, PACKAGE_SEPARATOR);
    }
508565
public static Collection<String> getClasspathResources(final Pattern searchPattern) {

        final List<String> resources = new ArrayList<>();

        final ClassLoader cl = Thread.currentThread().getContextClassLoader();

        if (hasJavaWebstartLibrary() && cl instanceof JNLPClassLoaderIf) {

            LOGGER.log(USE_JNLP_CLASSLOADER);

            final JNLPClassLoaderIf wsLoader = (JNLPClassLoaderIf) cl;

            // System.out.println("URLs "+ wsLoader.getURLs());
            for (final JARDesc jd : wsLoader.getLaunchDesc().getResources().getLocalJarDescs()) {
                try {

                    final JarFile jarFile = wsLoader.getJarFile(jd.getLocation());

                    LOGGER.log(PARSE_CACHED_JAR_FILE, jarFile.getName(), jd.getLocationString());

                    resources.addAll(getResources(jarFile.getName(), searchPattern, true));
                } catch (final IOException e) {
                    LOGGER.log(CANT_READ_CACHED_JAR_FILE, jd.getLocation());
                }
            }

        } else {

            LOGGER.log(USE_DEFAULT_CLASSLOADER);

            final String[] classpathEntries = CLASSPATH.split(CLASSPATH_SEPARATOR);
            for (final String urlEntry : classpathEntries) {
                // Parse the classpath entry and apply the given pattern as filter
                resources.addAll(getResources(urlEntry, searchPattern, false));
            }
        }

        // Sort resources
        Collections.sort(resources);

        return resources;
    }
420688
public static String readResource(String resourceName, String charset) {
        InputStream is = Util.class.getResourceAsStream(resourceName);
        try {
            return read(is, charset);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            closeQuietly(is);
        }
    }
906248
@Override
    public InputStream getResourceAsStream(final String path) {
        final ResourceList resourceList = scanResult.getResourcesWithPath(path);
        if (resourceList == null || resourceList.isEmpty()) {
            return super.getResourceAsStream(path);
        } else {
            try {
                return resourceList.get(0).open();
            } catch (final IOException e) {
                return null;
            }
        }
    }
135944
@Override
    public Enumeration<URL> getResources(final String path) throws IOException {
        final ResourceList resourceList = scanResult.getResourcesWithPath(path);
        if (resourceList == null || resourceList.isEmpty()) {
            return super.getResources(path);
        } else {
            return new Enumeration<URL>() {
                /** The idx. */
                int idx;

                @Override
                public boolean hasMoreElements() {
                    return idx < resourceList.size();
                }

                @Override
                public URL nextElement() {
                    return resourceList.get(idx++).getURL();
                }
            };
        }
    }
865563
public static BufferedReader getReader(String path, String charsetName) throws IORuntimeException {
		return getReader(file(path), charsetName);
	}
989737
public Set<String> getResourcePaths(String path) {

		Set<String> result = new HashSet<String>();
		path = path.replace('/', File.separatorChar);
		File resource = new File(baseDir, path);

		// If the path is not valid throw an exception
		String[] resArray = resource.list();
		if (null == resArray)
			return result;

		// Make the returned dirs end with '/', to match a servletcontext
		// behavior.
		for (int i = 0; i < resArray.length; i++) {

			resArray[i] = path + resArray[i];
			if (isDirectory(resArray[i]))
				resArray[i] += '/';
		}
		result.addAll(Arrays.asList(resArray));

		return result;
	}
1040341
@SuppressWarnings("deprecation")
    @Override
    public final URL[] findResourcesByClasspath()
    {
        List<URL> list = new ArrayList<URL>();
        String classpath = System.getProperty("java.class.path");
        StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);

        while (tokenizer.hasMoreTokens())
        {
            String path = tokenizer.nextToken();

            File fp = new File(path);
            if (!fp.exists())
                throw new ResourceReadingException("File in java.class.path does not exist: " + fp);
            try
            {
                list.add(fp.toURL());
            }
            catch (MalformedURLException e)
            {
                throw new ResourceReadingException(e);
            }
        }
        return list.toArray(new URL[list.size()]);
    }