Package io.karatelabs.common
Class PathResource
java.lang.Object
io.karatelabs.common.PathResource
- All Implemented Interfaces:
Resource
-
Field Summary
Fields inherited from interface io.karatelabs.common.Resource
CLASSPATH_COLON, FILE_COLON, THIS_COLON -
Constructor Summary
ConstructorsConstructorDescriptionPathResource(Path path) Creates a PathResource with working directory as root.PathResource(Path path, Path root) Creates a PathResource with a custom root.PathResource(Path path, Path root, boolean classpath) Creates a PathResource with custom root and classpath flag.PathResource(Path path, Path root, boolean classpath, Path classpathRoot) Creates a PathResource with custom root, classpath flag and an explicitclasspath:-fallback dir (seeResource.getClasspathRoot()). -
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).longgetLine(int index) Returns the parent of this resource, or null if no parent exists.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.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, getLineOffset, getPackageQualifiedName, getPrefixedPath, getRelativePathFrom, getRelativePathTo, getSimpleName, isInMemory, isJarResource, isLocalFile
-
Constructor Details
-
PathResource
Creates a PathResource with working directory as root.- Parameters:
path- the path
-
PathResource
Creates a PathResource with a custom root.- Parameters:
path- the pathroot- the root path for computing relative paths
-
PathResource
Creates a PathResource with custom root and classpath flag.- Parameters:
path- the pathroot- the root path for computing relative pathsclasspath- whether this is a classpath resource
-
PathResource
Creates a PathResource with custom root, classpath flag and an explicitclasspath:-fallback dir (seeResource.getClasspathRoot()).- Parameters:
path- the pathroot- the root path for computing relative pathsclasspath- whether this is a classpath resourceclasspathRoot- theclasspath:-miss fallback dir (null = root)
-
-
Method Details
-
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. -
getUri
-
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
-
resolve
-
getParent
Description copied from interface:ResourceReturns the parent of this resource, or null if no parent exists. For PathResource, preserves root and classpath context. For MemoryResource, returns null. -
getStream
-
getRelativePath
- Specified by:
getRelativePathin interfaceResource
-
getText
-
getLine
-
getLastModified
public long getLastModified()- Specified by:
getLastModifiedin interfaceResource
-
toString
-