-
- All Implemented Interfaces:
-
org.readium.r2.shared.fetcher.Resource,org.readium.r2.shared.util.SuspendingCloseable
public final class FallbackResource implements Resource
Resource that will act as a proxy to a fallback resource if the originalResource errors out.
-
-
Constructor Summary
Constructors Constructor Description FallbackResource(Resource originalResource, Function1<Resource.Exception, Resource> fallbackResourceFactory)
-
Method Summary
Modifier and Type Method Description Linklink()Returns the link from which the resource was retrieved. Try<Long, Resource.Exception>length()Returns data length from metadata if available, or calculated from reading the bytes otherwise. Try<ByteArray, Resource.Exception>read(LongRange range)Reads the bytes at the given range. Unitclose()Closes this object and releases any resources associated with it. -
-
Constructor Detail
-
FallbackResource
FallbackResource(Resource originalResource, Function1<Resource.Exception, Resource> fallbackResourceFactory)
-
-
Method Detail
-
length
Try<Long, Resource.Exception> length()
Returns data length from metadata if available, or calculated from reading the bytes otherwise.
This value must be treated as a hint, as it might not reflect the actual bytes length. To get the real length, you need to read the whole resource.
-
read
Try<ByteArray, Resource.Exception> read(LongRange range)
Reads the bytes at the given range.
When range is null, the whole content is returned. Out-of-range indexes are clamped to the available length automatically.
-
-
-
-