-
- All Implemented Interfaces:
-
org.readium.r2.shared.fetcher.Resource,org.readium.r2.shared.util.SuspendingCloseable
public abstract class TransformingResource extends ProxyResource
Transforms the bytes of resource on-the-fly.
If you set cacheBytes to false, consider providing your own implementation of length to avoid unnecessary transformations.
Warning: The transformation runs on the full content of resource, so it's not appropriate for large resources which can't be held in memory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classTransformingResource.Companion
-
Constructor Summary
Constructors Constructor Description TransformingResource(Resource resource, Boolean cacheBytes)
-
Method Summary
Modifier and Type Method Description abstract Try<ByteArray, Resource.Exception>transform(Try<ByteArray, Resource.Exception> data)Try<ByteArray, Resource.Exception>read(LongRange range)Reads the bytes at the given range. Try<Long, Resource.Exception>length()Returns data length from metadata if available, or calculated from reading the bytes otherwise. -
Methods inherited from class org.readium.r2.shared.fetcher.ProxyResource
close, getFile, link, toString -
Methods inherited from class org.readium.r2.shared.fetcher.Resource
readAsBitmap, readAsJson, readAsString, readAsXml -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
transform
abstract Try<ByteArray, Resource.Exception> transform(Try<ByteArray, Resource.Exception> data)
-
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.
-
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.
-
-
-
-