AbstractResource class abstract

A base class for new kinds of Resource: it fills in everything that can be derived from a few members.

Extend it to read content from a place the framework does not know, for example a database or an HTTP client of your own, then hand it out from a ProtocolResolver. A subclass implements exists, description and readAsBytes; text reading is derived from them. Synchronous reading and createRelative throw UnsupportedError until overridden. Two resources of the same type with the same description are equal.

// Content behind an HTTP client the application already has.
class HttpResource extends AbstractResource {
  HttpResource(this.url);

  final Uri url;

  @override
  bool exists() => true;

  @override
  String get description => 'URL [$url]';

  @override
  Future<Uint8List> readAsBytes() => http.readBytes(url);
}

Spring (Java):

class HttpResource extends AbstractResource {
  private final URI url;

  HttpResource(URI url) { this.url = url; }

  @Override
  public String getDescription() { return "URL [" + url + "]"; }

  @Override
  public InputStream getInputStream() throws IOException {
    return url.toURL().openStream();
  }
}
Implemented types

Constructors

AbstractResource()
Lets subclasses be const.
const

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 setteroverride
hashCode → int
The hash code for this object.
no setteroverride
isReadable → bool
Whether the content can be read; usually the same as exists, but false for a directory.
no setteroverride
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 setteroverride
uri → Uri?
The URI of the resource (file:, https:, ...), or null when it has none.
no setteroverride

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).
override
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.
override
readAsString({Encoding encoding = utf8}) → Future<String>
Reads the whole content as text, decoded with encoding (UTF-8 unless given).
override
readAsStringSync({Encoding encoding = utf8}) → String
Reads the whole content as text without waiting, decoded with encoding. Throws UnsupportedError unless supportsSyncRead.
override
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
Whether other is a resource of the same run-time type with the same description, as in Spring.
override