Package io.karatelabs.common
Class UrlResource
java.lang.Object
io.karatelabs.common.UrlResource
- All Implemented Interfaces:
Resource
Resource implementation for HTTP/HTTPS URLs.
Content is fetched once and cached in memory.
Preserves the original URL for reference (getUri(), getSimpleName()).
-
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.getLine(int index) 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()getUrl()Returns the original URL this resource was loaded from.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 URL 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
getClasspathRoot, getExtension, getFileNameWithoutExtension, getLastModified, getLineOffset, getPackageQualifiedName, getParent, getPrefixedPath, getRelativePathFrom, getRelativePathTo, getSimpleName, isInMemory, isJarResource, isLocalFile
-
Method Details
-
getUrl
Returns the original URL this resource was loaded from. -
getText
-
getLine
-
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). -
getUri
-
getRelativePath
- Specified by:
getRelativePathin interfaceResource
-
resolve
-
materialize
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
-
toString
-