Returns the class name for a compiled class file

@param path The path to check
@return The class name or null if it doesn't exist
423552
public static String getClassNameForClassFile(String rootDir, String path) {
        path = path.replace("/", ".");
        path = path.replace('\\', '.');
        path = path.substring(0, path.length() - CLASS_EXTENSION.length());
        if (rootDir != null) {
            path = path.substring(rootDir.length());
        }
        return path;
    }
42207
protected function getClassFromFile($path)
    {
        $count = count($tokens = token_get_all(file_get_contents($path)));

        for ($i = 2; $i < $count; ++$i) {
            if ($tokens[$i - 2][0] == T_CLASS && $tokens[$i - 1][0] == T_WHITESPACE && $tokens[$i][0] == T_STRING) {
                return $tokens[$i][1];
            }
        }
    }
890967
@Override
    public JavaClass findClass(/*@Nonnull*/ String className) {
        // Make sure we handle class names with slashes.
        // If we don't, we can get into serious trouble: a previously
        // loaded class will appear to be missing (because we're using the
        // wrong name to look it up) and be evicted by some other random
        // version of the class loaded from the classpath.
        String dottedClassName = className.replace('/', '.');

        return nameToClassMap.get(dottedClassName);
    }
299573
public static String classpathFromClass(Class<?> clazz) {
        String aname = clazz.getPackage().getName().replaceAll("\\.", "/") + "/" +  clazz.getSimpleName()+".class";
        String apath = ClassLoader.getSystemClassLoader().getResource( aname).getPath();
        String path = null;
        if (apath.contains("!")) {
            path = apath.substring(0, apath.indexOf("!")).replace("file:", "");
        } else {
            path = apath.substring(0, apath.indexOf(aname));
        }
        return path;
    }
9888
public static String getFilename(String path) {
        //The filename is after the last slash
        final int index = path != null ? path.lastIndexOf("/") : -1;
        if (index == -1) {
            IOException ioe = new IOException(TraceNLS.getFormattedMessage(FileTransferHelper.class,
                                                                           APIConstants.TRACE_BUNDLE_FILE_TRANSFER,
                                                                           "PATH_NOT_VALID",
                                                                           new String[] { path },
                                                                           "CWWKX0127E: The path " + path + " is not valid."));
            throw ErrorHelper.createRESTHandlerJsonException(ioe, null, APIConstants.STATUS_BAD_REQUEST);
        }

        return path.substring(index + 1);
    }
1239604
public Optional<URL> getResource(String path) {
        boolean isDirectory = isDirectory(path);

        if (!isDirectory) {
            URL url = classLoader.getResource(prefixPath(path));
            return Optional.ofNullable(url);
        }
        return Optional.empty();
    }
1150279
public static String getUrl(String path) {
        if (path == null) {
            return path;
        }

        ServletContext sc = ExecutionContext.getSession().getServletContext();

        if (path.startsWith("jar:")) {
            int i = path.indexOf("!");
            path = i < 0 ? path : path.substring(++i);
        }

        path = sc.getContextPath() + path;
        return path;
    }
1209730
private static String getClassNameandPath (String className, Path path) {
        if (path == null) {
            return getClassNameandPath(className, "/");
        } else {
            return getClassNameandPath(className, path.value());
        }
    }
1021381
public static String getClassPath()
  {
    if (_classPath != null)
      return _classPath;

    String cp = System.getProperty("java.class.path");

    String boot = System.getProperty("sun.boot.class.path");
    if (boot != null && ! boot.equals(""))
      cp = cp + File.pathSeparatorChar + boot;

    Pattern pattern = Pattern.compile("" + File.pathSeparatorChar);

    String []path = pattern.split(cp);

    CharBuffer cb = new CharBuffer();

    for (int i = 0; i < path.length; i++) {
      PathImpl subpath = VfsOld.lookup(path[i]);

      if (subpath.canRead() || subpath.isDirectory()) {
        if (cb.length() > 0)
          cb.append(File.pathSeparatorChar);

        cb.append(path[i]);
      }
    }

    _classPath = cb.toString();

    return _classPath;
  }
744490
public static function getAnonymousClassName(PhpParser\Node\Stmt\Class_ $class, $file_path)
    {
        return preg_replace('/[^A-Za-z0-9]/', '_', $file_path)
            . '_' . $class->getLine() . '_' . (int)$class->getAttribute('startFilePos');
    }
1242862
public static String getScript(String path) {
        StringBuilder sb = new StringBuilder();

        InputStream stream = ScriptUtil.class.getClassLoader().getResourceAsStream(path);
        try (BufferedReader br = new BufferedReader(new InputStreamReader(stream))){

            String str;
            while ((str = br.readLine()) != null) {
                sb.append(str).append(System.lineSeparator());
            }

        } catch (IOException e) {
            System.err.println(e.getStackTrace());
        }
        return sb.toString();
    }
776282
public static HttpFileBuilder ofResource(ClassLoader classLoader, String path) {
        requireNonNull(classLoader, "classLoader");
        requireNonNull(path, "path");

        // Strip the leading slash.
        if (path.startsWith("/")) {
            path = path.substring(1);
        }

        // Retrieve the resource URL.
        final URL url = classLoader.getResource(path);
        if (url == null || url.getPath().endsWith("/")) {
            // Non-existent resource.
            return new NonExistentHttpFileBuilder();
        }

        // Convert to a real file if possible.
        if ("file".equals(url.getProtocol())) {
            File f;
            try {
                f = new File(url.toURI());
            } catch (URISyntaxException ignored) {
                f = new File(url.getPath());
            }

            return of(f);
        }

        return new ClassPathHttpFileBuilder(url);
    }
1014637
@Override
	public Set<String> getResourceNames(String path) {

		Set<String> resources = null;

		URL resourceURL = null;

		try {
			resourceURL = ClassLoaderResourceUtils.getResourceURL(getCompletePath(path), this);
			if (resourceURL.toString().startsWith(JAR_URL_PREFIX)) {
				resources = getResourceNamesFromJar(path, resourceURL);
			} else if (resourceURL.toString().startsWith(FILE_URL_PREFIX)) {

				String dirPath = resourceURL.getFile();
				File dir = new File(dirPath);
				resources = FileUtils.getResourceNames(dir);
			}
		} catch (ResourceNotFoundException e) {

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

		return resources;
	}
1105399
private File getFileFromPath(final String path) {
        File result = (path != null) ? new File(path) : null;
        // AS7-1752 see if a non-existent relative path exists relative to the home dir
        if (result != null && homeDir != null && !result.exists() && !result.isAbsolute()) {
            File relative = new File(homeDir, path);
            if (relative.exists()) {
                result = relative;
            }
        }
        return result;
    }
260657
@Override
  protected Class<?> findClass(String name) throws ClassNotFoundException {
    if (!loadedClassFiles) {
      classFileMap = extractClassFileMap();
      loadedClassFiles = true;
    }

    if (classFileMap == null) {
      throw new ClassNotFoundException(name);
    }

    String internalName = name.replace('.', '/');
    CompiledClass compiledClass = classFileMap.get(internalName);
    if (compiledClass == null) {
      throw new ClassNotFoundException(name);
    }

    // Make sure the class's package is present.
    String pkg = compiledClass.getPackageName();
    if (getPackage(pkg) == null) {
      definePackage(pkg, null, null, null, null, null, null, null);
    }

    byte[] bytes = compiledClass.getBytes();
    return defineClass(name, bytes, 0, bytes.length);
  }
869318
static String getClasspathClassFileNames() {
        String classpath = System.getProperty("java.class.path");
        String[] pathParts = classpath.split(File.pathSeparator);

        Set<String> classes = new TreeSet<String>();

        for (String part : pathParts) {
            processPathPart(part, classes);
        }

        StringBuilder sb = new StringBuilder();
        for (String className : classes) {
            sb.append(className).append('\n');
        }

        return sb.toString();
    }
139250
public static String getName(String path, boolean ignoreTrailingSlash)
   {
      if (ignoreTrailingSlash && path.endsWith("/") && path.length() > 1)
      {
         path = path.substring(0, path.length() - 1);
      }
      return getName(path);
   }