Package io.karatelabs.common
Class MemoryResource
java.lang.Object
io.karatelabs.common.MemoryResource
- All Implemented Interfaces:
Resource
-
Field Summary
Fields inherited from interface io.karatelabs.common.Resource
CLASSPATH_COLON, FILE_COLON, THIS_COLON -
Method Summary
Modifier and TypeMethodDescriptionbooleanexists()Returns true if this resource exists and can be read.The directory aclasspath:reference falls back to when the classloader misses — declared byboot.classpath(dir)for a project whose resources live under a build layout (src/test/resources).getLine(int index) intReturns the line offset for embedded code (e.g., JS inside a feature file).getPath()Returns the Path representation of this resource if it's file-based.getRoot()Returns the root path used for relative path computation.getText()getUri()booleanReturns true if this resource was loaded from the classpath.booleanisFile()Returns true if this resource is backed by the file system.materialize(String filename) Materializes this in-memory resource to disk at the specified filename.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.karatelabs.common.Resource
getExtension, getFileNameWithoutExtension, getLastModified, getPackageQualifiedName, getParent, getPrefixedPath, getRelativePathFrom, getRelativePathTo, getSimpleName, isInMemory, isJarResource, isLocalFile
-
Method Details
-
getText
-
getLine
-
getLineOffset
public int getLineOffset()Description copied from interface:ResourceReturns 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:
getLineOffsetin interfaceResource
-
isFile
public boolean isFile()Description copied from interface:ResourceReturns true if this resource is backed by the file system. PathResource returns true, MemoryResource returns false. -
isClassPath
public boolean isClassPath()Description copied from interface:ResourceReturns true if this resource was loaded from the classpath.- Specified by:
isClassPathin interfaceResource
-
exists
public boolean exists()Description copied from interface:ResourceReturns 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. -
getPath
Description copied from interface:ResourceReturns the Path representation of this resource if it's file-based. Returns null for in-memory resources. -
getRoot
Description copied from interface:ResourceReturns 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). -
getClasspathRoot
Description copied from interface:ResourceThe directory aclasspath:reference falls back to when the classloader misses — declared byboot.classpath(dir)for a project whose resources live under a build layout (src/test/resources). Defaults toResource.getRoot(), so a bare-folder project needs no declaration:classpath:xand/xland on the same file.- Specified by:
getClasspathRootin interfaceResource
-
getUri
-
getRelativePath
- Specified by:
getRelativePathin interfaceResource
-
resolve
-
materialize
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
-
toString
-