Class MemoryResource

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

public class MemoryResource extends Object implements Resource
  • Method Details

    • getText

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

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

      public int getLineOffset()
      Description copied from interface: Resource
      Returns the line offset for embedded code (e.g., JS inside a feature file). The lexer uses this as the starting line number so tokens get absolute line numbers. Default is 0 (no offset).
      Specified by:
      getLineOffset 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)
    • 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
    • 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 in-memory 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