DiscreteFileProvider
class DiscreteFileProvider(fileSystem: FileSystem, rootDir: Path, initialFiles: List<File> = emptyList(), mimeTypeDetector: MimeTypeDetector = MimeTypeDetector { "text/plain" }) : ResourceProvider
A ResourceProvider that exposes a finite, discrete set of files (by relative path) from a given rootDir. It does NOT return any resource templates.
Example usage:
val fileSystem: FileSystem = FileSystem.SYSTEM
val provider = DiscreteFileProvider(
fileSystem = fileSystem,
rootDir = "/some/local/folder".toPath(),
knownFiles = listOf("notes.txt", "report.pdf")
)Content copied to clipboard
Once created, listResources will show the above files, each accessible via a file:// URI like file://notes.txt.
If you need to add or remove files at runtime, call addFile or removeFile.
Constructors
Link copied to clipboard
constructor(fileSystem: FileSystem, rootDir: Path, initialFiles: List<File> = emptyList(), mimeTypeDetector: MimeTypeDetector = MimeTypeDetector { "text/plain" })
Functions
Link copied to clipboard
open fun attachCallbacks(onResourceChange: suspend (String) -> Unit, onResourcesListChanged: suspend () -> Unit)
Link copied to clipboard
Lists the currently known, discrete resources. Each resource is associated with a file://relativePath URI.
Link copied to clipboard
Link copied to clipboard
Reads file contents if uri starts with file:// and matches one of the known files. If the file doesn't exist or is a directory, returns null.
Link copied to clipboard
Removes a file from the known list, triggering onResourcesListChanged() if removed.