Class PathResource

java.lang.Object
io.karatelabs.common.PathResource
All Implemented Interfaces:
Resource

public class PathResource extends Object implements Resource
  • Constructor Details

    • PathResource

      public PathResource(Path path)
      Creates a PathResource with working directory as root.
      Parameters:
      path - the path
    • PathResource

      public PathResource(Path path, Path root)
      Creates a PathResource with a custom root.
      Parameters:
      path - the path
      root - the root path for computing relative paths
    • PathResource

      public PathResource(Path path, Path root, boolean classpath)
      Creates a PathResource with custom root and classpath flag.
      Parameters:
      path - the path
      root - the root path for computing relative paths
      classpath - whether this is a classpath resource
    • PathResource

      public PathResource(Path path, Path root, boolean classpath, Path classpathRoot)
      Creates a PathResource with custom root, classpath flag and an explicit classpath:-fallback dir (see Resource.getClasspathRoot()).
      Parameters:
      path - the path
      root - the root path for computing relative paths
      classpath - whether this is a classpath resource
      classpathRoot - the classpath:-miss fallback dir (null = root)
  • Method Details

    • isFile

      public boolean isFile()
      Description copied from interface: Resource
      Returns true if this resource is backed by the file system. PathResource returns true, MemoryResource returns false.
      Specified by:
      isFile in interface Resource
    • isClassPath

      public boolean isClassPath()
      Description copied from interface: Resource
      Returns true if this resource was loaded from the classpath.
      Specified by:
      isClassPath in interface Resource
    • exists

      public boolean exists()
      Description copied from interface: Resource
      Returns true if this resource exists and can be read. For PathResource, checks if the file exists on disk. For UrlResource and MemoryResource, always returns true since content is already loaded.
      Specified by:
      exists in interface Resource
    • getUri

      public URI getUri()
      Specified by:
      getUri in interface Resource
    • getPath

      public Path getPath()
      Description copied from interface: Resource
      Returns the Path representation of this resource if it's file-based. Returns null for in-memory resources.
      Specified by:
      getPath in interface Resource
      Returns:
      Path object or null
    • getRoot

      public Path getRoot()
      Description copied from interface: Resource
      Returns the root path used for relative path computation. For PathResource, this is the configured root (or working directory). For MemoryResource, this is where the resource would be materialized (or system temp).
      Specified by:
      getRoot in interface Resource
      Returns:
      root Path, never null (falls back to system temp)
    • getClasspathRoot

      public Path getClasspathRoot()
      Description copied from interface: Resource
      The directory a classpath: reference falls back to when the classloader misses — declared by boot.classpath(dir) for a project whose resources live under a build layout (src/test/resources). Defaults to Resource.getRoot(), so a bare-folder project needs no declaration: classpath:x and /x land on the same file.
      Specified by:
      getClasspathRoot in interface Resource
    • resolve

      public Resource resolve(String childPath)
      Specified by:
      resolve in interface Resource
    • getParent

      public Resource getParent()
      Description copied from interface: Resource
      Returns the parent of this resource, or null if no parent exists. For PathResource, preserves root and classpath context. For MemoryResource, returns null.
      Specified by:
      getParent in interface Resource
      Returns:
      parent Resource or null
    • getStream

      public InputStream getStream()
      Specified by:
      getStream in interface Resource
    • getRelativePath

      public String getRelativePath()
      Specified by:
      getRelativePath in interface Resource
    • getText

      public String getText()
      Specified by:
      getText in interface Resource
    • getLine

      public String getLine(int index)
      Specified by:
      getLine in interface Resource
    • getLastModified

      public long getLastModified()
      Specified by:
      getLastModified in interface Resource
    • toString

      public String toString()
      Overrides:
      toString in class Object