-
- All Implemented Interfaces:
-
org.readium.r2.shared.util.SuspendingCloseable,org.readium.r2.shared.util.data.Readable,org.readium.r2.shared.util.resource.Resource
public final class BufferingResource implements Resource
Wraps a Resource and buffers its content.
Expensive interaction with the underlying resource is minimized, since most (smaller) requests can be satisfied by accessing the buffer alone. The drawback is that some extra space is required to hold the buffer and that copying takes place when filling that buffer, but this is usually outweighed by the performance benefits.
Note that this implementation is pretty limited and the benefits are only apparent when reading forward and consecutively – e.g. when downloading the resource by chunks. The buffer is ignored when reading backward or far ahead.
-
-
Field Summary
Fields Modifier and Type Field Description private final AbsoluteUrlsourceUrl
-
Constructor Summary
Constructors Constructor Description BufferingResource(Resource resource, Long resourceLength, Integer bufferSize)
-
Method Summary
Modifier and Type Method Description AbsoluteUrlgetSourceUrl()URL locating this resource, if any. Try<ByteArray, ReadError>read(LongRange range)Reads the bytes at the given range. -
Methods inherited from class org.readium.r2.shared.util.resource.BufferingResource
properties -
Methods inherited from class org.readium.r2.shared.util.resource.Resource
length -
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.
-
-
-
-