Class UrlResource

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

public class UrlResource extends Object implements Resource
Resource implementation for HTTP/HTTPS URLs. Content is fetched once and cached in memory. Preserves the original URL for reference (getUri(), getSimpleName()).
  • Method Details

    • getUrl

      public URL getUrl()
      Returns the original URL this resource was loaded from.
    • getText

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

      public String getLine(int index)
      Specified by:
      getLine in interface Resource
    • 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
    • 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)
    • getUri

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

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

      public Resource resolve(String path)
      Specified by:
      resolve in interface Resource
    • materialize

      public PathResource materialize(String filename)
      Materializes this URL resource to disk at the specified filename. The file is created within the root directory.
      Parameters:
      filename - the filename to save as
      Returns:
      PathResource pointing to the saved file
    • getStream

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

      public String toString()
      Overrides:
      toString in class Object