Class Relative

java.lang.Object
com.qulice.spi.Relative

public final class Relative extends Object
Path of a file relative to a base directory.

Given a base directory and a target file, computes the file path relative to the base, prefixed with a forward slash and using forward slashes as separators. Uses Path.relativize(Path) after normalising both paths to absolute form, which correctly handles cases where the file and base dir share a canonical location but differ in string form (for example, on macOS the /var symlink to /private/var). When the file lies outside the base directory, returns the file's absolute path unchanged.

Since:
0.24
  • Constructor Details

    • Relative

      public Relative(File base, File target)
      Ctor.
      Parameters:
      base - Base directory
      target - Target file
  • Method Details

    • path

      public String path()
      Path of the target file relative to the base directory.
      Returns:
      Relative path starting with a forward slash, or the absolute path of the file if it is not under the base directory