Get a relative URI for {@code file} from {@code output} folder.
11792
static String createRelativeUri(File file, File output) {
    if (file == null) {
      return null;
    }
    try {
      file = file.getCanonicalFile();
      output = output.getCanonicalFile();
      if (file.equals(output)) {
        throw new IllegalArgumentException("File path and output folder are the same.");
      }
      StringBuilder builder = new StringBuilder();
      while (!file.equals(output)) {
        if (builder.length() > 0) {
          builder.insert(0, "/");
        }
        builder.insert(0, file.getName());
        file = file.getParentFile().getCanonicalFile();
      }
      return builder.toString();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
519421
public InputStream getResourceAsStream(String fileName) {
		InputStream retval = super.getResourceAsStream(fileName);

		if (retval == null) {
			//String className = this.convertFileNameToClassName(fileName);
			//Object location = classResourceLocations.get(className);
			Object location = this.mixedResourceLocations.get(fileName);
			if (location == null) {
				return null;
			}

			byte[] data;
			try {
				data = getData(fileName, location);
			} catch (IOException ioe) {
				return null;
			}
			if (data == null) {
				return null;
			}
			return new ByteArrayInputStream(data);

		}
		return retval;
	}
1019738
public static String relativePath(File from, File to) {
        if (from == null || to == null) return null;
        try {
            if (from.isFile()) from = from.getParentFile();
            if (!from.isDirectory()) throw new IllegalArgumentException("Not a directory: " + from);

            final String[] fromParts = from.getCanonicalPath().split(Pattern.quote(File.separator));
            List<String> toParts = new ArrayList<>(asList(to.getCanonicalPath().split(Pattern.quote(File.separator))));

            int skip = 0; // Skip the common base path
            while (skip < fromParts.length && skip < toParts.size() && fromParts[skip].equals(toParts.get(skip))) {
                skip++;
            }
            if (skip > 0) toParts = toParts.subList(skip, toParts.size());

            // Replace each remaining directory in 'from' by a preceding "../"
            for (int i = fromParts.length; i > skip; i--) toParts.add(0, "..");

            // Return the resulting path, joined by seprators.
            return toParts.stream().collect(joining("/"));
        } catch (IOException ioe) {
            throw new IllegalStateException("I/O exception calculating relative path from \""
                    + from + "\" to \"" + to + "\": " + ioe.getMessage(), ioe);
        }
    }
664667
public static URI createFolderURI(File file) {
		URI uri = URI.createFileURI(file.getAbsolutePath());
		return toFolderURI(uri);
	}
906547
@Trivial
    private static URI getURI(final File file) {
        return AccessController.doPrivileged( new PrivilegedAction<URI>() {
            @Override
            public URI run() {
                return file.toURI();
            }
        } );
    }
968727
protected String getPathName(VirtualFile file) {
        try {
            // prefer the URI, as the pathName might
            // return an empty string for temp virtual files
            return file.toURI().toString();
        } catch (Exception e) {
            return file.getPathName();
        }
    }
215642
public String relative(String url)
	{
		try
		{
			final URI uri = absolute(url).build();

			return new URI(null, null, uri.getPath(), uri.getQuery(), uri.getFragment()).toString();
		}
		catch (URISyntaxException e)
		{
			throw new IllegalArgumentException(e);
		}
	}
199090
public String resolveRelativeUri(String uri) {
        // sometimes we get uri's massaged from File(String), so check for
        // a root directory separator char
        if (uri.startsWith("/") || uri.startsWith(File.separator)) {
            return uri;
        } else {
            return baseURI + uri;
        }
    }
685955
public FileInfo getOrCreateFileInfo(final URI file) {
        assert file.getFragment() == null;
        URI f = file.normalize();
        if (f.isAbsolute()) {
            f = tempDirURI.relativize(f);
        }
        FileInfo i = getFileInfo(file);
        if (i == null) {
            i = new FileInfo(f);
            add(i);
        }
        return i;
    }
579611
public DocLink getExternalLink(String pkgName, DocPath relativepath, String filename) {
        return getExternalLink(pkgName, relativepath, filename, null);
    }
1165546
public static String getImageAsDataUri(File file) throws IOException {
        String contentType = getContentType(file);
        String base64Content = getImageAsBase64(file);

        return "data:" + contentType + ";base64," + base64Content;
    }
163809
private URI getImageFile(final URI href) {
        final URI fileName;
        final FileInfo fi = job.getFileInfo(currentFile.resolve(href));
        if (fi != null) {
            fileName = job.getInputDir().relativize(fi.src);
        } else {
            fileName = href;
        }

        final URI outputURI = outputDir.toURI().resolve(fileName);
        if (exists(outputURI)) {
            logger.debug("Found " + outputURI);
            return outputURI;
        }

        final URI tempURI = job.tempDirURI.resolve(fileName);
        if (exists(tempURI)) {
            logger.debug("Found " + tempURI);
            return tempURI;
        }

        if (fi != null) {
            final URI srcTempURI = job.tempDirURI.resolve(fi.uri);
            if (exists(srcTempURI)) {
                logger.debug("Found " + srcTempURI);
                return srcTempURI;
            }
        }

        final URI srcURI = job.getInputDir().resolve(fileName);
        if (exists(srcURI)) {
            logger.debug("Found " + srcURI);
            return srcURI;
        }

        return null;
    }
1219638
private String getPrefix(final File relativeRootFile) {
        String res;
        final File p = relativeRootFile.getParentFile();
        if (p != null) {
            res = p.toString() + File.separator;
        } else {
            res = "";
        }
        return res;
    }
217773
@Nullable
  public static String getFileNameFromUri(URI uri) {
    if (!uri.getScheme().equals("jar")) {
      return uri.getPath();
    }

    try {
      String jarEntryFileName = ((JarURLConnection) uri.toURL().openConnection()).getEntryName();
      // It's possible (though it violates the zip file spec) for paths to zip file entries to use
      // '\' as the separator. Normalize to use '/'.
      jarEntryFileName = BACKSLASH_MATCHER.replaceFrom(jarEntryFileName, '/');
      if (!jarEntryFileName.startsWith("/")) {
        jarEntryFileName = "/" + jarEntryFileName;
      }
      return jarEntryFileName;
    } catch (IOException e) {
      return null;
    }
  }
220617
private static String getRelativePath(File file, FilesystemIterator iterator) throws IOException {
		String path = file.getPath();
		String prefix = iterator.getStartPath();
		if(!path.startsWith(prefix)) throw new IOException("path doesn't start with prefix: path=\""+path+"\", prefix=\""+prefix+"\"");
		return path.substring(prefix.length());
	}
369365
public File getOutputDir() {
        if (prop.containsKey(PROPERTY_OUTPUT_DIR)) {
            return new File(prop.get(PROPERTY_OUTPUT_DIR).toString());
        }
        return null;
    }
61966
public static String getURL(final String fileName) {

        if (fileName.startsWith("file:/")) {
            return fileName;
        } else {
            final File file = new File(fileName);
            return file.toURI().toString();
        }

    }