Returns requested ClassPathResource as File object

Please note: if this method called from compiled jar, temporary file will be created to provide File access

@return File requested at constructor call
@throws FileNotFoundException
188638
public File getFile() throws FileNotFoundException {
        URL url = this.getUrl();

        if (isJarURL(url)) {
            /*
                This is actually request for file, that's packed into jar. Probably the current one, but that doesn't matters.
             */
            try {
                url = extractActualUrl(url);
                File file = File.createTempFile("canova_temp", "file");
                file.deleteOnExit();

                ZipFile zipFile = new ZipFile(url.getFile());
                ZipEntry entry = zipFile.getEntry(this.resourceName);
                if (entry == null) {
                    if (this.resourceName.startsWith("/")) {
                        entry = zipFile.getEntry(this.resourceName.replaceFirst("/", ""));
                        if (entry == null) {
                            throw new FileNotFoundException("Resource " + this.resourceName + " not found");
                        }
                    } else
                        throw new FileNotFoundException("Resource " + this.resourceName + " not found");
                }

                long size = entry.getSize();

                InputStream stream = zipFile.getInputStream(entry);
                FileOutputStream outputStream = new FileOutputStream(file);
                byte[] array = new byte[1024];
                int rd = 0;
                long bytesRead = 0;
                do {
                    rd = stream.read(array);
                    outputStream.write(array, 0, rd);
                    bytesRead += rd;
                } while (bytesRead < size);

                outputStream.flush();
                outputStream.close();

                stream.close();
                zipFile.close();

                return file;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

        } else {
            /*
                It's something in the actual underlying filesystem, so we can just go for it
             */

            try {
                URI uri = new URI(url.toString().replaceAll(" ", "%20"));
                return new File(uri.getSchemeSpecificPart());
            } catch (URISyntaxException e) {
                return new File(url.getFile());
            }
        }
    }
179555
public static Resource getResourceObj(String path) {
		if(StrUtil.isNotBlank(path)) {
			if(path.startsWith(URLUtil.FILE_URL_PREFIX) || FileUtil.isAbsolutePath(path)) {
				return new FileResource(path);
			}
		}
		return new ClassPathResource(path);
	}
759261
private InputStream openCustomSortOrderFile() throws FileNotFoundException {
        InputStream inputStream;
        try {
            inputStream = new FileInputStream(customSortOrderFile);
        } catch (FileNotFoundException ex) {
            // try classpath
            try {
                URL resource = this.getClass().getClassLoader().getResource(customSortOrderFile);
                if (resource == null) {
                    throw new IOException("Cannot find resource");
                }
                inputStream = resource.openStream();
            } catch (IOException e1) {
                throw new FileNotFoundException(String.format("Could not find %s or %s in classpath", new File(
                        customSortOrderFile).getAbsolutePath(), customSortOrderFile));
            }
        }
        return inputStream;
    }
797862
public function build(): Source
    {
        $combinedSource = '';

        foreach ($this->filePaths as $filePath) {
            if (!\file_exists($filePath) || !\is_readable($filePath)) {
                throw new FileNotFoundException(sprintf('The file %s cannot be found or is not readable', $filePath));
            }

            $combinedSource .= \file_get_contents($filePath);
        }

        return new Source($combinedSource);
    }
858459
@Override
  protected ClassEntry getClassEntry(String name, String pathName)
    throws ClassNotFoundException
  {
    PathImpl path = _pathMap.get(name);

    if (path != null && path.canRead() && path.length() > 0) {
      ClassEntry entry = new ClassEntry(getClassLoader(), name, path,
                                        path, getCodeSource(path));

      /*
      int p = name.lastIndexOf('.');
      String pkg;
      if (p > 0)
        pkg = name.substring(0, p);
      else
        pkg = "";

      ClassPackage classPackage = jarEntry.getPackage(pkg);

      entry.setClassPackage(classPackage);
      */

      return entry;
    }

    return null;
  }
1329892
public static String getRootClassPath() {
		if (rootClassPath == null) {
			try {
				// String path = PathKit.class.getClassLoader().getResource("").toURI().getPath();
				String path = getClassLoader().getResource("").toURI().getPath();
				rootClassPath = new File(path).getAbsolutePath();
			}
			catch (Exception e) {
				// String path = PathKit.class.getClassLoader().getResource("").getPath();
				// String path = getClassLoader().getResource("").getPath();
				// rootClassPath = new File(path).getAbsolutePath();
				
				try {
					String path = PathKit.class.getProtectionDomain().getCodeSource().getLocation().getPath();
					path = java.net.URLDecoder.decode(path, "UTF-8");
					if (path.endsWith(File.separator)) {
						path = path.substring(0, path.length() - 1);
					}
					rootClassPath = path;
				} catch (UnsupportedEncodingException e1) {
					throw new RuntimeException(e1);
				}
			}
		}
		return rootClassPath;
	}
168747
public static File getClassFile(Class<?> clazz) {
    File dir = new File(clazz.getProtectionDomain().getCodeSource().getLocation().getPath());
    if (!dir.isDirectory()) return null; // class file might be contained in Jar
    File clazzFile = new File(dir, clazz.getName().replace('.', File.separatorChar) + ".class");
    return clazzFile.isFile() ? clazzFile : null;
  }
149886
public InputStream getAsStream() throws CacheException {
		File file = null;
		try {
			File directory = new File(System.getProperty("java.library.path"));
			file = new File(directory, filename);
			if(file.exists() && file.isFile()) {
				return new FileInputStream(file);
			}
		} catch(IOException e) {
			logger.error("file '{}' does not exist on classpath or is not a file", filename);
			throw new CacheException("File " + filename + " does not exist on classpath or is not a regular file", e);			
		}
		return null;
	}
344199
public function getFile(){
        if(!$this->isPropertyAvailable('File')){
            $this->setProperty("File", new File($this->getContext(),new ResourcePathEntity($this->getContext(),$this->getResourcePath(), "File")),false);
        }
        return $this->getProperty("File");
    }
887260
private static FileResource getFileResourceProto(final String fileName, final FileType type) throws IOException {
    File file = new File(fileName);
    if (file.exists()) {
      // It is a local file and can be added.
      if (file.isDirectory()) {
        // If it is a directory, create a JAR file of it and add that instead.
        file = toJar(file);
      }
      return FileResourceImpl.newBuilder()
          .setName(file.getName())
          .setPath(file.getPath())
          .setType(type)
          .build();
    } else {
      // The file isn't in the local filesytem. Assume that the file is actually a URI.
      // We then assume that the underlying resource manager knows how to deal with it.
      try {
        final URI uri = new URI(fileName);
        final String path = uri.getPath();
        final String name = path.substring(path.lastIndexOf('/') + 1);
        return FileResourceImpl.newBuilder()
            .setName(name)
            .setPath(uri.toString())
            .setType(type)
            .build();
      } catch (final URISyntaxException e) {
        throw new IOException("Unable to parse URI.", e);
      }
    }
  }
848910
@Pure
	public List<File> getClassPath() {
		if (this.classpath == null) {
			return Collections.emptyList();
		}
		return Collections.unmodifiableList(this.classpath);
	}
364027
private static ClassPath getAPIClassPath() throws IOException {
    ClassLoader classLoader = Flow.class.getClassLoader();
    String resourceName = Flow.class.getName().replace('.', '/') + ".class";
    URL url = classLoader.getResource(resourceName);
    if (url == null) {
      throw new IOException("Resource not found for " + resourceName);
    }

    try {
      URI classPathURI = getClassPathURL(resourceName, url).toURI();
      return ClassPath.from(classPathURI, classLoader);
    } catch (URISyntaxException e) {
      throw new IOException(e);
    }
  }
1255462
@Override
  public File getFile() throws IOException {
    String realPath = RequestUtils.getRealPath(this.servletContext, this.path);
    return new File(realPath);
  }
66699
public function build(): Source
    {
        if (!\file_exists($this->filePath) || !\is_readable($this->filePath)) {
            throw new FileNotFoundException(sprintf('The file %s cannot be found or is not readable', $this->filePath));
        }

        return new Source(\file_get_contents($this->filePath));
    }
143293
public static File getFileForResource(final String resourcePath) {
        URL path = ResourceUtil.class.getResource(resourcePath);
        if (path == null) {
            path = ResourceUtil.class.getResource("/");
            return new File(new File(path.getPath()), resourcePath);
        }

        return new File(path.getPath());
    }
569302
@Override
	public URL getResourceUrl(String fileName) {
		if (fileName == null) {
			return null;
		}
		URL resource = getClass().getResource(fileName);
		if (resource == null) {
			resource = Thread.currentThread().getContextClassLoader().getResource(fileName);
			if (resource == null) {
				resource = ClassLoader.getSystemResource(fileName);
				if (resource == null) {
					File file = new File(fileName);
					if (file.exists()) {
						try {
							resource = file.toURI().toURL();
						} catch (MalformedURLException e) {
							throw new JKException(e);
						}
					}
				}
			}
		}
		return resource;
	}
768693
public String getClassPath() {
        StringBuilder buf = new StringBuilder();
        for (Entry entry : entryList) {
            if (buf.length() > 0) {
                buf.append(File.pathSeparator);
            }
            buf.append(entry.getURL());
        }
        return buf.toString();
    }