Skip to content

//readium-shared/org.readium.r2.shared.fetcher/LazyResource

LazyResource

[androidJvm]\ class LazyResource(factory: suspend () -> Resource) : Resource

Wraps a Resource which will be created only when first accessing one of its members.

Constructors

LazyResource [androidJvm]
fun LazyResource(factory: suspend () -> Resource)

Functions

Name Summary
close [androidJvm]
open suspend override fun close()
Closes this object and releases any resources associated with it. If the object is already closed then invoking this method has no effect.
length [androidJvm]
open suspend override fun length(): ResourceTry<Long>
Returns data length from metadata if available, or calculated from reading the bytes otherwise.
link [androidJvm]
open suspend override fun link(): Link
Returns the link from which the resource was retrieved.
read [androidJvm]
open suspend override fun read(range: LongRange?): ResourceTry<ByteArray>
Reads the bytes at the given range.
readAsBitmap [androidJvm]
open suspend fun readAsBitmap(): ResourceTry<Bitmap>
Reads the full content as a Bitmap.
readAsJson [androidJvm]
open suspend fun readAsJson(): ResourceTry<JSONObject>
Reads the full content as a JSON object.
readAsString [androidJvm]
open suspend fun readAsString(charset: Charset? = null): ResourceTry<String>
Reads the full content as a String.
readAsXml [androidJvm]
open suspend fun readAsXml(): ResourceTry<ElementNode>
Reads the full content as an XML document.
toString [androidJvm]
open override fun toString(): String

Properties

Name Summary
file [androidJvm]
open val file: File?
Direct file to this resource, when available.

Extensions

Name Summary
buffered [androidJvm]
fun Resource.buffered(resourceLength: Long? = null, size: Long = BufferingResource.DEFAULT_BUFFER_SIZE): BufferingResource
Wraps this resource in a BufferingResource to improve reading performances.
cached [androidJvm]
fun Resource.~~cached~~(): Resource
Creates a cached resource wrapping this resource.
fallback [androidJvm]
fun Resource.fallback(fallbackResourceFactory: (Resource.Exception) -> Resource): Resource
Falls back to alternative resources when the receiver fails.
[androidJvm]
fun Resource.fallback(fallbackResource: Resource): Resource
Falls back to the given alternative resource when the receiver fails.
synchronized [androidJvm]
fun Resource.synchronized(): SynchronizedResource
Wraps this resource in a SynchronizedResource to protect the access from multiple threads.