ContextResource class abstract interface

A resource of a context with a path within it: a resources: file knows its path below lib/resources/ (content/guide/index.md), whether it is embedded or read from disk. A feature that lists files by a pattern (resources:content/**/*.md) reads it to name each file.

for (final page in context.getResources('resources:content/**/*.md')) {
  if (page case final ContextResource resource) {
    log.info(resource.pathWithinContext); // content/guide/index.md
  }
}

Spring (Java): ContextResource.getPathWithinContext(), and ClassPathResource.getPath().

Implemented types

Properties

description → String
A text that tells people which resource this is, for error messages, such as file [/app/config/application.properties]. It is also the default name of a property source read from it, and two resources of the same type with the same description are equal.
no setterinherited
filename → String?
The last part of the path, such as application.yml, or null when the resource has no file name (bytes in memory).
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
isReadable → bool
Whether the content can be read; usually the same as exists, but false for a directory.
no setterinherited
pathWithinContext → String
The path within the context, without a leading /.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
supportsSyncRead → bool
Whether readAsBytesSync and readAsStringSync work. True for files and the embedded classpath; false for URLs and Flutter assets.
no setterinherited
uri → Uri?
The URI of the resource (file:, https:, ...), or null when it has none.
no setterinherited

Methods

createRelative(String relativePath) → Resource
The resource at relativePath from this one, such as a sibling file next to a config file. It is not checked to exist. Throws UnsupportedError for resources without a location (bytes in memory).
inherited
exists() → bool
Whether the content is there: the file exists, the classpath entry is embedded. Check it before reading a resource that may be missing. A UrlResource cannot ask the server synchronously and always says true.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readAsBytes() → Future<Uint8List>
Reads the whole content as bytes. Works for every resource that exists; fails for one that does not.
inherited
readAsBytesSync() → Uint8List
Reads the whole content as bytes without waiting, for code that cannot be asynchronous. Throws UnsupportedError unless supportsSyncRead.
inherited
readAsString({Encoding encoding = utf8}) → Future<String>
Reads the whole content as text, decoded with encoding (UTF-8 unless given).
inherited
readAsStringSync({Encoding encoding = utf8}) → String
Reads the whole content as text without waiting, decoded with encoding. Throws UnsupportedError unless supportsSyncRead.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited