-
- All Implemented Interfaces:
-
org.readium.r2.shared.util.SuspendingCloseable,org.readium.r2.shared.util.data.Readable,org.readium.r2.shared.util.resource.Resource
public abstract class TransformingResource implements Resource
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
-
Field Summary
Fields Modifier and Type Field Description private final AbsoluteUrlsourceUrl
-
Constructor Summary
Constructors Constructor Description TransformingResource(Resource resource, Boolean cacheBytes)
-
Method Summary
Modifier and Type Method Description AbsoluteUrlgetSourceUrl()URL locating this resource, if any. abstract Try<ByteArray, ReadError>transform(Try<ByteArray, ReadError> data)Try<ByteArray, ReadError>read(LongRange range)Reads the bytes at the given range. Try<Long, ReadError>length()Returns data length from metadata if available, or calculated from reading the bytes otherwise. -
Methods inherited from class org.readium.r2.shared.util.resource.TransformingResource
properties -
Methods inherited from class org.readium.r2.shared.util.data.Readable
close -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
getSourceUrl
AbsoluteUrl getSourceUrl()
URL locating this resource, if any.
-
read
Try<ByteArray, ReadError> 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.
-
-
-
-